Public Member Functions | Protected Attributes | List of all members
evd::JSONFormatter Class Reference

#include <JSONFormatter.h>

Public Member Functions

 JSONFormatter (std::ostream &os)
 
template<class T >
JSONFormatteroperator<< (const T &x)
 
JSONFormatteroperator<< (double x)
 
JSONFormatteroperator<< (float x)
 
JSONFormatteroperator<< (int x)
 
JSONFormatteroperator<< (const char *x)
 
template<class T >
JSONFormatteroperator<< (const std::vector< T > &v)
 
template<class T , class U >
JSONFormatteroperator<< (const std::map< T, U > &m)
 
template<class T >
JSONFormatteroperator<< (const std::map< std::string, T > &m)
 
template<class T >
JSONFormatteroperator<< (const std::map< int, T > &m)
 
JSONFormatteroperator<< (const TVector3 &v)
 

Protected Attributes

std::ostream & fStream
 

Detailed Description

Definition at line 15 of file JSONFormatter.h.

Constructor & Destructor Documentation

evd::JSONFormatter::JSONFormatter ( std::ostream &  os)
inline

Definition at line 18 of file JSONFormatter.h.

18 : fStream(os) {}
std::ostream & fStream

Member Function Documentation

template<class T >
JSONFormatter& evd::JSONFormatter::operator<< ( const T &  x)
inline

Definition at line 20 of file JSONFormatter.h.

21  {
22  static_assert(std::is_arithmetic_v<T> ||
23  std::is_enum_v<T> ||
24  std::is_same_v<T, std::string>);
25  fStream << x;
26  return *this;
27  }
std::ostream & fStream
list x
Definition: train.py:276
JSONFormatter& evd::JSONFormatter::operator<< ( double  x)
inline

Definition at line 29 of file JSONFormatter.h.

30  {
31  // "NaN" and "Infinity" are the javascript syntax, but JSON doesn't include
32  // these concepts at all. Our options are to send a string, a null, or a
33  // number that is unrepresentable and will become Infinity again. I don't
34  // know any way to play the same trick with a NaN.
35  if(isnan(x)) fStream << "1e999";
36  else if(isinf(x)) fStream << "1e999";
37  else fStream << x;
38  return *this;
39  }
std::ostream & fStream
list x
Definition: train.py:276
JSONFormatter& evd::JSONFormatter::operator<< ( float  x)
inline

Definition at line 41 of file JSONFormatter.h.

41 {return *this << double(x);}
list x
Definition: train.py:276
JSONFormatter& evd::JSONFormatter::operator<< ( int  x)
inline

Definition at line 43 of file JSONFormatter.h.

44  {
45  fStream << x;
46  return *this;
47  }
std::ostream & fStream
list x
Definition: train.py:276
JSONFormatter& evd::JSONFormatter::operator<< ( const char *  x)
inline

Definition at line 49 of file JSONFormatter.h.

50  {
51  fStream << x;
52  return *this;
53  }
std::ostream & fStream
list x
Definition: train.py:276
template<class T >
JSONFormatter& evd::JSONFormatter::operator<< ( const std::vector< T > &  v)
inline

Definition at line 55 of file JSONFormatter.h.

56  {
57  fStream << "[";
58  for(const T& x: v){
59  (*this) << x;
60  if(&x != &v.back()) (*this) << ", ";
61  }
62  fStream << "]";
63  return *this;
64  }
std::ostream & fStream
list x
Definition: train.py:276
template<class T , class U >
JSONFormatter& evd::JSONFormatter::operator<< ( const std::map< T, U > &  m)
inline

Definition at line 67 of file JSONFormatter.h.

68  {
69  fStream << "{\n";
70  unsigned int n = 0;
71  for(auto& it: m){
72  (*this) << " " << it.first << ": " << it.second;
73  ++n;
74  if(n != m.size()) (*this) << ",\n";
75  }
76  fStream << "\n}";
77  return *this;
78  }
std::ostream & fStream
std::void_t< T > n
template<class T >
JSONFormatter& evd::JSONFormatter::operator<< ( const std::map< std::string, T > &  m)
inline

Definition at line 81 of file JSONFormatter.h.

82  {
83  fStream << "{\n";
84  unsigned int n = 0;
85  for(auto& it: m){
86  (*this) << " \"" << it.first << "\": " << it.second;
87  ++n;
88  if(n != m.size()) (*this) << ",\n";
89  }
90  fStream << "\n}";
91  return *this;
92  }
std::ostream & fStream
std::void_t< T > n
template<class T >
JSONFormatter& evd::JSONFormatter::operator<< ( const std::map< int, T > &  m)
inline

Definition at line 95 of file JSONFormatter.h.

96  {
97  fStream << "{\n";
98  unsigned int n = 0;
99  for(auto& it: m){
100  (*this) << " \"" << it.first << "\": " << it.second;
101  ++n;
102  if(n != m.size()) (*this) << ",\n";
103  }
104  fStream << "\n}";
105  return *this;
106  }
std::ostream & fStream
std::void_t< T > n
JSONFormatter& evd::JSONFormatter::operator<< ( const TVector3 &  v)
inline

Definition at line 108 of file JSONFormatter.h.

109  {
110  *this << "["
111  << v.X() << ", "
112  << v.Y() << ", "
113  << v.Z() << "]";
114  return *this;
115  }

Member Data Documentation

std::ostream& evd::JSONFormatter::fStream
protected

Definition at line 118 of file JSONFormatter.h.


The documentation for this class was generated from the following file: