3 #ifndef _XMLRPCVALUE_H_
4 #define _XMLRPCVALUE_H_
9 # pragma warning(disable:4786) // identifier was truncated in debug info
12 #include "xmlrpcpp/XmlRpcDecl.h"
42 typedef std::vector<char> BinaryData;
43 typedef std::vector<XmlRpcValue> ValueArray;
44 typedef std::map<std::string, XmlRpcValue> ValueStruct;
45 typedef ValueStruct::iterator iterator;
49 XmlRpcValue() : _type(TypeInvalid) { _value.asBinary = 0; }
50 XmlRpcValue(
bool value) : _type(TypeBoolean) { _value.asBool = value; }
51 XmlRpcValue(
int value) : _type(TypeInt) { _value.asInt = value; }
52 XmlRpcValue(
double value) : _type(TypeDouble) { _value.asDouble = value; }
54 XmlRpcValue(std::string
const& value) : _type(TypeString)
55 { _value.asString =
new std::string(value); }
57 XmlRpcValue(
const char* value) : _type(TypeString)
58 { _value.asString =
new std::string(value); }
60 XmlRpcValue(
struct tm* value) : _type(TypeDateTime)
61 { _value.asTime =
new struct tm(*value); }
64 XmlRpcValue(
void* value,
int nBytes) : _type(TypeBase64)
66 _value.asBinary =
new BinaryData((
char*)value, ((
char*)value)+nBytes);
70 XmlRpcValue(std::string
const& xml,
int* offset) : _type(TypeInvalid)
71 {
if ( !
fromXml(xml,offset)) _type = TypeInvalid; }
74 XmlRpcValue(XmlRpcValue
const& rhs) : _type(TypeInvalid) { *
this = rhs; }
77 ~XmlRpcValue() { invalidate(); }
80 void clear() { invalidate(); }
83 XmlRpcValue& operator=(XmlRpcValue
const& rhs);
84 XmlRpcValue& operator=(
int const& rhs) {
return operator=(XmlRpcValue(rhs)); }
85 XmlRpcValue& operator=(
double const& rhs) {
return operator=(XmlRpcValue(rhs)); }
86 XmlRpcValue& operator=(
const char* rhs) {
return operator=(XmlRpcValue(std::string(rhs))); }
88 bool operator==(XmlRpcValue
const& other)
const;
89 bool operator!=(XmlRpcValue
const& other)
const;
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 XmlRpcValue
const& operator[](
int i)
const { assertArray(i+1);
return _value.asArray->at(i); }
99 XmlRpcValue& operator[](
int i) { assertArray(i+1);
return _value.asArray->at(i); }
101 XmlRpcValue& operator[](std::string
const& k) { assertStruct();
return (*_value.asStruct)[k]; }
102 XmlRpcValue& operator[](
const char* k) { assertStruct(); std::string
s(k);
return (*_value.asStruct)[
s]; }
104 iterator begin() {assertStruct();
return (*_value.asStruct).begin(); }
105 iterator end() {assertStruct();
return (*_value.asStruct).end(); }
109 bool valid()
const {
return _type != TypeInvalid; }
112 Type
const &getType()
const {
return _type; }
118 void setSize(
int size) { assertArray(size); }
121 bool hasMember(
const std::string&
name)
const;
124 bool fromXml(std::string
const& valueXml,
int* offset);
127 std::string toXml()
const;
130 std::ostream& write(std::ostream& os)
const;
134 static std::string
const& getDoubleFormat() {
return _doubleFormat; }
137 static void setDoubleFormat(
const char*
f) { _doubleFormat =
f; }
145 void assertTypeOrInvalid(Type
t);
146 void assertArray(
int size)
const;
147 void assertArray(
int size);
151 bool boolFromXml(std::string
const& valueXml,
int* offset);
152 bool intFromXml(std::string
const& valueXml,
int* offset);
153 bool doubleFromXml(std::string
const& valueXml,
int* offset);
154 bool stringFromXml(std::string
const& valueXml,
int* offset);
155 bool timeFromXml(std::string
const& valueXml,
int* offset);
156 bool binaryFromXml(std::string
const& valueXml,
int* offset);
157 bool arrayFromXml(std::string
const& valueXml,
int* offset);
158 bool structFromXml(std::string
const& valueXml,
int* offset);
161 std::string boolToXml()
const;
162 std::string intToXml()
const;
163 std::string doubleToXml()
const;
164 std::string stringToXml()
const;
165 std::string timeToXml()
const;
166 std::string binaryToXml()
const;
167 std::string arrayToXml()
const;
168 std::string structToXml()
const;
171 static std::string _doubleFormat;
183 std::string* asString;
184 BinaryData* asBinary;
186 ValueStruct* asStruct;
196 #endif // _XMLRPCVALUE_H_