]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/Tools/AliJSONData.h
New MFT analysis tools
[u/mrichter/AliRoot.git] / PWG / Tools / AliJSONData.h
1 /*
2  * AliEMCALConfigurationObject.h
3  *
4  *  Created on: 06.11.2014
5  *      Author: markusfasel
6  */
7
8 #ifndef _ALIJSONDATA_H_
9 #define _ALIJSONDATA_H_
10
11 #include <ostream>
12 #include <TNamed.h>
13
14 /************************************************************
15  *
16  * Declaration of wrapper types used in the JSON handling
17  *
18  * **********************************************************/
19
20 class AliJSONValue : public TObject {
21 public:
22   AliJSONValue() {}
23   virtual ~AliJSONValue() {}
24
25   virtual const char *ToString() const = 0;
26
27   ClassDef(AliJSONValue,1);
28 };
29
30 class AliJSONInt : public AliJSONValue{
31 public:
32   AliJSONInt(Int_t val):
33     AliJSONValue(),
34     fValue(val)
35   {}
36   virtual ~AliJSONInt() {}
37
38   void SetValue(Int_t value) { fValue = value; }
39   Int_t GetValue() const { return fValue; }
40
41   virtual const char *ToString() const ;
42 private:
43   Int_t fValue;
44
45   ClassDef(AliJSONInt,1);
46 };
47
48 class AliJSONFloat : public AliJSONValue{
49 public:
50   AliJSONFloat(Float_t val):
51     AliJSONValue(),
52     fValue(val)
53   {}
54   virtual ~AliJSONFloat() {}
55
56   void SetValue(Float_t value) { fValue = value; }
57   Float_t GetValue() const { return fValue; }
58
59   virtual const char *ToString() const;
60 private:
61   Float_t fValue;
62
63   ClassDef(AliJSONFloat,1);
64 };
65
66 class AliJSONDouble : public AliJSONValue{
67 public:
68   AliJSONDouble(Double_t val):
69     AliJSONValue(),
70     fValue(val)
71   {}
72   virtual ~AliJSONDouble() {}
73
74   void SetValue(Double_t value) { fValue = value; }
75   Double_t GetValue() const { return fValue; }
76
77   virtual const char *ToString() const;
78 private:
79   Double_t fValue;
80
81   ClassDef(AliJSONDouble,1);
82 };
83
84 class AliJSONBool : public AliJSONValue{
85 public:
86   AliJSONBool(Bool_t val):
87     AliJSONValue(),
88     fValue(val)
89   {}
90   virtual ~AliJSONBool() {}
91
92   void SetValue(Bool_t value) { fValue = value; }
93   Bool_t GetValue() const { return fValue; }
94
95   virtual const char *ToString() const { return fValue ? "true" : "false"; }
96 private:
97   Bool_t fValue;
98
99   ClassDef(AliJSONBool,1);
100 };
101
102 class AliJSONString : public AliJSONValue{
103 public:
104   AliJSONString(const char *val):
105     AliJSONValue(),
106     fValue(val)
107   {}
108   virtual ~AliJSONString() {}
109
110   void SetValue(const char * value) { fValue = value; }
111   const char * GetValue() const { return fValue; }
112
113   virtual const char *ToString() const { return fValue; }
114 private:
115   TString fValue;
116
117   ClassDef(AliJSONString,1);
118 };
119
120 /********************************************************************
121  *                                                                  *
122  * Declaration of the JSON key-value pair                           *
123  *                                                                  *
124  ********************************************************************/
125
126 class AliJSONData : public TNamed {
127 public:
128   AliJSONData(const char *name, AliJSONValue *value):
129     TNamed(name, ""),
130     fValue(value)
131   {}
132   AliJSONData(const char *key, const char *value);
133
134   virtual ~AliJSONData(){
135     delete fValue;
136   }
137
138   void SetValue(AliJSONValue *val){
139     if(fValue) delete fValue;
140     fValue = val;
141   }
142
143   AliJSONValue *GetValue() const { return fValue; }
144   const char *ToString() const;
145
146 protected:
147   AliJSONData(const AliJSONData &ref);
148   AliJSONData &operator=(const AliJSONData &ref);
149
150   AliJSONValue *fValue;
151
152   ClassDef(AliJSONData, 1);
153 };
154
155 std::ostream &operator<<(std::ostream &, const AliJSONValue &);
156 std::ostream &operator<<(std::ostream &, const AliJSONData &);
157
158 #endif /* _ALIJSONDATA_H_ */