OverSim
XmlRpc::XmlRpcValue Class Reference

A class to represent RPC arguments and results. More...

#include <XmlRpcValue.h>

Public Types

enum  Type {
  TypeInvalid, TypeBoolean, TypeInt, TypeDouble,
  TypeString, TypeDateTime, TypeBase64, TypeArray,
  TypeStruct
}
 XmlRpcValue types. More...
typedef std::vector< char > BinaryData
typedef std::vector< XmlRpcValueValueArray
typedef std::map< std::string,
XmlRpcValue
ValueStruct

Public Member Functions

 XmlRpcValue ()
 Construct an empty XmlRpcValue.
 XmlRpcValue (bool value)
 Construct an XmlRpcValue with a bool value.
 XmlRpcValue (int value)
 Construct an XmlRpcValue with an int value.
 XmlRpcValue (double value)
 Construct an XmlRpcValue with a double value.
 XmlRpcValue (std::string const &value)
 Construct an XmlRpcValue with a string value.
 XmlRpcValue (const char *value)
 Construct an XmlRpcValue with a string value.
 XmlRpcValue (struct tm *value)
 Construct an XmlRpcValue with a date/time value.
 XmlRpcValue (void *value, int nBytes)
 Construct an XmlRpcValue with a binary data value.
 XmlRpcValue (std::string const &xml, int *offset)
 Construct from xml, beginning at *offset chars into the string, updates offset.
 XmlRpcValue (XmlRpcValue const &rhs)
 Copy constructor.
 ~XmlRpcValue ()
 Destructor (make virtual if you want to subclass)
void clear ()
 Erase the current value.
XmlRpcValueoperator= (XmlRpcValue const &rhs)
 Assignment from one XmlRpcValue to this one.
XmlRpcValueoperator= (int const &rhs)
 Assign an int to this XmlRpcValue.
XmlRpcValueoperator= (double const &rhs)
 Assign a double to this XmlRpcValue.
XmlRpcValueoperator= (const char *rhs)
 Assign a string to this XmlRpcValue.
bool operator== (XmlRpcValue const &other) const
 Tests two XmlRpcValues for equality.
bool operator!= (XmlRpcValue const &other) const
 Tests two XmlRpcValues for inequality.
 operator bool & ()
 Treat an XmlRpcValue as a bool.
 operator int & ()
 Treat an XmlRpcValue as an int.
 operator double & ()
 Treat an XmlRpcValue as a double.
 operator std::string & ()
 Treat an XmlRpcValue as a string.
 operator BinaryData & ()
 Access the BinaryData value.
 operator struct tm & ()
 Access the DateTime value.
XmlRpcValue const & operator[] (int i) const
 Const array value accessor.
XmlRpcValueoperator[] (int i)
 Array value accessor.
XmlRpcValueoperator[] (std::string const &k)
 Struct entry accessor.
XmlRpcValueoperator[] (const char *k)
 Struct entry accessor.
 operator ValueStruct const & ()
 Access the struct value map.
bool isValid () const
 Return true if the value has been set to something.
Type const & getType () const
 Return the type of the value stored.
int size () const
 Return the size for string, base64, array, and struct values.
void setSize (int size)
 Specify the size for array values. Array values will grow beyond this size if needed.
bool hasMember (const std::string &name) const
 Check for the existence of a struct member by name.
bool fromXml (std::string const &valueXml, int *offset)
 Decode xml. Destroys any existing value.
std::string toXml () const
 Encode the Value in xml.
std::ostream & write (std::ostream &os) const
 Write the value (no xml encoding)

Static Public Member Functions

static std::string const & getDoubleFormat ()
 Return the format used to write double values.
static void setDoubleFormat (const char *f)
 Specify the format used to write double values.

Protected Member Functions

void invalidate ()
void assertTypeOrInvalid (Type t)
void assertArray (int size) const
void assertArray (int size)
void assertStruct ()
bool boolFromXml (std::string const &valueXml, int *offset)
bool intFromXml (std::string const &valueXml, int *offset)
bool doubleFromXml (std::string const &valueXml, int *offset)
bool stringFromXml (std::string const &valueXml, int *offset)
bool timeFromXml (std::string const &valueXml, int *offset)
bool binaryFromXml (std::string const &valueXml, int *offset)
bool arrayFromXml (std::string const &valueXml, int *offset)
bool structFromXml (std::string const &valueXml, int *offset)
std::string boolToXml () const
std::string intToXml () const
std::string doubleToXml () const
std::string stringToXml () const
std::string timeToXml () const
std::string binaryToXml () const
std::string arrayToXml () const
std::string structToXml () const

