2 #ifndef _XMLRPCVALUE_H_
3 #define _XMLRPCVALUE_H_
8 # pragma warning(disable:4786) // identifier was truncated in debug info
49 XmlRpcValue(
bool value) : _type(TypeBoolean) { _value.asBool = value; }
50 XmlRpcValue(
int value) : _type(TypeInt) { _value.asInt = value; }
51 XmlRpcValue(
double value) : _type(TypeDouble) { _value.asDouble = value; }
54 { _value.asString =
new std::string(value); }
57 { _value.asString =
new std::string(value); }
60 { _value.asTime =
new struct tm(*value); }
65 _value.asBinary =
new BinaryData((
char*)value, ((
char*)value)+nBytes);
69 XmlRpcValue(std::string
const& xml,
int* offset) : _type(TypeInvalid)
70 {
if ( !
fromXml(xml,offset)) _type = TypeInvalid; }
91 operator bool&() { assertTypeOrInvalid(TypeBoolean);
return _value.asBool; }
92 operator int&() { assertTypeOrInvalid(TypeInt);
return _value.asInt; }
93 operator double&() { assertTypeOrInvalid(TypeDouble);
return _value.asDouble; }
94 operator std::string&() { assertTypeOrInvalid(TypeString);
return *_value.asString; }
95 operator BinaryData&() { assertTypeOrInvalid(TypeBase64);
return *_value.asBinary; }
96 operator struct tm&() { assertTypeOrInvalid(TypeDateTime);
return *_value.asTime; }
98 operator const bool&()
const { assertTypeOrInvalid(TypeBoolean);
return _value.asBool; }
99 operator const int&()
const { assertTypeOrInvalid(TypeInt);
return _value.asInt; }
100 operator const double&()
const { assertTypeOrInvalid(TypeDouble);
return _value.asDouble; }
101 operator const std::string&()
const { assertTypeOrInvalid(TypeString);
return *_value.asString; }
102 operator const BinaryData&()
const { assertTypeOrInvalid(TypeBase64);
return *_value.asBinary; }
103 operator const struct tm&()
const { assertTypeOrInvalid(TypeDateTime);
return *_value.asTime; }
114 iterator end() {assertStruct();
return (*_value.asStruct).end(); }
121 bool valid()
const {
return _type != TypeInvalid; }
133 bool hasMember(
const std::string& name)
const;
136 bool fromXml(std::string
const& valueXml,
int* offset);
139 std::string toXml()
const;
142 std::ostream& write(std::ostream& os)
const;
157 void assertTypeOrInvalid(Type t)
const;
158 void assertTypeOrInvalid(Type t);
159 void assertArray(
int size)
const;
160 void assertArray(
int size);
161 void assertStruct()
const;
165 bool boolFromXml(std::string
const& valueXml,
int* offset);
166 bool intFromXml(std::string
const& valueXml,
int* offset);
167 bool doubleFromXml(std::string
const& valueXml,
int* offset);
168 bool stringFromXml(std::string
const& valueXml,
int* offset);
169 bool timeFromXml(std::string
const& valueXml,
int* offset);
170 bool binaryFromXml(std::string
const& valueXml,
int* offset);
171 bool arrayFromXml(std::string
const& valueXml,
int* offset);
172 bool structFromXml(std::string
const& valueXml,
int* offset);
175 std::string boolToXml()
const;
176 std::string intToXml()
const;
177 std::string doubleToXml()
const;
178 std::string stringToXml()
const;
179 std::string timeToXml()
const;
180 std::string binaryToXml()
const;
181 std::string arrayToXml()
const;
182 std::string structToXml()
const;
210 *os << value.
toXml();
219 #endif // _XMLRPCVALUE_H_