BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
XmlRpc::XmlRpcValue Class Reference

RPC method arguments and results are represented by Values. More...

#include <XmlRpcValue.h>

Public Types

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

Public Member Functions

 XmlRpcValue ()
 Constructors.
 
 XmlRpcValue (bool value)
 
 XmlRpcValue (int value)
 
 XmlRpcValue (double value)
 
 XmlRpcValue (std::string const &value)
 
 XmlRpcValue (const char *value)
 
 XmlRpcValue (struct tm *value)
 
 XmlRpcValue (void *value, int nBytes)
 
 XmlRpcValue (std::string const &xml, int *offset)
 Construct from xml, beginning at *offset chars into the string, updates offset.
 
 XmlRpcValue (XmlRpcValue const &rhs)
 Copy.
 
 ~XmlRpcValue ()
 Destructor (make virtual if you want to subclass)
 
void clear ()
 Erase the current value.
 
XmlRpcValueoperator= (XmlRpcValue const &rhs)
 
XmlRpcValueoperator= (int const &rhs)
 
XmlRpcValueoperator= (double const &rhs)
 
XmlRpcValueoperator= (const char *rhs)
 
bool operator== (XmlRpcValue const &other) const
 
bool operator!= (XmlRpcValue const &other) const
 
 operator bool & ()
 
 operator int & ()
 
 operator double & ()
 
 operator std::string & ()
 
 operator BinaryData & ()
 
 operator struct tm & ()
 
XmlRpcValue const & operator[] (int i) const
 
XmlRpcValueoperator[] (int i)
 
XmlRpcValueoperator[] (std::string const &k)
 
XmlRpcValueoperator[] (const char *k)
 
bool valid () 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

RPC method arguments and results are represented by Values.

Definition at line 22 of file XmlRpcValue.h.

Member Typedef Documentation

◆ BinaryData

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

Definition at line 39 of file XmlRpcValue.h.

◆ ValueArray

Definition at line 40 of file XmlRpcValue.h.

◆ ValueStruct

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

Definition at line 41 of file XmlRpcValue.h.

Member Enumeration Documentation

◆ Type

Enumerator
TypeInvalid 
TypeBoolean 
TypeInt 
TypeDouble 
TypeString 
TypeDateTime 
TypeBase64 
TypeArray 
TypeStruct 

Definition at line 26 of file XmlRpcValue.h.

Constructor & Destructor Documentation

◆ XmlRpcValue() [1/10]

XmlRpc::XmlRpcValue::XmlRpcValue ( )
inline

Constructors.

Definition at line 45 of file XmlRpcValue.h.

45: _type(TypeInvalid) { _value.asBinary = 0; }
union XmlRpc::XmlRpcValue::@47 _value

Referenced by operator=().

◆ XmlRpcValue() [2/10]

XmlRpc::XmlRpcValue::XmlRpcValue ( bool  value)
inline

Definition at line 46 of file XmlRpcValue.h.

46: _type(TypeBoolean) { _value.asBool = value; }

◆ XmlRpcValue() [3/10]

XmlRpc::XmlRpcValue::XmlRpcValue ( int  value)
inline

Definition at line 47 of file XmlRpcValue.h.

47: _type(TypeInt) { _value.asInt = value; }

◆ XmlRpcValue() [4/10]

XmlRpc::XmlRpcValue::XmlRpcValue ( double  value)
inline

Definition at line 48 of file XmlRpcValue.h.

48: _type(TypeDouble) { _value.asDouble = value; }

◆ XmlRpcValue() [5/10]

XmlRpc::XmlRpcValue::XmlRpcValue ( std::string const &  value)
inline

Definition at line 50 of file XmlRpcValue.h.

51 { _value.asString = new std::string(value); }

◆ XmlRpcValue() [6/10]

XmlRpc::XmlRpcValue::XmlRpcValue ( const char *  value)
inline

Definition at line 53 of file XmlRpcValue.h.

54 { _value.asString = new std::string(value); }

◆ XmlRpcValue() [7/10]

XmlRpc::XmlRpcValue::XmlRpcValue ( struct tm *  value)
inline

Definition at line 56 of file XmlRpcValue.h.

57 { _value.asTime = new struct tm(*value); }

◆ XmlRpcValue() [8/10]

XmlRpc::XmlRpcValue::XmlRpcValue ( void *  value,
int  nBytes 
)
inline

