]>
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 | ||
20 | const char* AliJSONInt::ToString() const { | |
21 | std::stringstream stringbuilder; | |
22 | stringbuilder << fValue; | |
23 | return stringbuilder.str().c_str(); | |
24 | } | |
25 | ||
26 | const char* AliJSONFloat::ToString() const { | |
27 | std::stringstream stringbuilder; | |
28 | stringbuilder << fValue; | |
29 | return stringbuilder.str().c_str(); | |
30 | } | |
31 | ||
32 | const char* AliJSONDouble::ToString() const { | |
33 | std::stringstream stringbuilder; | |
34 | stringbuilder << fValue; | |
35 | return stringbuilder.str().c_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 | const char* 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 |