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 17 of file JSONReadersHelper.h.

References max(), and min().

18 {
19  if (tree.size() != 2) {
20  throw std::range_error("Expected two values e.g min/max not " + std::to_string(tree.size()));
21  // LOG(error) << "Expected two values eg. min/max not " << tree.size();
22  }
23  auto it = tree.begin();
24  double min = it->second.get_value<double>();
25  it++;
26  double max = it->second.get_value<double>();
27  return std::make_pair(min, max);
28 }
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:25
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:24

◆ readStringPair()

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

Definition at line 30 of file JSONReadersHelper.h.

31 {
32  if (tree.size() != 2) {
33  throw std::range_error("Expected two values e.g min/max not " + std::to_string(tree.size()));
34  // LOG(error) << "Expected two values eg. min/max not " << tree.size();
35  }
36  auto it = tree.begin();
37  std::string first = it->second.data();
38  it++;
39  std::string second = it->second.data();
40  return std::make_pair(first, second);
41 }

◆ readTriplet()

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

Definition at line 43 of file JSONReadersHelper.h.

44 {
45  if (tree.size() != 3) {
46  throw std::range_error("Expected three values e.g x/y/z not " + std::to_string(tree.size()));
47  // LOG(error) << << tree.size();
48  }
49  std::array<double, 3> xyz;
50  int index = 0;
51  for (auto val : tree) {
52  xyz[index++] = val.second.get_value<double>();
53  }
54  return xyz;
55 }

◆ readVector()

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

Definition at line 57 of file JSONReadersHelper.h.

58 {
59  std::vector<double> result;
60  for (auto val : tree) {
61  result.push_back(val.second.get_value<double>());
62  }
63  return result;
64 }