ATLAS Offline Software
JsonUtils.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 #ifndef _TOPCONFIGURATION_JSONUTILS_H_
6 #define _TOPCONFIGURATION_JSONUTILS_H_
7 
8 #include "AsgTools/Property.h"
9 
10 #include <optional>
11 #include <cmath>
12 #include <ios>
13 #include <memory>
14 #include <sstream>
15 #include <string>
16 #include <type_traits>
17 #include <utility>
18 #include <vector>
19 
20 class Property;
21 
22 namespace top {
24  template<typename T, typename std::enable_if<
26  >::type* = nullptr>
27  std::string json_dump(T value) {
28  return(value ? "true" : "false");
29  }
30 
32  template<typename T, typename std::enable_if<
34  >::type* = nullptr>
35  std::string json_dump(T value) {
36  std::stringstream out;
37  out << value;
38  return out.str();
39  }
40 
42  template<typename T, typename std::enable_if<
44  >::type* = nullptr>
45  std::string json_dump(T value) {
46  if (std::isfinite(value)) {
47  std::stringstream out;
48  out << value;
49  return out.str();
50  }
51  return(std::isinf(value) ? (std::signbit(value) ? "-Infinity" : "Infinity") : "NaN");
52  }
53 
55  std::string json_dump(std::string const& value);
56 
57 
62  public:
65 
71  std::optional<std::string> operator () (Property* prop) const;
72 
74  public:
75  virtual ~ISpecializedDumper();
76  virtual std::string operator () (Property* prop) = 0;
77  };
78  protected:
79  std::vector<std::pair<Property::Type, std::unique_ptr<ISpecializedDumper> > > m_dispatch;
80  };
81 }
82 
83 
84 #endif
top::PropertyValueJsonDumper::ISpecializedDumper::~ISpecializedDumper
virtual ~ISpecializedDumper()
Definition: JsonUtils.cxx:96
top::PropertyValueJsonDumper::ISpecializedDumper::operator()
virtual std::string operator()(Property *prop)=0
top::PropertyValueJsonDumper::operator()
std::optional< std::string > operator()(Property *prop) const
Convert the value of a property to JSON.
Definition: JsonUtils.cxx:88
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
top::PropertyValueJsonDumper
Convert values of Property instances to JSON.
Definition: JsonUtils.h:61
athena.value
value
Definition: athena.py:122
Property
Support class for PropertyMgr.
Definition: Property.h:23
Property.h
top::PropertyValueJsonDumper::~PropertyValueJsonDumper
~PropertyValueJsonDumper()
Definition: JsonUtils.cxx:85
top::PropertyValueJsonDumper::ISpecializedDumper
Definition: JsonUtils.h:73
top::PropertyValueJsonDumper::PropertyValueJsonDumper
PropertyValueJsonDumper()
Definition: JsonUtils.cxx:77
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
top::json_dump
std::string json_dump(std::string const &value)
Escape string for use in JSON format.
Definition: JsonUtils.cxx:13
top::PropertyValueJsonDumper::m_dispatch
std::vector< std::pair< Property::Type, std::unique_ptr< ISpecializedDumper > > > m_dispatch
Definition: JsonUtils.h:79
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35