Definition at line 60 of file XmlRpcValue.h.

61 {
62 _value.asBinary = new BinaryData((char*)value, ((char*)value)+nBytes);
63 }
std::vector< char > BinaryData
Definition: XmlRpcValue.h:39

◆ XmlRpcValue() [9/10]

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 66 of file XmlRpcValue.h.

67 { if ( ! fromXml(xml,offset)) _type = TypeInvalid; }
bool fromXml(std::string const &valueXml, int *offset)
Decode xml. Destroys any existing value.

◆ XmlRpcValue() [10/10]

XmlRpc::XmlRpcValue::XmlRpcValue ( XmlRpcValue const &  rhs)
inline

Copy.

Definition at line 70 of file XmlRpcValue.h.

70: _type(TypeInvalid) { *this = rhs; }

◆ ~XmlRpcValue()

XmlRpc::XmlRpcValue::~XmlRpcValue ( )
inline

Destructor (make virtual if you want to subclass)

Definition at line 73 of file XmlRpcValue.h.

73{ invalidate(); }

Member Function Documentation

◆ arrayFromXml()

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

Definition at line 459 of file XmlRpcValue.cpp.

460 {
461 if ( ! XmlRpcUtil::nextTagIs(DATA_TAG, valueXml, offset))
462 return false;
463
465 _value.asArray = new ValueArray;
467 while (v.fromXml(valueXml, offset))
468 _value.asArray->push_back(v); // copy...
469
470 // Skip the trailing </data>
471 (void) XmlRpcUtil::nextTagIs(DATA_ETAG, valueXml, offset);
472 return true;
473 }
**********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
static bool nextTagIs(const char *tag, std::string const &xml, int *offset)
Definition: XmlRpcUtil.cpp:131
std::vector< XmlRpcValue > ValueArray
Definition: XmlRpcValue.h:40
XmlRpcValue()
Constructors.
Definition: XmlRpcValue.h:45

Referenced by fromXml().

◆ arrayToXml()

std::string XmlRpc::XmlRpcValue::arrayToXml ( ) const
protected

Definition at line 478 of file XmlRpcValue.cpp.

479 {
480 std::string xml = VALUE_TAG;
481 xml += ARRAY_TAG;
482 xml += DATA_TAG;
483
484 int s = int(_value.asArray->size());
485 for (int i=0; i<s; ++i)
486 xml += _value.asArray->at(i).toXml();
487
488 xml += DATA_ETAG;
489 xml += ARRAY_ETAG;
490 xml += VALUE_ETAG;
491 return xml;
492 }
XmlRpcServer s
Definition: HelloServer.cpp:11

Referenced by toXml().

◆ assertArray() [1/2]

void XmlRpc::XmlRpcValue::assertArray ( int  size)
protected

Definition at line 96 of file XmlRpcValue.cpp.

97 {
98 if (_type == TypeInvalid) {
100 _value.asArray = new ValueArray(size);
101 } else if (_type == TypeArray) {
102 if (int(_value.asArray->size()) < size)
103 _value.asArray->resize(size);
104 } else
105 throw XmlRpcException("type error: expected an array");
106 }
int size() const
Return the size for string, base64, array, and struct values.

◆ assertArray() [2/2]

void XmlRpc::XmlRpcValue::assertArray ( int  size) const
protected

Definition at line 87 of file XmlRpcValue.cpp.

88 {
89 if (_type != TypeArray)
90 throw XmlRpcException("type error: expected an array");
91 else if (int(_value.asArray->size()) < size)
92 throw XmlRpcException("range error: array index too large");
93 }

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

◆ assertStruct()

void XmlRpc::XmlRpcValue::assertStruct ( )
protected

Definition at line 108 of file XmlRpcValue.cpp.

109 {
110 if (_type == TypeInvalid) {
112 _value.asStruct = new ValueStruct();
113 } else if (_type != TypeStruct)
114 throw XmlRpcException("type error: expected a struct");
115 }
std::map< std::string, XmlRpcValue > ValueStruct
Definition: XmlRpcValue.h:41

Referenced by operator[]().

◆ assertTypeOrInvalid()

void XmlRpc::XmlRpcValue::assertTypeOrInvalid ( Type  t)
protected

Definition at line 69 of file XmlRpcValue.cpp.

