82 default:
_value.asBinary = 0;
break;
93 else if (
int(
_value.asArray->size()) < size)
104 if (
int(
_value.asArray->size()) < size)
105 _value.asArray->resize(size);
142 default:
_value.asBinary = 0;
break;
150 static bool tmEq(
struct tm
const& t1,
struct tm
const& t2) {
151 return t1.tm_sec == t2.tm_sec && t1.tm_min == t2.tm_min &&
152 t1.tm_hour == t2.tm_hour && t1.tm_mday == t2.tm_mday &&
153 t1.tm_mon == t2.tm_mon && t1.tm_year == t2.tm_year;
177 ValueStruct::const_iterator it1=
_value.asStruct->begin();
179 while (it1 !=
_value.asStruct->end()) {
196 return !(*
this == other);
224 int savedOffset = *offset;
230 int afterValueOffset = *offset;
233 if (typeTag == BOOLEAN_TAG)
235 else if (typeTag == I4_TAG || typeTag == INT_TAG)
237 else if (typeTag == DOUBLE_TAG)
239 else if (typeTag.empty() || typeTag ==
STRING_TAG)
241 else if (typeTag == DATETIME_TAG)
243 else if (typeTag == BASE64_TAG)
245 else if (typeTag == ARRAY_TAG)
247 else if (typeTag == STRUCT_TAG)
250 else if (typeTag == VALUE_ETAG)
252 *offset = afterValueOffset;
259 *offset = savedOffset;
278 return std::string();
285 const char* valueStart = valueXml.c_str() + *offset;
287 long ivalue = strtol(valueStart, &valueEnd, 10);
288 if (valueEnd == valueStart || (ivalue != 0 && ivalue != 1))
292 _value.asBool = (ivalue == 1);
293 *offset += int(valueEnd - valueStart);
301 xml += (
_value.asBool ?
"1" :
"0");
310 const char* valueStart = valueXml.c_str() + *offset;
312 long ivalue = strtol(valueStart, &valueEnd, 10);
313 if (valueEnd == valueStart)
317 _value.asInt = int(ivalue);
318 *offset += int(valueEnd - valueStart);
325 snprintf(buf,
sizeof(buf)-1,
"%d",
_value.asInt);
326 buf[
sizeof(buf)-1] = 0;
338 const char* valueStart = valueXml.c_str() + *offset;
345 std::string tmplocale;
346 char* locale_cstr = setlocale(LC_NUMERIC, 0);
349 tmplocale = locale_cstr;
350 setlocale(LC_NUMERIC,
"POSIX");
353 double dvalue = strtod(valueStart, &valueEnd);
355 if (tmplocale.size() > 0) {
356 setlocale(LC_NUMERIC, tmplocale.c_str());
359 if (valueEnd == valueStart)
364 *offset += int(valueEnd - valueStart);
371 std::stringstream ss;
372 ss.imbue(std::locale::classic());
387 size_t valueEnd = valueXml.find(
'<', *offset);
388 if (valueEnd == std::string::npos)
393 *offset += int(
_value.asString->length());
410 size_t valueEnd = valueXml.find(
'<', *offset);
411 if (valueEnd == std::string::npos)
414 std::string stime = valueXml.substr(*offset, valueEnd-*offset);
418 if (sscanf_s(stime.c_str(),
"%4d%2d%2dT%2d:%2d:%2d",&t.tm_year,&t.tm_mon,&t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec) != 6)
420 if (sscanf(stime.c_str(),
"%4d%2d%2dT%2d:%2d:%2d",&t.tm_year,&t.tm_mon,&t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec) != 6)
426 _value.asTime =
new struct tm(t);
427 *offset += int(stime.length());
433 struct tm* t =
_value.asTime;
435 snprintf(buf,
sizeof(buf)-1,
"%4d%02d%02dT%02d:%02d:%02d",
436 t->tm_year,t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
437 buf[
sizeof(buf)-1] = 0;
451 size_t valueEnd = valueXml.find(
'<', *offset);
452 if (valueEnd == std::string::npos)
456 std::string
asString = valueXml.substr(*offset, valueEnd-*offset);
463 std::back_insert_iterator<BinaryData> ins = std::back_inserter(*(
_value.asBinary));
464 decoder.
get(asString.begin(), asString.end(), ins, iostatus);
466 *offset += int(asString.length());
474 std::vector<char> base64data;
477 std::back_insert_iterator<std::vector<char> > ins = std::back_inserter(base64data);
483 xml.append(base64data.begin(), base64data.end());
499 while (v.
fromXml(valueXml, offset))
500 _value.asArray->push_back(v);
516 int s = int(
_value.asArray->size());
517 for (
int i=0; i<
s; ++i)
518 xml +=
_value.asArray->at(i).toXml();
538 if ( ! val.
valid()) {
542 const std::pair<const std::string, XmlRpcValue> p(name, val);
543 _value.asStruct->insert(p);
558 ValueStruct::const_iterator it;
559 for (it=
_value.asStruct->begin(); it!=
_value.asStruct->end(); ++it) {
564 xml += it->second.toXml();
585 struct tm* t =
_value.asTime;
587 snprintf(buf,
sizeof(buf)-1,
"%4d%02d%02dT%02d:%02d:%02d",
588 t->tm_year,t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
589 buf[
sizeof(buf)-1] = 0;
596 std::ostreambuf_iterator<char> out(os);
603 int s = int(
_value.asArray->size());
605 for (
int i=0; i<
s; ++i)
607 if (i > 0) os <<
',';
608 _value.asArray->at(i).write(os);
616 ValueStruct::const_iterator it;
617 for (it=
_value.asStruct->begin(); it!=
_value.asStruct->end(); ++it)
619 if (it!=
_value.asStruct->begin()) os <<
',';
620 os << it->first <<
':';
621 it->second.write(os);
static const char ARRAY_ETAG[]
bool intFromXml(std::string const &valueXml, int *offset)
static const char BASE64_TAG[]
std::string arrayToXml() const
static const char NAME_TAG[]
std::vector< XmlRpcValue > ValueArray
static const char DOUBLE_TAG[]
static const char DATA_ETAG[]
RPC method arguments and results are represented by Values.
std::string doubleToXml() const
static const char STRUCT_ETAG[]
static const char VALUE_ETAG[]
void assertTypeOrInvalid(Type t)
static const char DOUBLE_ETAG[]
std::string timeToXml() const
std::string stringToXml() const
static const char BASE64_ETAG[]
std::string intToXml() const
static const char ARRAY_TAG[]
static const char DATA_TAG[]
int size() const
Return the size for string, base64, array, and struct values.
static const char NAME_ETAG[]
static std::string getNextTag(std::string const &xml, int *offset)
static std::string parseTag(const char *tag, std::string const &xml, int *offset)
Returns contents between <tag> and </tag>, updates offset to char after </tag>
XmlRpcValue & operator=(XmlRpcValue const &rhs)
bool valid() const
Return true if the value has been set to something.
_II get(_II _First, _II _Last, _OI _To, _State &_St) const
static bool findTag(const char *tag, std::string const &xml, int *offset)
Returns true if the tag is found and updates offset to the char after the tag.
std::string boolToXml() const
void assertStruct() const
static const char MEMBER_ETAG[]
static const char BOOLEAN_ETAG[]
static const char STRING_TAG[]
union XmlRpc::XmlRpcValue::@0 _value
static const char DATETIME_TAG[]
std::map< std::string, XmlRpcValue > ValueStruct
std::string toXml() const
Encode the Value in xml.
void assertArray(int size) const
static const char VALUE_TAG[]
std::string structToXml() const
std::string binaryToXml() const
bool stringFromXml(std::string const &valueXml, int *offset)
static const char I4_ETAG[]
bool fromXml(std::string const &valueXml, int *offset)
Decode xml. Destroys any existing value.
bool operator==(XmlRpcValue const &other) const
static const char I4_TAG[]
bool hasMember(const std::string &name) const
Check for the existence of a struct member by name.
std::ostream & write(std::ostream &os) const
Write the value (no xml encoding)
bool binaryFromXml(std::string const &valueXml, int *offset)
static const char DATETIME_ETAG[]
static bool tmEq(struct tm const &t1, struct tm const &t2)
bool doubleFromXml(std::string const &valueXml, int *offset)
static std::string xmlEncode(const std::string &raw)
Convert raw text to encoded xml.
bool timeFromXml(std::string const &valueXml, int *offset)
static const char INT_TAG[]
std::vector< char > BinaryData
static const char BOOLEAN_TAG[]
bool operator!=(XmlRpcValue const &other) const
std::ostream & operator<<(std::ostream &os, const XmlRpc::XmlRpcValue &v)
static std::string _doubleFormat
_II put(_II _First, _II _Last, _OI _To, _State &, _Endline) const
bool arrayFromXml(std::string const &valueXml, int *offset)
static std::string xmlDecode(const std::string &encoded)
Convert encoded xml to raw text.
bool structFromXml(std::string const &valueXml, int *offset)
bool boolFromXml(std::string const &valueXml, int *offset)
static const char MEMBER_TAG[]
static bool nextTagIs(const char *tag, std::string const &xml, int *offset)
static const char STRUCT_TAG[]