Protected Attributes

Type _type
union {
   bool   asBool
   int   asInt
   double   asDouble
   struct tm *   asTime
   std::string *   asString
   BinaryData *   asBinary
   ValueArray *   asArray
   ValueStruct *   asStruct
_value

Static Protected Attributes

static std::string _doubleFormat

Detailed Description

A class to represent RPC arguments and results.

Each XmlRpcValue object contains a typed value, where the type is determined by the initial value assigned to the object.

Definition at line 31 of file XmlRpcValue.h.

Member Typedef Documentation

typedef std::vector<char> XmlRpc::XmlRpcValue::BinaryData

Definition at line 48 of file XmlRpcValue.h.

Definition at line 49 of file XmlRpcValue.h.

typedef std::map<std::string, XmlRpcValue> XmlRpc::XmlRpcValue::ValueStruct

Definition at line 50 of file XmlRpcValue.h.

Member Enumeration Documentation

XmlRpcValue types.

Enumerator:
TypeInvalid 
TypeBoolean 
TypeInt 
TypeDouble 
TypeString 
TypeDateTime 
TypeBase64 
TypeArray 
TypeStruct 

Definition at line 35 of file XmlRpcValue.h.

Constructor & Destructor Documentation

XmlRpc::XmlRpcValue::XmlRpcValue ( )
inline

Construct an empty XmlRpcValue.

Definition at line 55 of file XmlRpcValue.h.

Referenced by operator=().

: _type(TypeInvalid) { _value.asBinary = 0; }
XmlRpc::XmlRpcValue::XmlRpcValue ( bool  value)
inline

Construct an XmlRpcValue with a bool value.

Definition at line 58 of file XmlRpcValue.h.

: _type(TypeBoolean) { _value.asBool = value; }
XmlRpc::XmlRpcValue::XmlRpcValue ( int  value)
inline

Construct an XmlRpcValue with an int value.

Definition at line 61 of file XmlRpcValue.h.

: _type(TypeInt) { _value.asInt = value; }
XmlRpc::XmlRpcValue::XmlRpcValue ( double  value)
inline

Construct an XmlRpcValue with a double value.

Definition at line 64 of file XmlRpcValue.h.

: _type(TypeDouble) { _value.asDouble = value; }
XmlRpc::XmlRpcValue::XmlRpcValue ( std::string const &  value)
inline

Construct an XmlRpcValue with a string value.

Definition at line 67 of file XmlRpcValue.h.

{ _value.asString = new std::string(value); }
XmlRpc::XmlRpcValue::XmlRpcValue ( const char *  value)
inline

Construct an XmlRpcValue with a string value.

Parameters
valueA null-terminated (C) string.

Definition at line 72 of file XmlRpcValue.h.

{ _value.asString = new std::string(value); }
XmlRpc::XmlRpcValue::XmlRpcValue ( struct tm *  value)
inline

Construct an XmlRpcValue with a date/time value.

Parameters
valueA pointer to a struct tm (see localtime)

Definition at line 77 of file XmlRpcValue.h.

{ _value.asTime = new struct tm(*value); }
XmlRpc::XmlRpcValue::XmlRpcValue ( void *  value,
int  nBytes 
)
inline

Construct an XmlRpcValue with a binary data value.

Parameters
valueA pointer to data
nBytesThe length of the data pointed to, in bytes

Definition at line 83 of file XmlRpcValue.h.

{
_value.asBinary = new BinaryData((char*)value, ((char*)value)+nBytes);
}
XmlRpc::XmlRpcValue::XmlRpcValue ( std::string const &  xml,
int *  offset 
)
inline

Construct from xml, beginning at *offset chars into the string, updates offset.

Definition at line 89 of file XmlRpcValue.h.

{ if ( ! fromXml(xml,offset)) _type = TypeInvalid; }
XmlRpc::XmlRpcValue::XmlRpcValue ( XmlRpcValue const &  rhs)
inline

Copy constructor.

Definition at line 93 of file XmlRpcValue.h.

: _type(TypeInvalid) { *this = rhs; }
XmlRpc::XmlRpcValue::~XmlRpcValue ( )
inline

Destructor (make virtual if you want to subclass)

Definition at line 96 of file XmlRpcValue.h.

{ invalidate(); }

Member Function Documentation

bool XmlRpc::XmlRpcValue::arrayFromXml ( std::string const &  valueXml,
int *  offset 
)
protected

Definition at line 465 of file XmlRpcValue.cc.

Referenced by fromXml().

{
if ( ! XmlRpcUtil::nextTagIs(DATA_TAG, valueXml, offset))
return false;
_value.asArray = new ValueArray;
while (v.fromXml(valueXml, offset))
_value.asArray->push_back(v); // copy...
// Skip the trailing </data>
(void) XmlRpcUtil::nextTagIs(DATA_ETAG, valueXml, offset);
return true;
}
std::string XmlRpc::XmlRpcValue::arrayToXml ( ) const
protected

Definition at line 484 of file XmlRpcValue.cc.

Referenced by toXml().

{
std::string xml = VALUE_TAG;
xml += ARRAY_TAG;
xml += DATA_TAG;
int s = int(_value.asArray->size());
for (int i=0; i<s; ++i)
xml += _value.asArray->at(i).toXml();
xml += DATA_ETAG;
xml += ARRAY_ETAG;
xml += VALUE_ETAG;
return xml;
}
void XmlRpc::XmlRpcValue::assertArray ( int  size) const
protected

Definition at line 92 of file XmlRpcValue.cc.

Referenced by operator[](), and setSize().

{
if (_type != TypeArray)
throw XmlRpcException("type error: expected an array");
else if (int(_value.asArray->size()) < size)
throw XmlRpcException("range error: array index too large");
}
void XmlRpc::XmlRpcValue::assertArray ( int  size)
protected

Definition at line 101 of file XmlRpcValue.cc.

{
if (_type == TypeInvalid) {
_value.asArray = new ValueArray(size);
} else if (_type == TypeArray) {
if (int(_value.asArray->size()) < size)
_value.asArray->resize(size);
} else
throw XmlRpcException("type error: expected an array");
}
void XmlRpc::XmlRpcValue::assertStruct ( )
protected

Definition at line 113 of file XmlRpcValue.cc.

Referenced by operator ValueStruct const &(), and operator[]().

{
if (_type == TypeInvalid) {
_value.asStruct = new ValueStruct();
} else if (_type != TypeStruct)
throw XmlRpcException("type error: expected a struct");
}
void XmlRpc::XmlRpcValue::assertTypeOrInvalid ( Type  t)
protected

Definition at line 74 of file XmlRpcValue.cc.

Referenced by operator BinaryData &(), operator bool &(), operator double &(), operator int &(), operator std::string &(), and operator struct tm &().

{
{
_type = t;
switch (_type) { // Ensure there is a valid value for the type
case TypeString: _value.asString = new std::string(); break;
case TypeDateTime: _value.asTime = new struct tm(); break;
case TypeBase64: _value.asBinary = new BinaryData(); break;
case TypeArray: _value.asArray = new ValueArray(); break;
case TypeStruct: _value.asStruct = new ValueStruct(); break;
default: _value.asBinary = 0; break;
}
}
else if (_type != t)
throw XmlRpcException("type error");
}
bool XmlRpc::XmlRpcValue::binaryFromXml ( std::string const &  valueXml,
int *  offset 
)
protected

Definition at line 423 of file XmlRpcValue.cc.

Referenced by fromXml().

{
size_t valueEnd = valueXml.find('<', *offset);
if (valueEnd == std::string::npos)
return false; // No end tag;
std::string asString = valueXml.substr(*offset, valueEnd-*offset);
_value.asBinary = new BinaryData();
// check whether base64 encodings can contain chars xml encodes...
// convert from base64 to binary
int iostatus = 0;
base64<char> decoder;
std::back_insert_iterator<BinaryData> ins = std::back_inserter(*(_value.asBinary));
decoder.get(asString.begin(), asString.end(), ins, iostatus);
*offset += int(asString.length());
return true;
}
std::string XmlRpc::XmlRpcValue::binaryToXml ( ) const
protected

Definition at line 445 of file XmlRpcValue.cc.

Referenced by toXml().

{
// convert to base64
std::vector<char> base64data;
int iostatus = 0;
base64<char> encoder;
std::back_insert_iterator<std::vector<char> > ins = std::back_inserter(base64data);
encoder.put(_value.asBinary->begin(), _value.asBinary->end(), ins, iostatus, base64<>::crlf());
// Wrap with xml
std::string xml = VALUE_TAG;
xml += BASE64_TAG;
xml.append(base64data.begin(), base64data.end());
xml += BASE64_ETAG;
xml += VALUE_ETAG;
return xml;
}
bool XmlRpc::XmlRpcValue::boolFromXml ( std::string const &  valueXml,
int *  offset 
)
protected

Definition at line 280 of file XmlRpcValue.cc.

Referenced by fromXml().

{
const char* valueStart = valueXml.c_str() + *offset;
char* valueEnd;
long ivalue = strtol(valueStart, &valueEnd, 10);
if (valueEnd == valueStart || (ivalue != 0 && ivalue != 1))
return false;
_value.asBool = (ivalue == 1);
*offset += int(valueEnd - valueStart);
return true;
}
std::string XmlRpc::XmlRpcValue::boolToXml ( ) const
protected

Definition at line 294 of file XmlRpcValue.cc.

Referenced by toXml().

{
std::string xml = VALUE_TAG;
xml += BOOLEAN_TAG;
xml += (_value.asBool ? "1" : "0");
xml += BOOLEAN_ETAG;
xml += VALUE_ETAG;
return xml;
}
void XmlRpc::XmlRpcValue::clear ( )
inline

Erase the current value.

Definition at line 99 of file XmlRpcValue.h.

Referenced by XmlRpc::XmlRpcClient::execute().

{ invalidate(); }
bool XmlRpc::XmlRpcValue::doubleFromXml ( std::string const &  valueXml,
int *  offset 
)
protected

Definition at line 333 of file XmlRpcValue.cc.

Referenced by fromXml().

{
const char* valueStart = valueXml.c_str() + *offset;
char* valueEnd;
double dvalue = strtod(valueStart, &valueEnd);
if (valueEnd == valueStart)
return false;
_value.asDouble = dvalue;
*offset += int(valueEnd - valueStart);
return true;
}
std::string XmlRpc::XmlRpcValue::doubleToXml ( ) const
protected

Definition at line 347 of file XmlRpcValue.cc.

Referenced by toXml().

{
char buf[256];
snprintf(buf, sizeof(buf)-1, getDoubleFormat().c_str(), _value.asDouble);
buf[sizeof(buf)-1] = 0;
std::string xml = VALUE_TAG;
xml += DOUBLE_TAG;
xml += buf;
xml += DOUBLE_ETAG;
xml += VALUE_ETAG;
return xml;
}
bool XmlRpc::XmlRpcValue::fromXml ( std::string const &  valueXml,
int *  offset 
)

Decode xml. Destroys any existing value.

Definition at line 219 of file XmlRpcValue.cc.

Referenced by arrayFromXml(), XmlRpc::XmlRpcClient::parseResponse(), and XmlRpcValue().

{
int savedOffset = *offset;
if ( ! XmlRpcUtil::nextTagIs(VALUE_TAG, valueXml, offset))
return false; // Not a value, offset not updated
int afterValueOffset = *offset;
std::string typeTag = XmlRpcUtil::getNextTag(valueXml, offset);
bool result = false;
if (typeTag == BOOLEAN_TAG)
result = boolFromXml(valueXml, offset);
else if (typeTag == I4_TAG || typeTag == INT_TAG)
result = intFromXml(valueXml, offset);
else if (typeTag == DOUBLE_TAG)
result = doubleFromXml(valueXml, offset);
else if (typeTag.empty() || typeTag == STRING_TAG)
result = stringFromXml(valueXml, offset);
else if (typeTag == DATETIME_TAG)
result = timeFromXml(valueXml, offset);
else if (typeTag == BASE64_TAG)
result = binaryFromXml(valueXml, offset);
else if (typeTag == ARRAY_TAG)
result = arrayFromXml(valueXml, offset);
else if (typeTag == STRUCT_TAG)
result = structFromXml(valueXml, offset);
// Watch for empty/blank strings with no <string>tag
else if (typeTag == VALUE_ETAG)
{
*offset = afterValueOffset; // back up & try again
result = stringFromXml(valueXml, offset);
}
if (result) // Skip over the </value> tag
XmlRpcUtil::findTag(VALUE_ETAG, valueXml, offset);
else // Unrecognized tag after <value>
*offset = savedOffset;
return result;
}
static std::string const& XmlRpc::XmlRpcValue::getDoubleFormat ( )
inlinestatic

Return the format used to write double values.

Definition at line 202 of file XmlRpcValue.h.

Referenced by doubleToXml().

{ return _doubleFormat; }
Type const& XmlRpc::XmlRpcValue::getType ( ) const
inline

Return the type of the value stored.

See Also
Type.

Definition at line 180 of file XmlRpcValue.h.

Referenced by XmlRpc::XmlRpcServer::executeMulticall(), and XmlRpc::XmlRpcClient::generateRequest().

{ return _type; }
bool XmlRpc::XmlRpcValue::hasMember ( const std::string &  name) const

Check for the existence of a struct member by name.

Definition at line 212 of file XmlRpcValue.cc.

{
return _type == TypeStruct && _value.asStruct->find(name) != _value.asStruct->end();
}
bool XmlRpc::XmlRpcValue::intFromXml ( std::string const &  valueXml,
int *  offset 
)
protected

Definition at line 305 of file XmlRpcValue.cc.

Referenced by fromXml().

{
const char* valueStart = valueXml.c_str() + *offset;
char* valueEnd;
long ivalue = strtol(valueStart, &valueEnd, 10);
if (valueEnd == valueStart)
return false;
_value.asInt = int(ivalue);
*offset += int(valueEnd - valueStart);
return true;
}
std::string XmlRpc::XmlRpcValue::intToXml ( ) const
protected

Definition at line 319 of file XmlRpcValue.cc.

Referenced by toXml().

{
char buf[256];
snprintf(buf, sizeof(buf)-1, "%d", _value.asInt);
buf[sizeof(buf)-1] = 0;
std::string xml = VALUE_TAG;
xml += I4_TAG;
xml += buf;
xml += I4_ETAG;
xml += VALUE_ETAG;
return xml;
}
void XmlRpc::XmlRpcValue::invalidate ( )
protected

Definition at line 58 of file XmlRpcValue.cc.

Referenced by clear(), fromXml(), operator=(), structFromXml(), and ~XmlRpcValue().

{
switch (_type) {
case TypeString: delete _value.asString; break;
case TypeDateTime: delete _value.asTime; break;
case TypeBase64: delete _value.asBinary; break;
case TypeArray: delete _value.asArray; break;
case TypeStruct: delete _value.asStruct; break;
default: break;
}
_value.asBinary = 0;
}
bool XmlRpc::XmlRpcValue::isValid ( void  ) const
inline

Return true if the value has been set to something.

Definition at line 177 of file XmlRpcValue.h.

Referenced by XmlRpc::XmlRpcServer::executeMethod(), XmlRpc::XmlRpcClient::generateRequest(), XmlRpc::XmlRpcClient::parseResponse(), and structFromXml().

{ return _type != TypeInvalid; }
XmlRpc::XmlRpcValue::operator BinaryData & ( )
inline

Access the BinaryData value.

Throws XmlRpcException if the value is initialized to a type that is not TypeBase64.

Definition at line 144 of file XmlRpcValue.h.

{ assertTypeOrInvalid(TypeBase64); return *_value.asBinary; }
XmlRpc::XmlRpcValue::operator bool & ( )
inline

Treat an XmlRpcValue as a bool.

Throws XmlRpcException if the value is initialized to a type that is not TypeBoolean.

Definition at line 124 of file XmlRpcValue.h.

XmlRpc::XmlRpcValue::operator double & ( )
inline

Treat an XmlRpcValue as a double.

Throws XmlRpcException if the value is initialized to a type that is not TypeDouble.

Definition at line 134 of file XmlRpcValue.h.

{ assertTypeOrInvalid(TypeDouble); return _value.asDouble; }
XmlRpc::XmlRpcValue::operator int & ( )
inline

Treat an XmlRpcValue as an int.

Throws XmlRpcException if the value is initialized to a type that is not TypeInt.

Definition at line 129 of file XmlRpcValue.h.

{ assertTypeOrInvalid(TypeInt); return _value.asInt; }
XmlRpc::XmlRpcValue::operator std::string & ( )
inline

Treat an XmlRpcValue as a string.

Throws XmlRpcException if the value is initialized to a type that is not TypeString.

Definition at line 139 of file XmlRpcValue.h.

{ assertTypeOrInvalid(TypeString); return *_value.asString; }
XmlRpc::XmlRpcValue::operator struct tm & ( )
inline

Access the DateTime value.

Throws XmlRpcException if the value is initialized to a type that is not TypeDateTime.

Definition at line 149 of file XmlRpcValue.h.

XmlRpc::XmlRpcValue::operator ValueStruct const & ( )
inline

Access the struct value map.

Can be used to iterate over the entries in the map to find all defined entries.

Definition at line 173 of file XmlRpcValue.h.

{ assertStruct(); return *_value.asStruct; }
bool XmlRpc::XmlRpcValue::operator!= ( XmlRpcValue const &  other) const

Tests two XmlRpcValues for inequality.

Definition at line 191 of file XmlRpcValue.cc.

{
return !(*this == other);
}
XmlRpcValue & XmlRpc::XmlRpcValue::operator= ( XmlRpcValue const &  rhs)

Assignment from one XmlRpcValue to this one.

Parameters
rhsThe value in rhs is copied to this value.

Definition at line 124 of file XmlRpcValue.cc.

{
if (this != &rhs)
{
_type = rhs._type;
switch (_type) {
case TypeBoolean: _value.asBool = rhs._value.asBool; break;
case TypeInt: _value.asInt = rhs._value.asInt; break;
case TypeDouble: _value.asDouble = rhs._value.asDouble; break;
case TypeDateTime: _value.asTime = new struct tm(*rhs._value.asTime); break;
case TypeString: _value.asString = new std::string(*rhs._value.asString); break;
case TypeBase64: _value.asBinary = new BinaryData(*rhs._value.asBinary); break;
case TypeArray: _value.asArray = new ValueArray(*rhs._value.asArray); break;
case TypeStruct: _value.asStruct = new ValueStruct(*rhs._value.asStruct); break;
default: _value.asBinary = 0; break;
}
}
return *this;
}
XmlRpcValue& XmlRpc::XmlRpcValue::operator= ( int const &  rhs)
inline

Assign an int to this XmlRpcValue.

Definition at line 107 of file XmlRpcValue.h.

Referenced by operator=().

{ return operator=(XmlRpcValue(rhs)); }
XmlRpcValue& XmlRpc::XmlRpcValue::operator= ( double const &  rhs)
inline

Assign a double to this XmlRpcValue.

Definition at line 110 of file XmlRpcValue.h.

Referenced by operator=().

{ return operator=(XmlRpcValue(rhs)); }
XmlRpcValue& XmlRpc::XmlRpcValue::operator= ( const char *  rhs)
inline

Assign a string to this XmlRpcValue.

Definition at line 113 of file XmlRpcValue.h.

Referenced by operator=().

{ return operator=(XmlRpcValue(std::string(rhs))); }
bool XmlRpc::XmlRpcValue::operator== ( XmlRpcValue const &  other) const

Tests two XmlRpcValues for equality.

Definition at line 153 of file XmlRpcValue.cc.

{
if (_type != other._type)
return false;
switch (_type) {
case TypeBoolean: return ( !_value.asBool && !other._value.asBool) ||
( _value.asBool && other._value.asBool);
case TypeInt: return _value.asInt == other._value.asInt;
case TypeDouble: return _value.asDouble == other._value.asDouble;
case TypeDateTime: return tmEq(*_value.asTime, *other._value.asTime);
case TypeString: return *_value.asString == *other._value.asString;
case TypeBase64: return *_value.asBinary == *other._value.asBinary;
case TypeArray: return *_value.asArray == *other._value.asArray;
// The map<>::operator== requires the definition of value< for kcc
case TypeStruct: //return *_value.asStruct == *other._value.asStruct;
{
if (_value.asStruct->size() != other._value.asStruct->size())
return false;
ValueStruct::const_iterator it1=_value.asStruct->begin();
ValueStruct::const_iterator it2=other._value.asStruct->begin();
while (it1 != _value.asStruct->end()) {
const XmlRpcValue& v1 = it1->second;
const XmlRpcValue& v2 = it2->second;
if ( ! (v1 == v2))
return false;
it1++;
it2++;
}
return true;
}
default: break;
}
return true; // Both invalid values ...
}
XmlRpcValue const& XmlRpc::XmlRpcValue::operator[] ( int  i) const
inline

Const array value accessor.

Access the ith value of the array. Throws XmlRpcException if the value is not an array or if the index i is not a valid index for the array.

Definition at line 156 of file XmlRpcValue.h.

{ assertArray(i+1); return _value.asArray->at(i); }
XmlRpcValue& XmlRpc::XmlRpcValue::operator[] ( int  i)
inline

Array value accessor.

Access the ith value of the array, growing the array if necessary. Throws XmlRpcException if the value is not an array.

Definition at line 161 of file XmlRpcValue.h.

{ assertArray(i+1); return _value.asArray->at(i); }
XmlRpcValue& XmlRpc::XmlRpcValue::operator[] ( std::string const &  k)
inline

Struct entry accessor.

Returns the value associated with the given entry, creating one if necessary.

Definition at line 165 of file XmlRpcValue.h.

{ assertStruct(); return (*_value.asStruct)[k]; }
XmlRpcValue& XmlRpc::XmlRpcValue::operator[] ( const char *  k)
inline

Struct entry accessor.

Returns the value associated with the given entry, creating one if necessary.

Definition at line 169 of file XmlRpcValue.h.

{ assertStruct(); std::string s(k); return (*_value.asStruct)[s]; }
static void XmlRpc::XmlRpcValue::setDoubleFormat ( const char *  f)
inlinestatic

Specify the format used to write double values.

Definition at line 205 of file XmlRpcValue.h.

{ _doubleFormat = f; }
void XmlRpc::XmlRpcValue::setSize ( int  size)
inline

Specify the size for array values. Array values will grow beyond this size if needed.

Definition at line 186 of file XmlRpcValue.h.

Referenced by XmlRpc::XmlRpcServer::executeMulticall(), XmlRpcInterface::handleRpcResponse(), and XmlRpc::XmlRpcServer::listMethods().

int XmlRpc::XmlRpcValue::size ( ) const

Return the size for string, base64, array, and struct values.

Definition at line 198 of file XmlRpcValue.cc.

Referenced by XmlRpcInterface::dumpDht(), XmlRpc::XmlRpcServer::executeMulticall(), XmlRpc::XmlRpcClient::generateRequest(), XmlRpcInterface::get(), XmlRpcInterface::joinOverlay(), XmlRpcInterface::localLookup(), XmlRpcInterface::lookup(), XmlRpcInterface::p2pnsRegister(), XmlRpcInterface::p2pnsResolve(), and XmlRpcInterface::put().

{
switch (_type) {
case TypeString: return int(_value.asString->size());
case TypeBase64: return int(_value.asBinary->size());
case TypeArray: return int(_value.asArray->size());
case TypeStruct: return int(_value.asStruct->size());
default: break;
}
throw XmlRpcException("type error");
}
bool XmlRpc::XmlRpcValue::stringFromXml ( std::string const &  valueXml,
int *  offset 
)
protected

Definition at line 362 of file XmlRpcValue.cc.

Referenced by fromXml().

{
size_t valueEnd = valueXml.find('<', *offset);
if (valueEnd == std::string::npos)
return false; // No end tag;
_value.asString = new std::string(XmlRpcUtil::xmlDecode(valueXml.substr(*offset, valueEnd-*offset)));
*offset += int(_value.asString->length());
return true;
}
std::string XmlRpc::XmlRpcValue::stringToXml ( ) const
protected

Definition at line 374 of file XmlRpcValue.cc.

Referenced by toXml().

{
std::string xml = VALUE_TAG;
//xml += STRING_TAG; optional
xml += XmlRpcUtil::xmlEncode(*_value.asString);
//xml += STRING_ETAG;
xml += VALUE_ETAG;
return xml;
}
bool XmlRpc::XmlRpcValue::structFromXml ( std::string const &  valueXml,
int *  offset 
)
protected

Definition at line 502 of file XmlRpcValue.cc.

Referenced by fromXml().

{
_value.asStruct = new ValueStruct;
while (XmlRpcUtil::nextTagIs(MEMBER_TAG, valueXml, offset)) {
// name
const std::string name = XmlRpcUtil::parseTag(NAME_TAG, valueXml, offset);
// value
XmlRpcValue val(valueXml, offset);
if ( ! val.isValid()) {
return false;
}
const std::pair<const std::string, XmlRpcValue> p(name, val);
_value.asStruct->insert(p);
(void) XmlRpcUtil::nextTagIs(MEMBER_ETAG, valueXml, offset);
}
return true;
}
std::string XmlRpc::XmlRpcValue::structToXml ( ) const
protected

Definition at line 527 of file XmlRpcValue.cc.

Referenced by toXml().

{
std::string xml = VALUE_TAG;
xml += STRUCT_TAG;
ValueStruct::const_iterator it;
for (it=_value.asStruct->begin(); it!=_value.asStruct->end(); ++it) {
xml += MEMBER_TAG;
xml += NAME_TAG;
xml += XmlRpcUtil::xmlEncode(it->first);
xml += NAME_ETAG;
xml += it->second.toXml();
xml += MEMBER_ETAG;
}
xml += STRUCT_ETAG;
xml += VALUE_ETAG;
return xml;
}
bool XmlRpc::XmlRpcValue::timeFromXml ( std::string const &  valueXml,
int *  offset 
)
protected

Definition at line 385 of file XmlRpcValue.cc.

Referenced by fromXml().

{
size_t valueEnd = valueXml.find('<', *offset);
if (valueEnd == std::string::npos)
return false; // No end tag;
std::string stime = valueXml.substr(*offset, valueEnd-*offset);
struct tm t;
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)
return false;
t.tm_year -= 1900;
t.tm_isdst = -1;
_value.asTime = new struct tm(t);
*offset += int(stime.length());
return true;
}
std::string XmlRpc::XmlRpcValue::timeToXml ( ) const
protected