70 {
71 if (_type == TypeInvalid)
72 {
73 _type = t;
74 switch (_type) { // Ensure there is a valid value for the type
75 case TypeString: _value.asString = new std::string(); break;
76 case TypeDateTime: _value.asTime = new struct tm(); break;
77 case TypeBase64: _value.asBinary = new BinaryData(); break;
78 case TypeArray: _value.asArray = new ValueArray(); break;
79 case TypeStruct: _value.asStruct = new ValueStruct(); break;
80 default: _value.asBinary = 0; break;
81 }
82 }
83 else if (_type != t)
84 throw XmlRpcException("type error");
85 }
int t()
Definition: t.c:1

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

◆ binaryFromXml()

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

Definition at line 417 of file XmlRpcValue.cpp.

418 {
419 size_t valueEnd = valueXml.find('<', *offset);
420 if (valueEnd == std::string::npos)
421 return false; // No end tag;
422
424 std::string asString = valueXml.substr(*offset, valueEnd-*offset);
425 _value.asBinary = new BinaryData();
426 // check whether base64 encodings can contain chars xml encodes...
427
428 // convert from base64 to binary
429 int iostatus = 0;
430 base64<char> decoder;
431 std::back_insert_iterator<BinaryData> ins = std::back_inserter(*(_value.asBinary));
432 decoder.get(asString.begin(), asString.end(), ins, iostatus);
433
434 *offset += int(asString.length());
435 return true;
436 }
std::string * asString
Definition: XmlRpcValue.h:176
Definition: base64.h:43
_II get(_II _First, _II _Last, _OI _To, _State &_St) const
Definition: base64.h:215

Referenced by fromXml().

◆ binaryToXml()

std::string XmlRpc::XmlRpcValue::binaryToXml ( ) const
protected

Definition at line 439 of file XmlRpcValue.cpp.

440 {
441 // convert to base64
442 std::vector<char> base64data;
443 int iostatus = 0;
444 base64<char> encoder;
445 std::back_insert_iterator<std::vector<char> > ins = std::back_inserter(base64data);
446 encoder.put(_value.asBinary->begin(), _value.asBinary->end(), ins, iostatus, base64<>::crlf());
447
448 // Wrap with xml
449 std::string xml = VALUE_TAG;
450 xml += BASE64_TAG;
451 xml.append(base64data.begin(), base64data.end());
452 xml += BASE64_ETAG;
453 xml += VALUE_ETAG;
454 return xml;
455 }
_II put(_II _First, _II _Last, _OI _To, _State &_St, _Endline _Endl) const
Definition: base64.h:155

Referenced by toXml().

◆ boolFromXml()

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

Definition at line 275 of file XmlRpcValue.cpp.

276 {
277 const char* valueStart = valueXml.c_str() + *offset;
278 char* valueEnd;
279 long ivalue = strtol(valueStart, &valueEnd, 10);
280 if (valueEnd == valueStart || (ivalue != 0 && ivalue != 1))
281 return false;
282
284 _value.asBool = (ivalue == 1);
285 *offset += int(valueEnd - valueStart);
286 return true;
287 }

Referenced by fromXml().

◆ boolToXml()

std::string XmlRpc::XmlRpcValue::boolToXml ( ) const
protected

Definition at line 289 of file XmlRpcValue.cpp.

290 {
291 std::string xml = VALUE_TAG;
292 xml += BOOLEAN_TAG;
293 xml += (_value.asBool ? "1" : "0");
294 xml += BOOLEAN_ETAG;
295 xml += VALUE_ETAG;
296 return xml;
297 }

Referenced by toXml().

◆ clear()

void XmlRpc::XmlRpcValue::clear ( )
inline

Erase the current value.

Definition at line 76 of file XmlRpcValue.h.

76{ invalidate(); }

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

◆ doubleFromXml()

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

Definition at line 328 of file XmlRpcValue.cpp.

329 {
330 const char* valueStart = valueXml.c_str() + *offset;
331 char* valueEnd;
332 double dvalue = strtod(valueStart, &valueEnd);
333 if (valueEnd == valueStart)
334 return false;
335
337 _value.asDouble = dvalue;
338 *offset += int(valueEnd - valueStart);
339 return true;
340 }

Referenced by fromXml().

◆ doubleToXml()

std::string XmlRpc::XmlRpcValue::doubleToXml ( ) const
protected

Definition at line 342 of file XmlRpcValue.cpp.

343 {
344 char buf[256];
345 snprintf(buf, sizeof(buf)-1, getDoubleFormat().c_str(), _value.asDouble);
346 buf[sizeof(buf)-1] = 0;
347
348 std::string xml = VALUE_TAG;
349 xml += DOUBLE_TAG;
350 xml += buf;
351 xml += DOUBLE_ETAG;
352 xml += VALUE_ETAG;
353 return xml;
354 }
static std::string const & getDoubleFormat()
Return the format used to write double values.
Definition: XmlRpcValue.h:127
char * c_str(Index i)
Definition: EvtCyclic3.cc:252

Referenced by toXml().

◆ fromXml()

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

Decode xml. Destroys any existing value.

Definition at line 214 of file XmlRpcValue.cpp.

215 {
216 int savedOffset = *offset;
217
218 invalidate();
219 if ( ! XmlRpcUtil::nextTagIs(VALUE_TAG, valueXml, offset))
220 return false; // Not a value, offset not updated
221
222 int afterValueOffset = *offset;
223 std::string typeTag = XmlRpcUtil::getNextTag(valueXml, offset);
224 bool result = false;
225 if (typeTag == BOOLEAN_TAG)
226 result = boolFromXml(valueXml, offset);
227 else if (typeTag == I4_TAG || typeTag == INT_TAG)
228 result = intFromXml(valueXml, offset);
229 else if (typeTag == DOUBLE_TAG)
230 result = doubleFromXml(valueXml, offset);
231 else if (typeTag.empty() || typeTag == STRING_TAG)
232 result = stringFromXml(valueXml, offset);
233 else if (typeTag == DATETIME_TAG)
234 result = timeFromXml(valueXml, offset);
235 else if (typeTag == BASE64_TAG)
236 result = binaryFromXml(valueXml, offset);
237 else if (typeTag == ARRAY_TAG)
238 result = arrayFromXml(valueXml, offset);
239 else if (typeTag == STRUCT_TAG)
240 result = structFromXml(valueXml, offset);
241 // Watch for empty/blank strings with no <string>tag
242 else if (typeTag == VALUE_ETAG)
243 {
244 *offset = afterValueOffset; // back up & try again
245 result = stringFromXml(valueXml, offset);
246 }
247
248 if (result) // Skip over the </value> tag
249 XmlRpcUtil::findTag(VALUE_ETAG, valueXml, offset);
250 else // Unrecognized tag after <value>
251 *offset = savedOffset;
252
253 return result;
254 }
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.
Definition: XmlRpcUtil.cpp:116
static std::string getNextTag(std::string const &xml, int *offset)
Definition: XmlRpcUtil.cpp:152
bool timeFromXml(std::string const &valueXml, int *offset)
bool binaryFromXml(std::string const &valueXml, int *offset)
bool intFromXml(std::string const &valueXml, int *offset)
bool doubleFromXml(std::string const &valueXml, int *offset)
bool arrayFromXml(std::string const &valueXml, int *offset)
bool structFromXml(std::string const &valueXml, int *offset)
bool stringFromXml(std::string const &valueXml, int *offset)
bool boolFromXml(std::string const &valueXml, int *offset)

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

◆ getDoubleFormat()

static std::string const & XmlRpc::XmlRpcValue::getDoubleFormat ( )
inlinestatic

Return the format used to write double values.

Definition at line 127 of file XmlRpcValue.h.

127{ return _doubleFormat; }
static std::string _doubleFormat
Definition: XmlRpcValue.h:164

Referenced by doubleToXml().

◆ getType()

Type const & XmlRpc::XmlRpcValue::getType ( ) const
inline

Return the type of the value stored.

See also
Type.

Definition at line 105 of file XmlRpcValue.h.

105{ return _type; }

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

◆ hasMember()

bool XmlRpc::XmlRpcValue::hasMember ( const std::string &  name) const

Check for the existence of a struct member by name.

Definition at line 207 of file XmlRpcValue.cpp.

208 {
209 return _type == TypeStruct && _value.asStruct->find(name) != _value.asStruct->end();
210 }

◆ intFromXml()

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

Definition at line 300 of file XmlRpcValue.cpp.

301 {
302 const char* valueStart = valueXml.c_str() + *offset;
303 char* valueEnd;
304 long ivalue = strtol(valueStart, &valueEnd, 10);
305 if (valueEnd == valueStart)
306 return false;
307
308 _type = TypeInt;
309 _value.asInt = int(ivalue);
310 *offset += int(valueEnd - valueStart);
311 return true;
312 }

