AliPhysics  bba8f44 (bba8f44)
AliJSONData.cxx
Go to the documentation of this file.
1 /*
2  * AliJSONData.cxx
3  *
4  * Created on: 06.11.2014
5  * Author: markusfasel
6  */
7 #include <sstream>
8 #include <TString.h>
9 
10 #include <AliJSONData.h>
11 
12 ClassImp(AliJSONValue)
13 ClassImp(AliJSONInt)
14 ClassImp(AliJSONFloat)
15 ClassImp(AliJSONDouble)
16 ClassImp(AliJSONBool)
17 ClassImp(AliJSONString)
18 ClassImp(AliJSONData)
19 
20 std::string AliJSONInt::ToString() const {
21  std::stringstream stringbuilder;
22  stringbuilder << fValue;
23  return stringbuilder.str();
24 }
25 
26 std::string AliJSONFloat::ToString() const {
27  std::stringstream stringbuilder;
28  stringbuilder << fValue;
29  return stringbuilder.str();
30 }
31 
32 std::string AliJSONDouble::ToString() const {
33  std::stringstream stringbuilder;
34  stringbuilder << fValue;
35  return stringbuilder.str();
36 }
37 
38 AliJSONData::AliJSONData(const char* key, const char* value):
39  TNamed(key, ""),
40  fValue(NULL)
41 {
42  TString valstring(value);
43  if(!valstring.CompareTo("true"))
44  fValue = new AliJSONBool(kTRUE);
45  else if(!valstring.CompareTo("false"))
46  fValue = new AliJSONBool(kFALSE);
47  else if(valstring.IsDigit()){
48  if(valstring.IsFloat())
49  fValue = new AliJSONDouble(valstring.Atof());
50  else
51  fValue = new AliJSONInt(valstring.Atoi());
52  } else
53  fValue = new AliJSONString(value);
54 }
55 
56 std::string AliJSONData::ToString() const {
57  std::stringstream jsonbuilder;
58  jsonbuilder << "\"" << GetName() << "\":\"" << fValue->ToString() << "\"";
59  return jsonbuilder.str().c_str();
60 }
61 
62 std::ostream &operator<<(std::ostream &os, const AliJSONValue &val){
63  os << val.ToString();
64  return os;
65 }
66 
67 std::ostream &operator<<(std::ostream &os, const AliJSONData &obj){
68  os << obj.ToString();
69  return os;
70 }
71 
AliJSONData(const char *name, AliJSONValue *value)
Definition: AliJSONData.h:130
virtual std::string ToString() const
Definition: AliJSONData.cxx:32
Float_t fValue
Definition: AliJSONData.h:63
AliJSONValue * fValue
Definition: AliJSONData.h:152
virtual std::string ToString() const
Definition: AliJSONData.cxx:26
std::string ToString() const
Definition: AliJSONData.cxx:56
virtual std::string ToString() const =0
std::ostream & operator<<(std::ostream &os, const AliJSONValue &val)
Definition: AliJSONData.cxx:62