00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef TRIGBUNCHCROSSINGTOOL_JSON_ELEMENTS_H
00011 #define TRIGBUNCHCROSSINGTOOL_JSON_ELEMENTS_H
00012
00013
00014 #include <deque>
00015 #include <list>
00016 #include <string>
00017 #include <stdexcept>
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 namespace json {
00029
00030
00032
00033 class Visitor;
00034 class ConstVisitor;
00035
00036 template <typename ValueTypeT>
00037 class TrivialType_T;
00038
00039 typedef TrivialType_T<double> Number;
00040 typedef TrivialType_T<bool> Boolean;
00041 typedef TrivialType_T<std::string> String;
00042
00043 class Object;
00044 class Array;
00045 class Null;
00046
00047
00048
00050
00051 class Exception : public std::runtime_error {
00052 public:
00053 Exception(const std::string& sMessage);
00054 };
00055
00056
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 class UnknownElement {
00071
00072 public:
00073 UnknownElement();
00074 UnknownElement( const UnknownElement& unknown );
00075 UnknownElement( const Object& object );
00076 UnknownElement( const Array& array );
00077 UnknownElement( const Number& number );
00078 UnknownElement( const Boolean& boolean );
00079 UnknownElement( const String& string );
00080 UnknownElement( const Null& null );
00081
00082 ~UnknownElement();
00083
00084 UnknownElement& operator = ( const UnknownElement& unknown );
00085
00086
00087 operator const Object& () const;
00088 operator const Array& () const;
00089 operator const Number& () const;
00090 operator const Boolean& () const;
00091 operator const String& () const;
00092 operator const Null& () const;
00093
00094
00095 operator Object& ();
00096 operator Array& ();
00097 operator Number& ();
00098 operator Boolean& ();
00099 operator String& ();
00100 operator Null& ();
00101
00102
00103 UnknownElement& operator[] ( const std::string& key );
00104 const UnknownElement& operator[] ( const std::string& key ) const;
00105
00106
00107 UnknownElement& operator[] ( size_t index );
00108 const UnknownElement& operator[] ( size_t index ) const;
00109
00110
00111 void Accept( ConstVisitor& visitor ) const;
00112 void Accept( Visitor& visitor );
00113
00114
00115 bool operator == ( const UnknownElement& element ) const;
00116
00117 private:
00118 class Imp;
00119
00120 template <typename ElementTypeT>
00121 class Imp_T;
00122
00123 class CastVisitor;
00124 class ConstCastVisitor;
00125
00126 template <typename ElementTypeT>
00127 class CastVisitor_T;
00128
00129 template <typename ElementTypeT>
00130 class ConstCastVisitor_T;
00131
00132 template <typename ElementTypeT>
00133 const ElementTypeT& CastTo() const;
00134
00135 template <typename ElementTypeT>
00136 ElementTypeT& ConvertTo();
00137
00138 Imp* m_pImp;
00139 };
00140
00141
00143
00144
00145
00146 class Array {
00147
00148 public:
00149 typedef std::deque< UnknownElement > Elements;
00150 typedef Elements::iterator iterator;
00151 typedef Elements::const_iterator const_iterator;
00152
00153 iterator Begin();
00154 iterator End();
00155 const_iterator Begin() const;
00156 const_iterator End() const;
00157
00158 iterator Insert( const UnknownElement& element, iterator itWhere );
00159 iterator Insert( const UnknownElement& element );
00160 iterator Erase( iterator itWhere );
00161 void Resize( size_t newSize );
00162 void Clear();
00163
00164 size_t Size() const;
00165 bool Empty() const;
00166
00167 UnknownElement& operator[] ( size_t index );
00168 const UnknownElement& operator[] ( size_t index ) const;
00169
00170 bool operator == (const Array& array) const;
00171
00172 private:
00173 Elements m_Elements;
00174 };
00175
00176
00178
00179
00180 class Object {
00181
00182 public:
00183 struct Member {
00184 Member( const std::string& nameIn = std::string(),
00185 const UnknownElement& elementIn = UnknownElement() );
00186
00187 bool operator == ( const Member& member ) const;
00188
00189 std::string name;
00190 UnknownElement element;
00191 };
00192
00193 typedef std::list<Member> Members;
00194 typedef Members::iterator iterator;
00195 typedef Members::const_iterator const_iterator;
00196
00197 bool operator == ( const Object& object ) const;
00198
00199 iterator Begin();
00200 iterator End();
00201 const_iterator Begin() const;
00202 const_iterator End() const;
00203
00204 size_t Size() const;
00205 bool Empty() const;
00206
00207 iterator Find( const std::string& name );
00208 const_iterator Find( const std::string& name ) const;
00209
00210 iterator Insert( const Member& member );
00211 iterator Insert( const Member& member, iterator itWhere );
00212 iterator Erase( iterator itWhere );
00213 void Clear();
00214
00215 UnknownElement& operator []( const std::string& name );
00216 const UnknownElement& operator []( const std::string& name ) const;
00217
00218 private:
00219 class Finder;
00220
00221 Members m_Members;
00222 };
00223
00224
00226
00227
00228
00229 template <typename DataTypeT>
00230 class TrivialType_T {
00231
00232 public:
00233 TrivialType_T( const DataTypeT& t = DataTypeT() );
00234
00235 operator DataTypeT&();
00236 operator const DataTypeT&() const;
00237
00238 DataTypeT& Value();
00239 const DataTypeT& Value() const;
00240
00241 bool operator == ( const TrivialType_T<DataTypeT>& trivial ) const;
00242
00243 private:
00244 DataTypeT m_tValue;
00245 };
00246
00247
00249
00250
00251 class Null {
00252
00253 public:
00254 bool operator == ( const Null& trivial ) const;
00255 };
00256
00257
00258 }
00259
00260 #ifndef __CINT__
00261
00262 #include "elements.inl"
00263 #endif // __CINT__
00264
00265 #endif // TRIGBUNCHCROSSINGTOOL_JSON_ELEMENTS_H