PandaRoot
JSONReaders Namespace Reference

collection of helper methods to load in pairs, triplets or vectors of doubles from JSON files More...

Functions

std::pair< double, double > readPair (pt::ptree &tree)
 
std::pair< std::string, std::string > readStringPair (pt::ptree &tree)
 
std::array< double, 3 > readTriplet (pt::ptree &tree)
 
std::vector< double > readVector (pt::ptree &tree)
 

Detailed Description

collection of helper methods to load in pairs, triplets or vectors of doubles from JSON files

JSONReadersHelper.h

Date
21.09.2022
Author
Tobias Stockmanns t.sto.nosp@m.ckma.nosp@m.nns@f.nosp@m.z-ju.nosp@m.elich.nosp@m..de

Function Documentation

◆ readPair()

std::pair<double, double> JSONReaders::readPair ( pt::ptree &  tree)
inline

Definition at line 29 of file JSONReadersHelper.h.

References max(), and min().

30 {
31  if (tree.size() != 2) {
32  throw std::range_error("Expected two values e.g min/max not " + std::to_string(tree.size()));
33  // LOG(error) << "Expected two values eg. min/max not " << tree.size();
34  }
35  auto it = tree.begin();
36  double min = it->second.get_value<double>();
37  it++;
38  double max = it->second.get_value<double>();
39  return std::make_pair(min, max);
40 }
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:37
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:36

◆ readStringPair()

std::pair<std::string, std::string> JSONReaders::readStringPair ( pt::ptree &  tree)
inline

Definition at line 42 of file JSONReadersHelper.h.

43 {
44  if (tree.size() != 2) {
45  throw std::range_error("Expected two values e.g min/max not " + std::to_string(tree.size()));
46  // LOG(error) << "Expected two values eg. min/max not " << tree.size();
47  }
48  auto it = tree.begin();
49  std::string first = it->second.data();
50  it++;
51  std::string second = it->second.data();
52  return std::make_pair(first, second);
53 }

◆ readTriplet()

std::array<double, 3> JSONReaders::readTriplet ( pt::ptree &  tree)
inline

Definition at line 55 of file JSONReadersHelper.h.

56 {
57  if (tree.size() != 3) {
58  throw std::range_error("Expected three values e.g x/y/z not " + std::to_string(tree.size()));
59  // LOG(error) << << tree.size();
60  }
61  std::array<double, 3> xyz;
62  int index = 0;
63  for (auto val : tree) {
64  xyz[index++] = val.second.get_value<double>();
65  }
66  return xyz;
67 }

◆ readVector()

std::vector<double> JSONReaders::readVector ( pt::ptree &  tree)
inline

Definition at line 69 of file JSONReadersHelper.h.

70 {
71  std::vector<double> result;
72  for (auto val : tree) {
73  result.push_back(val.second.get_value<double>());
74  }
75  return result;
76 }