]>
Commit | Line | Data |
---|---|---|
c4109efb | 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 | ||
7a88a153 | 20 | std::string AliJSONInt::ToString() const { |
c4109efb | 21 | std::stringstream stringbuilder; |
22 | stringbuilder << fValue; | |
7a88a153 | 23 | return stringbuilder.str(); |
c4109efb | 24 | } |
25 | ||
7a88a153 | 26 | std::string AliJSONFloat::ToString() const { |
c4109efb | 27 | std::stringstream stringbuilder; |
28 | stringbuilder << fValue; | |
7a88a153 | 29 | return stringbuilder.str(); |
c4109efb | 30 | } |
31 | ||
7a88a153 | 32 | std::string AliJSONDouble::ToString() const { |
c4109efb | 33 | std::stringstream stringbuilder; |
34 | stringbuilder << fValue; | |
7a88a153 | 35 | return stringbuilder.str(); |
c4109efb | 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 | ||
7a88a153 | 56 | std::string AliJSONData::ToString() const { |
c4109efb | 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 |