BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
XmlRpcValue.h
Go to the documentation of this file.
1
2#ifndef _XMLRPCVALUE_H_
3#define _XMLRPCVALUE_H_
4//
5// XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
6//
7#if defined( _MSC_VER )
8# pragma warning( disable : 4786 ) // identifier was truncated in debug info
9#endif
10
11#ifndef MAKEDEPEND
12# include <map>
13# include <string>
14# include <time.h>
15# include <vector>
16#endif
17
18namespace XmlRpc {
19
20 //! RPC method arguments and results are represented by Values
21 // should probably refcount them...
23 public:
35
36 // Non-primitive types
37 typedef std::vector<char> BinaryData;
38 typedef std::vector<XmlRpcValue> ValueArray;
39 typedef std::map<std::string, XmlRpcValue> ValueStruct;
40
41 //! Constructors
42 XmlRpcValue() : _type( TypeInvalid ) { _value.asBinary = 0; }
43 XmlRpcValue( bool value ) : _type( TypeBoolean ) { _value.asBool = value; }
44 XmlRpcValue( int value ) : _type( TypeInt ) { _value.asInt = value; }
45 XmlRpcValue( double value ) : _type( TypeDouble ) { _value.asDouble = value; }
46
47 XmlRpcValue( std::string const& value ) : _type( TypeString ) {
48 _value.asString = new std::string( value );
49 }
50
51 XmlRpcValue( const char* value ) : _type( TypeString ) {
52 _value.asString = new std::string( value );
53 }
54
55 XmlRpcValue( struct tm* value ) : _type( TypeDateTime ) {
56 _value.asTime = new struct tm( *value );
57 }
58
59 XmlRpcValue( void* value, int nBytes ) : _type( TypeBase64 ) {
60 _value.asBinary = new BinaryData( (char*)value, ( (char*)value ) + nBytes );
61 }
62
63 //! Construct from xml, beginning at *offset chars into the string, updates offset
64 XmlRpcValue( std::string const& xml, int* offset ) : _type( TypeInvalid ) {
65 if ( !fromXml( xml, offset ) ) _type = TypeInvalid;
66 }
67
68 //! Copy
69 XmlRpcValue( XmlRpcValue const& rhs ) : _type( TypeInvalid ) { *this = rhs; }
70
71 //! Destructor (make virtual if you want to subclass)
72 /*virtual*/ ~XmlRpcValue() { invalidate(); }
73
74 //! Erase the current value
75 void clear() { invalidate(); }
76
77 // Operators
78 XmlRpcValue& operator=( XmlRpcValue const& rhs );
79 XmlRpcValue& operator=( int const& rhs ) { return operator=( XmlRpcValue( rhs ) ); }
80 XmlRpcValue& operator=( double const& rhs ) { return operator=( XmlRpcValue( rhs ) ); }
81 XmlRpcValue& operator=( const char* rhs ) {
82 return operator=( XmlRpcValue( std::string( rhs ) ) );
83 }
84
85 bool operator==( XmlRpcValue const& other ) const;
86 bool operator!=( XmlRpcValue const& other ) const;
87
88 operator bool&() {
90 return _value.asBool;
91 }
92 operator int&() {
94 return _value.asInt;
95 }
96 operator double&() {
98 return _value.asDouble;
99 }
100 operator std::string&() {
102 return *_value.asString;
103 }
104 operator BinaryData&() {
106 return *_value.asBinary;
107 }
108 operator struct tm &() {
110 return *_value.asTime;
111 }
112
113 XmlRpcValue const& operator[]( int i ) const {
114 assertArray( i + 1 );
115 return _value.asArray->at( i );
116 }
118 assertArray( i + 1 );
119 return _value.asArray->at( i );
120 }
121
122 XmlRpcValue& operator[]( std::string const& k ) {
123 assertStruct();
124 return ( *_value.asStruct )[k];
125 }
126 XmlRpcValue& operator[]( const char* k ) {
127 assertStruct();
128 std::string s( k );
129 return ( *_value.asStruct )[s];
130 }
131
132 // Accessors
133 //! Return true if the value has been set to something.
134 bool valid() const { return _type != TypeInvalid; }
135
136 //! Return the type of the value stored. \see Type.
137 Type const& getType() const { return _type; }
138
139 //! Return the size for string, base64, array, and struct values.
140 int size() const;
141
142 //! Specify the size for array values. Array values will grow beyond this size if needed.
143 void setSize( int size ) { assertArray( size ); }
144
145 //! Check for the existence of a struct member by name.
146 bool hasMember( const std::string& name ) const;
147
148 //! Decode xml. Destroys any existing value.
149 bool fromXml( std::string const& valueXml, int* offset );
150
151 //! Encode the Value in xml
152 std::string toXml() const;
153
154 //! Write the value (no xml encoding)
155 std::ostream& write( std::ostream& os ) const;
156
157 // Formatting
158 //! Return the format used to write double values.
159 static std::string const& getDoubleFormat() { return _doubleFormat; }
160
161 //! Specify the format used to write double values.
162 static void setDoubleFormat( const char* f ) { _doubleFormat = f; }
163
164 protected:
165 // Clean up
166 void invalidate();
167
168 // Type checking
169 void assertTypeOrInvalid( Type t );
170 void assertArray( int size ) const;
171 void assertArray( int size );
172 void assertStruct();
173
174 // XML decoding
175 bool boolFromXml( std::string const& valueXml, int* offset );
176 bool intFromXml( std::string const& valueXml, int* offset );
177 bool doubleFromXml( std::string const& valueXml, int* offset );
178 bool stringFromXml( std::string const& valueXml, int* offset );
179 bool timeFromXml( std::string const& valueXml, int* offset );
180 bool binaryFromXml( std::string const& valueXml, int* offset );
181 bool arrayFromXml( std::string const& valueXml, int* offset );
182 bool structFromXml( std::string const& valueXml, int* offset );
183
184 // XML encoding
185 std::string boolToXml() const;
186 std::string intToXml() const;
187 std::string doubleToXml() const;
188 std::string stringToXml() const;
189 std::string timeToXml() const;
190 std::string binaryToXml() const;
191 std::string arrayToXml() const;
192 std::string structToXml() const;
193
194 // Format strings
195 static std::string _doubleFormat;
196
197 // Type tag and values
199
200 // At some point I will split off Arrays and Structs into
201 // separate ref-counted objects for more efficient copying.
202 union {
203 bool asBool;
204 int asInt;
205 double asDouble;
206 struct tm* asTime;
207 std::string* asString;
212 };
213} // namespace XmlRpc
214
215std::ostream& operator<<( std::ostream& os, XmlRpc::XmlRpcValue& v );
216
217#endif // _XMLRPCVALUE_H_
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
XmlRpcServer s
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
Definition KarLud.h:35
std::ostream & operator<<(std::ostream &os, XmlRpc::XmlRpcValue &v)
RPC method arguments and results are represented by Values.
Definition XmlRpcValue.h:22
std::vector< char > BinaryData
Definition XmlRpcValue.h:37
std::string intToXml() const
std::string doubleToXml() const
bool timeFromXml(std::string const &valueXml, int *offset)
bool hasMember(const std::string &name) const
Check for the existence of a struct member by name.
XmlRpcValue & operator[](const char *k)
ValueStruct * asStruct
XmlRpcValue(int value)
Definition XmlRpcValue.h:44
XmlRpcValue(std::string const &value)
Definition XmlRpcValue.h:47
bool operator==(XmlRpcValue const &other) const
bool binaryFromXml(std::string const &valueXml, int *offset)
int size() const
Return the size for string, base64, array, and struct values.
XmlRpcValue & operator=(XmlRpcValue const &rhs)
bool intFromXml(std::string const &valueXml, int *offset)
XmlRpcValue & operator=(const char *rhs)
Definition XmlRpcValue.h:81
void assertArray(int size) const
XmlRpcValue & operator=(double const &rhs)
Definition XmlRpcValue.h:80
XmlRpcValue const & operator[](int i) const
std::string arrayToXml() const
std::string timeToXml() const
void assertTypeOrInvalid(Type t)
std::string structToXml() const
void clear()
Erase the current value.
Definition XmlRpcValue.h:75
XmlRpcValue(std::string const &xml, int *offset)
Construct from xml, beginning at *offset chars into the string, updates offset.
Definition XmlRpcValue.h:64
bool doubleFromXml(std::string const &valueXml, int *offset)
XmlRpcValue(void *value, int nBytes)
Definition XmlRpcValue.h:59
ValueArray * asArray
static void setDoubleFormat(const char *f)
Specify the format used to write double values.
bool arrayFromXml(std::string const &valueXml, int *offset)
bool operator!=(XmlRpcValue const &other) const
XmlRpcValue(bool value)
Definition XmlRpcValue.h:43
XmlRpcValue(XmlRpcValue const &rhs)
Copy.
Definition XmlRpcValue.h:69
XmlRpcValue(double value)
Definition XmlRpcValue.h:45
XmlRpcValue & operator[](std::string const &k)
std::string * asString
bool fromXml(std::string const &valueXml, int *offset)
Decode xml. Destroys any existing value.
bool structFromXml(std::string const &valueXml, int *offset)
std::string binaryToXml() const
XmlRpcValue(struct tm *value)
Definition XmlRpcValue.h:55
static std::string _doubleFormat
union XmlRpc::XmlRpcValue::@050363270230164230256327115202057142222030207371 _value
std::map< std::string, XmlRpcValue > ValueStruct
Definition XmlRpcValue.h:39
~XmlRpcValue()
Destructor (make virtual if you want to subclass).
Definition XmlRpcValue.h:72
std::string boolToXml() const
static std::string const & getDoubleFormat()
Return the format used to write double values.
std::vector< XmlRpcValue > ValueArray
Definition XmlRpcValue.h:38
bool stringFromXml(std::string const &valueXml, int *offset)
std::ostream & write(std::ostream &os) const
Write the value (no xml encoding).
bool valid() const
Return true if the value has been set to something.
XmlRpcValue & operator=(int const &rhs)
Definition XmlRpcValue.h:79
XmlRpcValue & operator[](int i)
bool boolFromXml(std::string const &valueXml, int *offset)
BinaryData * asBinary
XmlRpcValue(const char *value)
Definition XmlRpcValue.h:51
std::string toXml() const
Encode the Value in xml.
void setSize(int size)
Specify the size for array values. Array values will grow beyond this size if needed.
std::string stringToXml() const
Type const & getType() const
Return the type of the value stored.
XmlRpcValue()
Constructors.
Definition XmlRpcValue.h:42
int t()
Definition t.c:1