Referenced by fromXml().

◆ intToXml()

std::string XmlRpc::XmlRpcValue::intToXml ( ) const
protected

Definition at line 314 of file XmlRpcValue.cpp.

315 {
316 char buf[256];
317 snprintf(buf, sizeof(buf)-1, "%d", _value.asInt);
318 buf[sizeof(buf)-1] = 0;
319 std::string xml = VALUE_TAG;
320 xml += I4_TAG;
321 xml += buf;
322 xml += I4_ETAG;
323 xml += VALUE_ETAG;
324 return xml;
325 }

Referenced by toXml().

◆ invalidate()

void XmlRpc::XmlRpcValue::invalidate ( )
protected

Definition at line 53 of file XmlRpcValue.cpp.

54 {
55 switch (_type) {
56 case TypeString: delete _value.asString; break;
57 case TypeDateTime: delete _value.asTime; break;
58 case TypeBase64: delete _value.asBinary; break;
59 case TypeArray: delete _value.asArray; break;
60 case TypeStruct: delete _value.asStruct; break;
61 default: break;
62 }
64 _value.asBinary = 0;
65 }

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

◆ operator BinaryData &()

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

Definition at line 91 of file XmlRpcValue.h.

91{ assertTypeOrInvalid(TypeBase64); return *_value.asBinary; }
void assertTypeOrInvalid(Type t)
Definition: XmlRpcValue.cpp:69

◆ operator bool &()

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

Definition at line 87 of file XmlRpcValue.h.

87{ assertTypeOrInvalid(TypeBoolean); return _value.asBool; }

◆ operator double &()

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

Definition at line 89 of file XmlRpcValue.h.

89{ assertTypeOrInvalid(TypeDouble); return _value.asDouble; }

◆ operator int &()

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

Definition at line 88 of file XmlRpcValue.h.

88{ assertTypeOrInvalid(TypeInt); return _value.asInt; }

◆ operator std::string &()

XmlRpc::XmlRpcValue::operator std::string & ( )
inline

Definition at line 90 of file XmlRpcValue.h.

90{ assertTypeOrInvalid(TypeString); return *_value.asString; }

◆ operator struct tm &()

XmlRpc::XmlRpcValue::operator struct tm & ( )
inline

Definition at line 92 of file XmlRpcValue.h.

92{ assertTypeOrInvalid(TypeDateTime); return *_value.asTime; }

◆ operator!=()

bool XmlRpc::XmlRpcValue::operator!= ( XmlRpcValue const &  other) const

Definition at line 186 of file XmlRpcValue.cpp.

187 {
188 return !(*this == other);
189 }
Index other(Index i, Index j)
Definition: EvtCyclic3.cc:118

◆ operator=() [1/4]

XmlRpcValue & XmlRpc::XmlRpcValue::operator= ( const char *  rhs)
inline

Definition at line 82 of file XmlRpcValue.h.

82{ return operator=(XmlRpcValue(std::string(rhs))); }
XmlRpcValue & operator=(XmlRpcValue const &rhs)

Referenced by operator=().

◆ operator=() [2/4]

XmlRpcValue & XmlRpc::XmlRpcValue::operator= ( double const &  rhs)
inline

Definition at line 81 of file XmlRpcValue.h.

81{ return operator=(XmlRpcValue(rhs)); }

Referenced by operator=().

◆ operator=() [3/4]

XmlRpcValue & XmlRpc::XmlRpcValue::operator= ( int const &  rhs)
inline

Definition at line 80 of file XmlRpcValue.h.

80{ return operator=(XmlRpcValue(rhs)); }

Referenced by operator=().

◆ operator=() [4/4]

XmlRpcValue & XmlRpc::XmlRpcValue::operator= ( XmlRpcValue const &  rhs)

Definition at line 119 of file XmlRpcValue.cpp.

120 {
121 if (this != &rhs)
122 {
123 invalidate();
124 _type = rhs._type;
125 switch (_type) {
126 case TypeBoolean: _value.asBool = rhs._value.asBool; break;
127 case TypeInt: _value.asInt = rhs._value.asInt; break;
128 case TypeDouble: _value.asDouble = rhs._value.asDouble; break;
129 case TypeDateTime: _value.asTime = new struct tm(*rhs._value.asTime); break;
130 case TypeString: _value.asString = new std::string(*rhs._value.asString); break;
131 case TypeBase64: _value.asBinary = new BinaryData(*rhs._value.asBinary); break;
132 case TypeArray: _value.asArray = new ValueArray(*rhs._value.asArray); break;
133 case TypeStruct: _value.asStruct = new ValueStruct(*rhs._value.asStruct); break;
134 default: _value.asBinary = 0; break;
135 }
136 }
137 return *this;
138 }

◆ operator==()

bool XmlRpc::XmlRpcValue::operator== ( XmlRpcValue const &  other) const

Definition at line 148 of file XmlRpcValue.cpp.

149 {
150 if (_type != other._type)
151 return false;
152
153 switch (_type) {
154 case TypeBoolean: return ( !_value.asBool && !other._value.asBool) ||
155 ( _value.asBool && other._value.asBool);
156 case TypeInt: return _value.asInt == other._value.asInt;
157 case TypeDouble: return _value.asDouble == other._value.asDouble;
158 case TypeDateTime: return tmEq(*_value.asTime, *other._value.asTime);
159 case TypeString: return *_value.asString == *other._value.asString;
160 case TypeBase64: return *_value.asBinary == *other._value.asBinary;
161 case TypeArray: return *_value.asArray == *other._value.asArray;
162
163 // The map<>::operator== requires the definition of value< for kcc
164 case TypeStruct: //return *_value.asStruct == *other._value.asStruct;
165 {
166 if (_value.asStruct->size() != other._value.asStruct->size())
167 return false;
168
169 ValueStruct::const_iterator it1=_value.asStruct->begin();
170 ValueStruct::const_iterator it2=other._value.asStruct->begin();
171 while (it1 != _value.asStruct->end()) {
172 const XmlRpcValue& v1 = it1->second;
173 const XmlRpcValue& v2 = it2->second;
174 if ( ! (v1 == v2))
175 return false;
176 it1++;
177 it2++;
178 }
179 return true;
180 }
181 default: break;
182 }
183 return true; // Both invalid values ...
184 }

◆ operator[]() [1/4]

XmlRpcValue & XmlRpc::XmlRpcValue::operator[] ( const char *  k)
inline

Definition at line 98 of file XmlRpcValue.h.

98{ assertStruct(); std::string s(k); return (*_value.asStruct)[s]; }

◆ operator[]() [2/4]

XmlRpcValue & XmlRpc::XmlRpcValue::operator[] ( int  i)
inline

Definition at line 95 of file XmlRpcValue.h.

95{ assertArray(i+1); return _value.asArray->at(i); }
void assertArray(int size) const
Definition: XmlRpcValue.cpp:87

◆ operator[]() [3/4]

XmlRpcValue const & XmlRpc::XmlRpcValue::operator[] ( int  i) const
inline

Definition at line 94 of file XmlRpcValue.h.

94{ assertArray(i+1); return _value.asArray->at(i); }

◆ operator[]() [4/4]

XmlRpcValue & XmlRpc::XmlRpcValue::operator[] ( std::string const &  k)
inline

Definition at line 97 of file XmlRpcValue.h.

97{ assertStruct(); return (*_value.asStruct)[k]; }

◆ setDoubleFormat()

static void XmlRpc::XmlRpcValue::setDoubleFormat ( const char *  f)
inlinestatic

Specify the format used to write double values.

Definition at line 130 of file XmlRpcValue.h.

130{ _doubleFormat = f; }

◆ setSize()

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 111 of file XmlRpcValue.h.

111{ assertArray(size); }

Referenced by XmlRpc::XmlRpcServerConnection::executeMulticall(), XmlRpc::XmlRpcServer::listMethods(), testArray(), and testStruct().

◆ size()

int XmlRpc::XmlRpcValue::size ( ) const

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

Definition at line 193 of file XmlRpcValue.cpp.

194 {
195 switch (_type) {
196 case TypeString: return int(_value.asString->size());
197 case TypeBase64: return int(_value.asBinary->size());
198 case TypeArray: return int(_value.asArray->size());
199 case TypeStruct: return int(_value.asStruct->size());
200 default: break;
201 }
202
203 throw XmlRpcException("type error");
204 }

Referenced by assertArray(), Sum::execute(), ArrayOfStructsTest::execute(), ModerateSizeArrayCheck::execute(), XmlRpc::XmlRpcServerConnection::executeMulticall(), XmlRpc::XmlRpcClient::generateRequest(), main(), and setSize().

◆ stringFromXml()

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

Definition at line 357 of file XmlRpcValue.cpp.

358 {
359 size_t valueEnd = valueXml.find('<', *offset);
360 if (valueEnd == std::string::npos)
361 return false; // No end tag;
362
364 _value.asString = new std::string(XmlRpcUtil::xmlDecode(valueXml.substr(*offset, valueEnd-*offset)));
365 *offset += int(_value.asString->length());
366 return true;
367 }
static std::string xmlDecode(const std::string &encoded)
Convert encoded xml to raw text.
Definition: XmlRpcUtil.cpp:187

Referenced by fromXml().

◆ stringToXml()

std::string XmlRpc::XmlRpcValue::stringToXml ( ) const
protected

Definition at line 369 of file XmlRpcValue.cpp.

370 {
371 std::string xml = VALUE_TAG;
372 //xml += STRING_TAG; optional
373 xml += XmlRpcUtil::xmlEncode(*_value.asString);
374 //xml += STRING_ETAG;
375 xml += VALUE_ETAG;
376 return xml;
377 }
static std::string xmlEncode(const std::string &raw)
Convert raw text to encoded xml.
Definition: XmlRpcUtil.cpp:224

Referenced by toXml().

◆ structFromXml()

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

Definition at line 496 of file XmlRpcValue.cpp.

497 {
499 _value.asStruct = new ValueStruct;
500
501 while (XmlRpcUtil::nextTagIs(MEMBER_TAG, valueXml, offset)) {
502 // name
503 const std::string name = XmlRpcUtil::parseTag(NAME_TAG, valueXml, offset);
504 // value
505 XmlRpcValue val(valueXml, offset);
506 if ( ! val.valid()) {
507 invalidate();
508 return false;
509 }
510 const std::pair<const std::string, XmlRpcValue> p(name, val);
511 _value.asStruct->insert(p);
512
513 (void) XmlRpcUtil::nextTagIs(MEMBER_ETAG, valueXml, offset);
514 }
515 return true;
516 }
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>
Definition: XmlRpcUtil.cpp:98

Referenced by fromXml().

◆ structToXml()

std::string XmlRpc::XmlRpcValue::structToXml ( ) const
protected

Definition at line 521 of file XmlRpcValue.cpp.

522 {
523 std::string xml = VALUE_TAG;
524 xml += STRUCT_TAG;
525
526 ValueStruct::const_iterator it;
527 for (it=_value.asStruct->begin(); it!=_value.asStruct->end(); ++it) {
528 xml += MEMBER_TAG;
529 xml += NAME_TAG;
530 xml += XmlRpcUtil::xmlEncode(it->first);
531 xml += NAME_ETAG;
532 xml += it->second.toXml();
533 xml += MEMBER_ETAG;
534 }
535
536 xml += STRUCT_ETAG;
537 xml += VALUE_ETAG;
538 return xml;
539 }

Referenced by toXml().

◆ timeFromXml()

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

Definition at line 380 of file XmlRpcValue.cpp.

381 {
382 size_t valueEnd = valueXml.find('<', *offset);
383 if (valueEnd == std::string::npos)
384 return false; // No end tag;
385
386 std::string stime = valueXml.substr(*offset, valueEnd-*offset);
387
388 struct tm t;
389 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)
390 return false;
391
392 t.tm_isdst = -1;
394 _value.asTime = new struct tm(t);
395 *offset += int(stime.length());
396 return true;
397 }

Referenced by fromXml().

◆ timeToXml()

std::string XmlRpc::XmlRpcValue::timeToXml ( ) const
protected

Definition at line 399 of file XmlRpcValue.cpp.

400 {
401 struct tm* t = _value.asTime;
402 char buf[20];
403 snprintf(buf, sizeof(buf)-1, "%4d%02d%02dT%02d:%02d:%02d",
404 t->tm_year,t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
405 buf[sizeof(buf)-1] = 0;
406
407 std::string xml = VALUE_TAG;
408 xml += DATETIME_TAG;
409 xml += buf;
410 xml += DATETIME_ETAG;
411 xml += VALUE_ETAG;
412 return xml;
413 }

Referenced by toXml().

◆ toXml()

std::string XmlRpc::XmlRpcValue::toXml ( ) const

Encode the Value in xml.

Definition at line 257 of file XmlRpcValue.cpp.

258 {
259 switch (_type) {
260 case TypeBoolean: return boolToXml();
261 case TypeInt: return intToXml();
262 case TypeDouble: return doubleToXml();
263 case TypeString: return stringToXml();
264 case TypeDateTime: return timeToXml();
265 case TypeBase64: return binaryToXml();
266 case TypeArray: return arrayToXml();
267 case TypeStruct: return structToXml();
268 default: break;
269 }
270 return std::string(); // Invalid value
271 }
std::string intToXml() const
std::string doubleToXml() const
std::string arrayToXml() const
std::string timeToXml() const
std::string structToXml() const
std::string binaryToXml() const
std::string boolToXml() const
std::string stringToXml() const

Referenced by XmlRpc::XmlRpcServerConnection::executeRequest(), XmlRpc::XmlRpcServerConnection::generateFaultResponse(), XmlRpc::XmlRpcClient::generateRequest(), and testString().

◆ valid()

bool XmlRpc::XmlRpcValue::valid ( ) const
inline

Return true if the value has been set to something.

Definition at line 102 of file XmlRpcValue.h.

102{ return _type != TypeInvalid; }

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

◆ write()

std::ostream & XmlRpc::XmlRpcValue::write ( std::ostream &  os) const

Write the value (no xml encoding)

Definition at line 544 of file XmlRpcValue.cpp.

544 {
545 switch (_type) {
546 default: break;
547 case TypeBoolean: os << _value.asBool; break;
548 case TypeInt: os << _value.asInt; break;
549 case TypeDouble: os << _value.asDouble; break;
550 case TypeString: os << *_value.asString; break;
551 case TypeDateTime:
552 {
553 struct tm* t = _value.asTime;
554 char buf[20];
555 snprintf(buf, sizeof(buf)-1, "%4d%02d%02dT%02d:%02d:%02d",
556 t->tm_year,t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
557 buf[sizeof(buf)-1] = 0;
558 os << buf;
559 break;
560 }
561 case TypeBase64:
562 {
563 int iostatus = 0;
564 std::ostreambuf_iterator<char> out(os);
565 base64<char> encoder;
566 encoder.put(_value.asBinary->begin(), _value.asBinary->end(), out, iostatus, base64<>::crlf());
567 break;
568 }
569 case TypeArray:
570 {
571 int s = int(_value.asArray->size());
572 os << '{';
573 for (int i=0; i<s; ++i)
574 {
575 if (i > 0) os << ',';
576 _value.asArray->at(i).write(os);
577 }
578 os << '}';
579 break;
580 }
581 case TypeStruct:
582 {
583 os << '[';
584 ValueStruct::const_iterator it;
585 for (it=_value.asStruct->begin(); it!=_value.asStruct->end(); ++it)
586 {
587 if (it!=_value.asStruct->begin()) os << ',';
588 os << it->first << ':';
589 it->second.write(os);
590 }
591 os << ']';
592 break;
593 }
594
595 }
596
597 return os;
598 }

Member Data Documentation

◆ _doubleFormat

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

Definition at line 164 of file XmlRpcValue.h.

Referenced by getDoubleFormat(), and setDoubleFormat().

◆ _type

◆ 

◆ asArray

ValueArray* XmlRpc::XmlRpcValue::asArray

Definition at line 178 of file XmlRpcValue.h.

Referenced by operator=().

◆ asBinary

BinaryData* XmlRpc::XmlRpcValue::asBinary

Definition at line 177 of file XmlRpcValue.h.

Referenced by operator=().

◆ asBool

bool XmlRpc::XmlRpcValue::asBool

Definition at line 172 of file XmlRpcValue.h.

Referenced by operator=().

◆ asDouble

double XmlRpc::XmlRpcValue::asDouble

Definition at line 174 of file XmlRpcValue.h.

Referenced by operator=().

◆ asInt

int XmlRpc::XmlRpcValue::asInt

Definition at line 173 of file XmlRpcValue.h.

Referenced by operator=().

◆ asString

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

Definition at line 176 of file XmlRpcValue.h.

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

◆ asStruct

ValueStruct* XmlRpc::XmlRpcValue::asStruct

Definition at line 179 of file XmlRpcValue.h.

Referenced by operator=().

◆ asTime

struct tm* XmlRpc::XmlRpcValue::asTime

Definition at line 175 of file XmlRpcValue.h.

Referenced by operator=().


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