Definition at line 405 of file XmlRpcValue.cc.

Referenced by toXml().

{
struct tm* t = _value.asTime;
char buf[20];
snprintf(buf, sizeof(buf)-1, "%04d%02d%02dT%02d:%02d:%02d",
1900+t->tm_year,t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
buf[sizeof(buf)-1] = 0;
std::string xml = VALUE_TAG;
xml += DATETIME_TAG;
xml += buf;
xml += DATETIME_ETAG;
xml += VALUE_ETAG;
return xml;
}
std::string XmlRpc::XmlRpcValue::toXml ( ) const

Encode the Value in xml.

Definition at line 262 of file XmlRpcValue.cc.

Referenced by XmlRpc::XmlRpcServer::executeRequest(), XmlRpc::XmlRpcServer::generateFaultResponse(), XmlRpc::XmlRpcClient::generateRequest(), and XmlRpcInterface::handleRpcResponse().

{
switch (_type) {
case TypeBoolean: return boolToXml();
case TypeInt: return intToXml();
case TypeDouble: return doubleToXml();
case TypeString: return stringToXml();
case TypeDateTime: return timeToXml();
case TypeBase64: return binaryToXml();
case TypeArray: return arrayToXml();
case TypeStruct: return structToXml();
default: break;
}
return std::string(); // Invalid value
}
std::ostream & XmlRpc::XmlRpcValue::write ( std::ostream &  os) const

Write the value (no xml encoding)

Definition at line 550 of file XmlRpcValue.cc.

Referenced by operator<<().

{
switch (_type) {
default: break;
case TypeBoolean: os << _value.asBool; break;
case TypeInt: os << _value.asInt; break;
case TypeDouble: os << _value.asDouble; break;
case TypeString: os << *_value.asString; break;
{
struct tm* t = _value.asTime;
char buf[20];
snprintf(buf, sizeof(buf)-1, "%4d%02d%02dT%02d:%02d:%02d",
t->tm_year,t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
buf[sizeof(buf)-1] = 0;
os << buf;
break;
}
case TypeBase64:
{
int iostatus = 0;
std::ostreambuf_iterator<char> out(os);
base64<char> encoder;
encoder.put(_value.asBinary->begin(), _value.asBinary->end(), out, iostatus, base64<>::crlf());
break;
}
case TypeArray:
{
int s = int(_value.asArray->size());
os << '{';
for (int i=0; i<s; ++i)
{
if (i > 0) os << ',';
_value.asArray->at(i).write(os);
}
os << '}';
break;
}
case TypeStruct:
{
os << '[';
ValueStruct::const_iterator it;
for (it=_value.asStruct->begin(); it!=_value.asStruct->end(); ++it)
{
if (it!=_value.asStruct->begin()) os << ',';
os << it->first << ':';
it->second.write(os);
}
os << ']';
break;
}
}
return os;
}

Member Data Documentation

std::string XmlRpc::XmlRpcValue::_doubleFormat
staticprotected

Definition at line 239 of file XmlRpcValue.h.

Referenced by getDoubleFormat(), and setDoubleFormat().

ValueArray* XmlRpc::XmlRpcValue::asArray

Definition at line 253 of file XmlRpcValue.h.

Referenced by operator=(), and operator==().

BinaryData* XmlRpc::XmlRpcValue::asBinary

Definition at line 252 of file XmlRpcValue.h.

Referenced by operator=(), and operator==().

bool XmlRpc::XmlRpcValue::asBool

Definition at line 247 of file XmlRpcValue.h.

Referenced by operator=(), and operator==().

double XmlRpc::XmlRpcValue::asDouble

Definition at line 249 of file XmlRpcValue.h.

Referenced by operator=(), and operator==().

int XmlRpc::XmlRpcValue::asInt

Definition at line 248 of file XmlRpcValue.h.

Referenced by operator=(), and operator==().

std::string* XmlRpc::XmlRpcValue::asString

Definition at line 251 of file XmlRpcValue.h.

Referenced by binaryFromXml(), operator=(), and operator==().

ValueStruct* XmlRpc::XmlRpcValue::asStruct

Definition at line 254 of file XmlRpcValue.h.

Referenced by operator=(), and operator==().

struct tm* XmlRpc::XmlRpcValue::asTime

Definition at line 250 of file XmlRpcValue.h.

Referenced by operator=(), and operator==().


The documentation for this class was generated from the following files: