BOSS 6.6.4.p01
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 <vector>
15# include <time.h>
16#endif
17
18namespace XmlRpc {
19
20 //! RPC method arguments and results are represented by Values
21 // should probably refcount them...
23 public:
24
25
26 enum Type {
36 };
37
38 // Non-primitive types
39 typedef std::vector<char> BinaryData;
40 typedef std::vector<XmlRpcValue> ValueArray;
41 typedef std::map<std::string, XmlRpcValue> ValueStruct;
42
43
44 //! Constructors
45 XmlRpcValue() : _type(TypeInvalid) { _value.asBinary = 0; }
46 XmlRpcValue(bool value) : _type(TypeBoolean) { _value.asBool = value; }
47 XmlRpcValue(int value) : _type(TypeInt) { _value.asInt = value; }
48 XmlRpcValue(double value) : _type(TypeDouble) { _value.asDouble = value; }
49
50 XmlRpcValue(std::string const& value) : _type(TypeString)
51 { _value.asString = new std::string(value); }
52
53 XmlRpcValue(const char* value) : _type(TypeString)
54 { _value.asString = new std::string(value); }
55
56 XmlRpcValue(struct tm* value) : _type(TypeDateTime)
57 { _value.asTime = new struct tm(*value); }
58
59
60 XmlRpcValue(void* value, int nBytes) : _type(TypeBase64)
61 {
62 _value.asBinary = new BinaryData((char*)value, ((char*)value)+nBytes);
63 }
64
65 //! Construct from xml, beginning at *offset chars into the string, updates offset
66 XmlRpcValue(std::string const& xml, int* offset) : _type(TypeInvalid)
67 { if ( ! fromXml(xml,offset)) _type = TypeInvalid; }
68
69 //! Copy
70 XmlRpcValue(XmlRpcValue const& rhs) : _type(TypeInvalid) { *this = rhs; }
71
72 //! Destructor (make virtual if you want to subclass)
73 /*virtual*/ ~XmlRpcValue() { invalidate(); }
74
75 //! Erase the current value
76 void clear() { invalidate(); }
77
78 // Operators
80 XmlRpcValue& operator=(int const& rhs) { return operator=(XmlRpcValue(rhs)); }
81 XmlRpcValue& operator=(double const& rhs) { return operator=(XmlRpcValue(rhs)); }
82 XmlRpcValue& operator=(const char* rhs) { return operator=(XmlRpcValue(std::string(rhs))); }
83
84 bool operator==(XmlRpcValue const& other) const;
85 bool operator!=(XmlRpcValue const& other) const;
86
87 operator bool&() { assertTypeOrInvalid(TypeBoolean); return _value.asBool; }
88 operator int&() { assertTypeOrInvalid(TypeInt); return _value.asInt; }
89 operator double&() { assertTypeOrInvalid(TypeDouble); return _value.asDouble; }
90 operator std::string&() { assertTypeOrInvalid(TypeString); return *_value.asString; }
91 operator BinaryData&() { assertTypeOrInvalid(TypeBase64); return *_value.asBinary; }
92 operator struct tm&() { assertTypeOrInvalid(TypeDateTime); return *_value.asTime; }
93
94 XmlRpcValue const& operator[](int i) const { assertArray(i+1); return _value.asArray->at(i); }
95 XmlRpcValue& operator[](int i) { assertArray(i+1); return _value.asArray->at(i); }
96
97 XmlRpcValue& operator[](std::string const& k) { assertStruct(); return (*_value.asStruct)[k]; }
98 XmlRpcValue& operator[](const char* k) { assertStruct(); std::string s(k); return (*_value.asStruct)[s]; }
99
100 // Accessors
101 //! Return true if the value has been set to something.
102 bool valid() const { return _type != TypeInvalid; }
103
104 //! Return the type of the value stored. \see Type.
105 Type const &getType() const { return _type; }
106
107 //! Return the size for string, base64, array, and struct values.
108 int size() const;
109
110 //! Specify the size for array values. Array values will grow beyond this size if needed.
111 void setSize(int size) { assertArray(size); }
112
113 //! Check for the existence of a struct member by name.
114 bool hasMember(const std::string& name) const;
115
116 //! Decode xml. Destroys any existing value.
117 bool fromXml(std::string const& valueXml, int* offset);
118
119 //! Encode the Value in xml
120 std::string toXml() const;
121
122 //! Write the value (no xml encoding)
123 std::ostream& write(std::ostream& os) const;
124
125 // Formatting
126 //! Return the format used to write double values.
127 static std::string const& getDoubleFormat() { return _doubleFormat; }
128
129 //! Specify the format used to write double values.
130 static void setDoubleFormat(const char* f) { _doubleFormat = f; }
131
132
133 protected:
134 // Clean up
135 void invalidate();
136
137 // Type checking
139 void assertArray(int size) const;
140 void assertArray(int size);
141 void assertStruct();
142
143 // XML decoding
144 bool boolFromXml(std::string const& valueXml, int* offset);
145 bool intFromXml(std::string const& valueXml, int* offset);
146 bool doubleFromXml(std::string const& valueXml, int* offset);
147 bool stringFromXml(std::string const& valueXml, int* offset);
148 bool timeFromXml(std::string const& valueXml, int* offset);
149 bool binaryFromXml(std::string const& valueXml, int* offset);
150 bool arrayFromXml(std::string const& valueXml, int* offset);
151 bool structFromXml(std::string const& valueXml, int* offset);
152
153 // XML encoding
154 std::string boolToXml() const;
155 std::string intToXml() const;
156 std::string doubleToXml() const;
157 std::string stringToXml() const;
158 std::string timeToXml() const;
159 std::string binaryToXml() const;
160 std::string arrayToXml() const;
161 std::string structToXml() const;
162
163 // Format strings
164 static std::string _doubleFormat;
165
166 // Type tag and values
168
169 // At some point I will split off Arrays and Structs into
170 // separate ref-counted objects for more efficient copying.
171 union {
172 bool asBool;
173 int asInt;
174 double asDouble;
175 struct tm* asTime;
176 std::string* asString;
181
182 };
183} // namespace XmlRpc
184
185
186std::ostream& operator<<(std::ostream& os, XmlRpc::XmlRpcValue& v);
187
188
189#endif // _XMLRPCVALUE_H_
XmlRpcServer s
Definition: HelloServer.cpp:11
**********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:39
struct tm * asTime
Definition: XmlRpcValue.h:175
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)
Definition: XmlRpcValue.h:98
ValueStruct * asStruct
Definition: XmlRpcValue.h:179
XmlRpcValue(int value)
Definition: XmlRpcValue.h:47
XmlRpcValue(std::string const &value)
Definition: XmlRpcValue.h:50
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:82
void assertArray(int size) const
Definition: XmlRpcValue.cpp:87
XmlRpcValue & operator=(double const &rhs)
Definition: XmlRpcValue.h:81
XmlRpcValue const & operator[](int i) const
Definition: XmlRpcValue.h:94
std::string arrayToXml() const
std::string timeToXml() const
void assertTypeOrInvalid(Type t)
Definition: XmlRpcValue.cpp:69
std::string structToXml() const
void clear()
Erase the current value.
Definition: XmlRpcValue.h:76
XmlRpcValue(std::string const &xml, int *offset)
Construct from xml, beginning at *offset chars into the string, updates offset.
Definition: XmlRpcValue.h:66
bool doubleFromXml(std::string const &valueXml, int *offset)
XmlRpcValue(void *value, int nBytes)
Definition: XmlRpcValue.h:60
ValueArray * asArray
Definition: XmlRpcValue.h:178
static void setDoubleFormat(const char *f)
Specify the format used to write double values.
Definition: XmlRpcValue.h:130
bool arrayFromXml(std::string const &valueXml, int *offset)
bool operator!=(XmlRpcValue const &other) const
XmlRpcValue(bool value)
Definition: XmlRpcValue.h:46
XmlRpcValue(XmlRpcValue const &rhs)
Copy.
Definition: XmlRpcValue.h:70
XmlRpcValue(double value)
Definition: XmlRpcValue.h:48
XmlRpcValue & operator[](std::string const &k)
Definition: XmlRpcValue.h:97
std::string * asString
Definition: XmlRpcValue.h:176
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
union XmlRpc::XmlRpcValue::@47 _value
XmlRpcValue(struct tm *value)
Definition: XmlRpcValue.h:56
static std::string _doubleFormat
Definition: XmlRpcValue.h:164
std::map< std::string, XmlRpcValue > ValueStruct
Definition: XmlRpcValue.h:41
~XmlRpcValue()
Destructor (make virtual if you want to subclass)
Definition: XmlRpcValue.h:73
std::string boolToXml() const
static std::string const & getDoubleFormat()
Return the format used to write double values.
Definition: XmlRpcValue.h:127
std::vector< XmlRpcValue > ValueArray
Definition: XmlRpcValue.h:40
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.
Definition: XmlRpcValue.h:102
XmlRpcValue & operator=(int const &rhs)
Definition: XmlRpcValue.h:80
XmlRpcValue & operator[](int i)
Definition: XmlRpcValue.h:95
bool boolFromXml(std::string const &valueXml, int *offset)
BinaryData * asBinary
Definition: XmlRpcValue.h:177
XmlRpcValue(const char *value)
Definition: XmlRpcValue.h:53
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.
Definition: XmlRpcValue.h:111
std::string stringToXml() const
Type const & getType() const
Return the type of the value stored.
Definition: XmlRpcValue.h:105
XmlRpcValue()
Constructors.
Definition: XmlRpcValue.h:45
Definition: XmlRpc.h:35
int t()
Definition: t.c:1