BOSS 8.0.0
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 37 of file XmlRpcValue.h.

◆ ValueArray

Definition at line 38 of file XmlRpcValue.h.

◆ ValueStruct

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

Definition at line 39 of file XmlRpcValue.h.

Member Enumeration Documentation

◆ Type

Enumerator
TypeInvalid 
TypeBoolean 
TypeInt 
TypeDouble 
TypeString 
TypeDateTime 
TypeBase64 
TypeArray 
TypeStruct 

Definition at line 24 of file XmlRpcValue.h.

Constructor & Destructor Documentation

◆ XmlRpcValue() [1/10]

XmlRpc::XmlRpcValue::XmlRpcValue ( )
inline

Constructors.

Definition at line 42 of file XmlRpcValue.h.

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

Referenced by arrayFromXml(), operator!=(), operator=(), operator=(), operator=(), operator=(), operator==(), operator[](), operator[](), operator[](), operator[](), structFromXml(), and XmlRpcValue().

◆ XmlRpcValue() [2/10]

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

Definition at line 43 of file XmlRpcValue.h.

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

◆ XmlRpcValue() [3/10]

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

Definition at line 44 of file XmlRpcValue.h.

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

◆ XmlRpcValue() [4/10]

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

Definition at line 45 of file XmlRpcValue.h.

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

◆ XmlRpcValue() [5/10]

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

Definition at line 47 of file XmlRpcValue.h.

47 : _type( TypeString ) {
48 _value.asString = new std::string( value );
49 }

◆ XmlRpcValue() [6/10]

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

Definition at line 51 of file XmlRpcValue.h.

51 : _type( TypeString ) {
52 _value.asString = new std::string( value );
53 }

◆ XmlRpcValue() [7/10]

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

Definition at line 55 of file XmlRpcValue.h.

55 : _type( TypeDateTime ) {
56 _value.asTime = new struct tm( *value );
57 }

◆ XmlRpcValue() [8/10]

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

Definition at line 59 of file XmlRpcValue.h.

59 : _type( TypeBase64 ) {
60 _value.asBinary = new BinaryData( (char*)value, ( (char*)value ) + nBytes );
61 }
std::vector< char > BinaryData
Definition XmlRpcValue.h:37

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

64 : _type( TypeInvalid ) {
65 if ( !fromXml( xml, offset ) ) _type = TypeInvalid;
66 }
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 69 of file XmlRpcValue.h.

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

◆ ~XmlRpcValue()

XmlRpc::XmlRpcValue::~XmlRpcValue ( )
inline

Destructor (make virtual if you want to subclass).

Definition at line 72 of file XmlRpcValue.h.

72{ invalidate(); }

Member Function Documentation

◆ arrayFromXml()

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

Definition at line 417 of file XmlRpcValue.cpp.

417 {
418 if ( !XmlRpcUtil::nextTagIs( DATA_TAG, valueXml, offset ) ) return false;
419
421 _value.asArray = new ValueArray;
423 while ( v.fromXml( valueXml, offset ) ) _value.asArray->push_back( v ); // copy...
424
425 // Skip the trailing </data>
426 (void)XmlRpcUtil::nextTagIs( DATA_ETAG, valueXml, offset );
427 return true;
428 }
**********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)
std::vector< XmlRpcValue > ValueArray
Definition XmlRpcValue.h:38
XmlRpcValue()
Constructors.
Definition XmlRpcValue.h:42

Referenced by fromXml().

◆ arrayToXml()

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

Definition at line 432 of file XmlRpcValue.cpp.

432 {
433 std::string xml = VALUE_TAG;
434 xml += ARRAY_TAG;
435 xml += DATA_TAG;
436
437 int s = int( _value.asArray->size() );
438 for ( int i = 0; i < s; ++i ) xml += _value.asArray->at( i ).toXml();
439
440 xml += DATA_ETAG;
441 xml += ARRAY_ETAG;
442 xml += VALUE_ETAG;
443 return xml;
444 }
XmlRpcServer s

Referenced by toXml().

◆ assertArray() [1/2]

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

Definition at line 86 of file XmlRpcValue.cpp.

86 {
87 if ( _type == TypeInvalid )
88 {
90 _value.asArray = new ValueArray( size );
91 }
92 else if ( _type == TypeArray )
93 {
94 if ( int( _value.asArray->size() ) < size ) _value.asArray->resize( size );
95 }
96 else throw XmlRpcException( "type error: expected an array" );
97 }
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 80 of file XmlRpcValue.cpp.

80 {
81 if ( _type != TypeArray ) throw XmlRpcException( "type error: expected an array" );
82 else if ( int( _value.asArray->size() ) < size )
83 throw XmlRpcException( "range error: array index too large" );
84 }

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

◆ assertStruct()

void XmlRpc::XmlRpcValue::assertStruct ( )
protected

Definition at line 99 of file XmlRpcValue.cpp.

99 {
100 if ( _type == TypeInvalid )
101 {
103 _value.asStruct = new ValueStruct();
104 }
105 else if ( _type != TypeStruct ) throw XmlRpcException( "type error: expected a struct" );
106 }
std::map< std::string, XmlRpcValue > ValueStruct
Definition XmlRpcValue.h:39

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

◆ assertTypeOrInvalid()

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

Definition at line 63 of file XmlRpcValue.cpp.

63 {
64 if ( _type == TypeInvalid )
65 {
66 _type = t;
67 switch ( _type )
68 { // Ensure there is a valid value for the type
69 case TypeString: _value.asString = new std::string(); break;
70 case TypeDateTime: _value.asTime = new struct tm(); break;
71 case TypeBase64: _value.asBinary = new BinaryData(); break;
72 case TypeArray: _value.asArray = new ValueArray(); break;
73 case TypeStruct: _value.asStruct = new ValueStruct(); break;
74 default: _value.asBinary = 0; break;
75 }
76 }
77 else if ( _type != t ) throw XmlRpcException( "type error" );
78 }
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 379 of file XmlRpcValue.cpp.

379 {
380 size_t valueEnd = valueXml.find( '<', *offset );
381 if ( valueEnd == std::string::npos ) return false; // No end tag;
382
384 std::string asString = valueXml.substr( *offset, valueEnd - *offset );
385 _value.asBinary = new BinaryData();
386 // check whether base64 encodings can contain chars xml encodes...
387
388 // convert from base64 to binary
389 int iostatus = 0;
390 base64<char> decoder;
391 std::back_insert_iterator<BinaryData> ins = std::back_inserter( *( _value.asBinary ) );
392 decoder.get( asString.begin(), asString.end(), ins, iostatus );
393
394 *offset += int( asString.length() );
395 return true;
396 }
std::string * asString
_II get(_II _First, _II _Last, _OI _To, _State &_St) const
Definition base64.h:198

Referenced by fromXml().

◆ binaryToXml()

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

Definition at line 398 of file XmlRpcValue.cpp.

398 {
399 // convert to base64
400 std::vector<char> base64data;
401 int iostatus = 0;
402 base64<char> encoder;
403 std::back_insert_iterator<std::vector<char>> ins = std::back_inserter( base64data );
404 encoder.put( _value.asBinary->begin(), _value.asBinary->end(), ins, iostatus,
405 base64<>::crlf() );
406
407 // Wrap with xml
408 std::string xml = VALUE_TAG;
409 xml += BASE64_TAG;
410 xml.append( base64data.begin(), base64data.end() );
411 xml += BASE64_ETAG;
412 xml += VALUE_ETAG;
413 return xml;
414 }
_II put(_II _First, _II _Last, _OI _To, _State &_St, _Endline _Endl) const
Definition base64.h:129

Referenced by toXml().

◆ boolFromXml()

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

Definition at line 251 of file XmlRpcValue.cpp.

251 {
252 const char* valueStart = valueXml.c_str() + *offset;
253 char* valueEnd;
254 long ivalue = strtol( valueStart, &valueEnd, 10 );
255 if ( valueEnd == valueStart || ( ivalue != 0 && ivalue != 1 ) ) return false;
256
258 _value.asBool = ( ivalue == 1 );
259 *offset += int( valueEnd - valueStart );
260 return true;
261 }

Referenced by fromXml().

◆ boolToXml()

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

Definition at line 263 of file XmlRpcValue.cpp.

263 {
264 std::string xml = VALUE_TAG;
265 xml += BOOLEAN_TAG;
266 xml += ( _value.asBool ? "1" : "0" );
267 xml += BOOLEAN_ETAG;
268 xml += VALUE_ETAG;
269 return xml;
270 }

Referenced by toXml().

◆ clear()

void XmlRpc::XmlRpcValue::clear ( )
inline

Erase the current value.

Definition at line 75 of file XmlRpcValue.h.

75{ invalidate(); }

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

◆ doubleFromXml()

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

Definition at line 298 of file XmlRpcValue.cpp.

298 {
299 const char* valueStart = valueXml.c_str() + *offset;
300 char* valueEnd;
301 double dvalue = strtod( valueStart, &valueEnd );
302 if ( valueEnd == valueStart ) return false;
303
305 _value.asDouble = dvalue;
306 *offset += int( valueEnd - valueStart );
307 return true;
308 }

Referenced by fromXml().

◆ doubleToXml()

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

Definition at line 310 of file XmlRpcValue.cpp.

310 {
311 char buf[256];
312 snprintf( buf, sizeof( buf ) - 1, getDoubleFormat().c_str(), _value.asDouble );
313 buf[sizeof( buf ) - 1] = 0;
314
315 std::string xml = VALUE_TAG;
316 xml += DOUBLE_TAG;
317 xml += buf;
318 xml += DOUBLE_ETAG;
319 xml += VALUE_ETAG;
320 return xml;
321 }
static std::string const & getDoubleFormat()
Return the format used to write double values.
char * c_str(Index i)

Referenced by toXml().

◆ fromXml()

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

Decode xml. Destroys any existing value.

Definition at line 198 of file XmlRpcValue.cpp.

198 {
199 int savedOffset = *offset;
200
201 invalidate();
202 if ( !XmlRpcUtil::nextTagIs( VALUE_TAG, valueXml, offset ) )
203 return false; // Not a value, offset not updated
204
205 int afterValueOffset = *offset;
206 std::string typeTag = XmlRpcUtil::getNextTag( valueXml, offset );
207 bool result = false;
208 if ( typeTag == BOOLEAN_TAG ) result = boolFromXml( valueXml, offset );
209 else if ( typeTag == I4_TAG || typeTag == INT_TAG )
210 result = intFromXml( valueXml, offset );
211 else if ( typeTag == DOUBLE_TAG ) result = doubleFromXml( valueXml, offset );
212 else if ( typeTag.empty() || typeTag == STRING_TAG )
213 result = stringFromXml( valueXml, offset );
214 else if ( typeTag == DATETIME_TAG ) result = timeFromXml( valueXml, offset );
215 else if ( typeTag == BASE64_TAG ) result = binaryFromXml( valueXml, offset );
216 else if ( typeTag == ARRAY_TAG ) result = arrayFromXml( valueXml, offset );
217 else if ( typeTag == STRUCT_TAG ) result = structFromXml( valueXml, offset );
218 // Watch for empty/blank strings with no <string>tag
219 else if ( typeTag == VALUE_ETAG )
220 {
221 *offset = afterValueOffset; // back up & try again
222 result = stringFromXml( valueXml, offset );
223 }
224
225 if ( result ) // Skip over the </value> tag
226 XmlRpcUtil::findTag( VALUE_ETAG, valueXml, offset );
227 else // Unrecognized tag after <value>
228 *offset = savedOffset;
229
230 return result;
231 }
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.
static std::string getNextTag(std::string const &xml, int *offset)
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()

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

Return the format used to write double values.

Definition at line 159 of file XmlRpcValue.h.

159{ return _doubleFormat; }
static std::string _doubleFormat

Referenced by doubleToXml().

◆ getType()

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

Return the type of the value stored.

See also
Type.

Definition at line 137 of file XmlRpcValue.h.

137{ return _type; }

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

◆ hasMember()

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

Check for the existence of a struct member by name.

Definition at line 192 of file XmlRpcValue.cpp.

192 {
193 return _type == TypeStruct && _value.asStruct->find( name ) != _value.asStruct->end();
194 }

◆ intFromXml()

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

Definition at line 273 of file XmlRpcValue.cpp.

273 {
274 const char* valueStart = valueXml.c_str() + *offset;
275 char* valueEnd;
276 long ivalue = strtol( valueStart, &valueEnd, 10 );
277 if ( valueEnd == valueStart ) return false;
278
279 _type = TypeInt;
280 _value.asInt = int( ivalue );
281 *offset += int( valueEnd - valueStart );
282 return true;
283 }

Referenced by fromXml().

◆ intToXml()

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

Definition at line 285 of file XmlRpcValue.cpp.

285 {
286 char buf[256];
287 snprintf( buf, sizeof( buf ) - 1, "%d", _value.asInt );
288 buf[sizeof( buf ) - 1] = 0;
289 std::string xml = VALUE_TAG;
290 xml += I4_TAG;
291 xml += buf;
292 xml += I4_ETAG;
293 xml += VALUE_ETAG;
294 return xml;
295 }

Referenced by toXml().

◆ invalidate()

void XmlRpc::XmlRpcValue::invalidate ( )
protected

Definition at line 48 of file XmlRpcValue.cpp.

48 {
49 switch ( _type )
50 {
51 case TypeString: delete _value.asString; break;
52 case TypeDateTime: delete _value.asTime; break;
53 case TypeBase64: delete _value.asBinary; break;
54 case TypeArray: delete _value.asArray; break;
55 case TypeStruct: delete _value.asStruct; break;
56 default: break;
57 }
59 _value.asBinary = 0;
60 }

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

◆ operator BinaryData &()

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

Definition at line 104 of file XmlRpcValue.h.

104 {
106 return *_value.asBinary;
107 }
void assertTypeOrInvalid(Type t)

◆ operator bool &()

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

Definition at line 88 of file XmlRpcValue.h.

88 {
90 return _value.asBool;
91 }

◆ operator double &()

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

Definition at line 96 of file XmlRpcValue.h.

96 {
98 return _value.asDouble;
99 }

◆ operator int &()

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

Definition at line 92 of file XmlRpcValue.h.

92 {
94 return _value.asInt;
95 }

◆ operator std::string &()

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

Definition at line 100 of file XmlRpcValue.h.

100 {
102 return *_value.asString;
103 }

◆ operator struct tm &()

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

Definition at line 108 of file XmlRpcValue.h.

108 {
110 return *_value.asTime;
111 }

◆ operator!=()

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

Definition at line 173 of file XmlRpcValue.cpp.

173 {
174 return !( *this == other );
175 }
Index other(Index i, Index j)

◆ operator=() [1/4]

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

Definition at line 81 of file XmlRpcValue.h.

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

◆ operator=() [2/4]

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

Definition at line 80 of file XmlRpcValue.h.

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

Referenced by operator=().

◆ operator=() [3/4]

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

Definition at line 79 of file XmlRpcValue.h.

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

Referenced by operator=().

◆ operator=() [4/4]

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

Definition at line 109 of file XmlRpcValue.cpp.

109 {
110 if ( this != &rhs )
111 {
112 invalidate();
113 _type = rhs._type;
114 switch ( _type )
115 {
116 case TypeBoolean: _value.asBool = rhs._value.asBool; break;
117 case TypeInt: _value.asInt = rhs._value.asInt; break;
118 case TypeDouble: _value.asDouble = rhs._value.asDouble; break;
119 case TypeDateTime: _value.asTime = new struct tm( *rhs._value.asTime ); break;
120 case TypeString: _value.asString = new std::string( *rhs._value.asString ); break;
121 case TypeBase64: _value.asBinary = new BinaryData( *rhs._value.asBinary ); break;
122 case TypeArray: _value.asArray = new ValueArray( *rhs._value.asArray ); break;
123 case TypeStruct: _value.asStruct = new ValueStruct( *rhs._value.asStruct ); break;
124 default: _value.asBinary = 0; break;
125 }
126 }
127 return *this;
128 }

Referenced by operator=().

◆ operator==()

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

Definition at line 136 of file XmlRpcValue.cpp.

136 {
137 if ( _type != other._type ) return false;
138
139 switch ( _type )
140 {
141 case TypeBoolean:
142 return ( !_value.asBool && !other._value.asBool ) ||
143 ( _value.asBool && other._value.asBool );
144 case TypeInt: return _value.asInt == other._value.asInt;
145 case TypeDouble: return _value.asDouble == other._value.asDouble;
146 case TypeDateTime: return tmEq( *_value.asTime, *other._value.asTime );
147 case TypeString: return *_value.asString == *other._value.asString;
148 case TypeBase64: return *_value.asBinary == *other._value.asBinary;
149 case TypeArray: return *_value.asArray == *other._value.asArray;
150
151 // The map<>::operator== requires the definition of value< for kcc
152 case TypeStruct: // return *_value.asStruct == *other._value.asStruct;
153 {
154 if ( _value.asStruct->size() != other._value.asStruct->size() ) return false;
155
156 ValueStruct::const_iterator it1 = _value.asStruct->begin();
157 ValueStruct::const_iterator it2 = other._value.asStruct->begin();
158 while ( it1 != _value.asStruct->end() )
159 {
160 const XmlRpcValue& v1 = it1->second;
161 const XmlRpcValue& v2 = it2->second;
162 if ( !( v1 == v2 ) ) return false;
163 it1++;
164 it2++;
165 }
166 return true;
167 }
168 default: break;
169 }
170 return true; // Both invalid values ...
171 }

◆ operator[]() [1/4]

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

Definition at line 126 of file XmlRpcValue.h.

126 {
127 assertStruct();
128 std::string s( k );
129 return ( *_value.asStruct )[s];
130 }

◆ operator[]() [2/4]

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

Definition at line 117 of file XmlRpcValue.h.

117 {
118 assertArray( i + 1 );
119 return _value.asArray->at( i );
120 }
void assertArray(int size) const

◆ operator[]() [3/4]

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

Definition at line 113 of file XmlRpcValue.h.

113 {
114 assertArray( i + 1 );
115 return _value.asArray->at( i );
116 }

◆ operator[]() [4/4]

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

Definition at line 122 of file XmlRpcValue.h.

122 {
123 assertStruct();
124 return ( *_value.asStruct )[k];
125 }

◆ setDoubleFormat()

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

Specify the format used to write double values.

Definition at line 162 of file XmlRpcValue.h.

162{ _doubleFormat = f; }
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")

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

143{ assertArray( size ); }

Referenced by XmlRpc::XmlRpcServerConnection::executeMulticall(), getFnamesAtBkk(), 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 178 of file XmlRpcValue.cpp.

178 {
179 switch ( _type )
180 {
181 case TypeString: return int( _value.asString->size() );
182 case TypeBase64: return int( _value.asBinary->size() );
183 case TypeArray: return int( _value.asArray->size() );
184 case TypeStruct: return int( _value.asStruct->size() );
185 default: break;
186 }
187
188 throw XmlRpcException( "type error" );
189 }

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

◆ stringFromXml()

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

Definition at line 324 of file XmlRpcValue.cpp.

324 {
325 size_t valueEnd = valueXml.find( '<', *offset );
326 if ( valueEnd == std::string::npos ) return false; // No end tag;
327
329 _value.asString = new std::string(
330 XmlRpcUtil::xmlDecode( valueXml.substr( *offset, valueEnd - *offset ) ) );
331 *offset += int( _value.asString->length() );
332 return true;
333 }
static std::string xmlDecode(const std::string &encoded)
Convert encoded xml to raw text.

Referenced by fromXml().

◆ stringToXml()

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

Definition at line 335 of file XmlRpcValue.cpp.

335 {
336 std::string xml = VALUE_TAG;
337 // xml += STRING_TAG; optional
338 xml += XmlRpcUtil::xmlEncode( *_value.asString );
339 // xml += STRING_ETAG;
340 xml += VALUE_ETAG;
341 return xml;
342 }
static std::string xmlEncode(const std::string &raw)
Convert raw text to encoded xml.

Referenced by toXml().

◆ structFromXml()

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

Definition at line 447 of file XmlRpcValue.cpp.

447 {
449 _value.asStruct = new ValueStruct;
450
451 while ( XmlRpcUtil::nextTagIs( MEMBER_TAG, valueXml, offset ) )
452 {
453 // name
454 const std::string name = XmlRpcUtil::parseTag( NAME_TAG, valueXml, offset );
455 // value
456 XmlRpcValue val( valueXml, offset );
457 if ( !val.valid() )
458 {
459 invalidate();
460 return false;
461 }
462 const std::pair<const std::string, XmlRpcValue> p( name, val );
463 _value.asStruct->insert( p );
464
465 (void)XmlRpcUtil::nextTagIs( MEMBER_ETAG, valueXml, offset );
466 }
467 return true;
468 }
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>.

Referenced by fromXml().

◆ structToXml()

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

Definition at line 472 of file XmlRpcValue.cpp.

472 {
473 std::string xml = VALUE_TAG;
474 xml += STRUCT_TAG;
475
476 ValueStruct::const_iterator it;
477 for ( it = _value.asStruct->begin(); it != _value.asStruct->end(); ++it )
478 {
479 xml += MEMBER_TAG;
480 xml += NAME_TAG;
481 xml += XmlRpcUtil::xmlEncode( it->first );
482 xml += NAME_ETAG;
483 xml += it->second.toXml();
484 xml += MEMBER_ETAG;
485 }
486
487 xml += STRUCT_ETAG;
488 xml += VALUE_ETAG;
489 return xml;
490 }

Referenced by toXml().

◆ timeFromXml()

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

Definition at line 345 of file XmlRpcValue.cpp.

345 {
346 size_t valueEnd = valueXml.find( '<', *offset );
347 if ( valueEnd == std::string::npos ) return false; // No end tag;
348
349 std::string stime = valueXml.substr( *offset, valueEnd - *offset );
350
351 struct tm t;
352 if ( sscanf( stime.c_str(), "%4d%2d%2dT%2d:%2d:%2d", &t.tm_year, &t.tm_mon, &t.tm_mday,
353 &t.tm_hour, &t.tm_min, &t.tm_sec ) != 6 )
354 return false;
355
356 t.tm_isdst = -1;
358 _value.asTime = new struct tm( t );
359 *offset += int( stime.length() );
360 return true;
361 }

Referenced by fromXml().

◆ timeToXml()

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

Definition at line 363 of file XmlRpcValue.cpp.

363 {
364 struct tm* t = _value.asTime;
365 char buf[20];
366 snprintf( buf, sizeof( buf ) - 1, "%4d%02d%02dT%02d:%02d:%02d", t->tm_year, t->tm_mon,
367 t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec );
368 buf[sizeof( buf ) - 1] = 0;
369
370 std::string xml = VALUE_TAG;
371 xml += DATETIME_TAG;
372 xml += buf;
373 xml += DATETIME_ETAG;
374 xml += VALUE_ETAG;
375 return xml;
376 }

Referenced by toXml().

◆ toXml()

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

Encode the Value in xml.

Definition at line 234 of file XmlRpcValue.cpp.

234 {
235 switch ( _type )
236 {
237 case TypeBoolean: return boolToXml();
238 case TypeInt: return intToXml();
239 case TypeDouble: return doubleToXml();
240 case TypeString: return stringToXml();
241 case TypeDateTime: return timeToXml();
242 case TypeBase64: return binaryToXml();
243 case TypeArray: return arrayToXml();
244 case TypeStruct: return structToXml();
245 default: break;
246 }
247 return std::string(); // Invalid value
248 }
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 134 of file XmlRpcValue.h.

134{ 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 493 of file XmlRpcValue.cpp.

493 {
494 switch ( _type )
495 {
496 default: break;
497 case TypeBoolean: os << _value.asBool; break;
498 case TypeInt: os << _value.asInt; break;
499 case TypeDouble: os << _value.asDouble; break;
500 case TypeString: os << *_value.asString; break;
501 case TypeDateTime: {
502 struct tm* t = _value.asTime;
503 char buf[20];
504 snprintf( buf, sizeof( buf ) - 1, "%4d%02d%02dT%02d:%02d:%02d", t->tm_year, t->tm_mon,
505 t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec );
506 buf[sizeof( buf ) - 1] = 0;
507 os << buf;
508 break;
509 }
510 case TypeBase64: {
511 int iostatus = 0;
512 std::ostreambuf_iterator<char> out( os );
513 base64<char> encoder;
514 encoder.put( _value.asBinary->begin(), _value.asBinary->end(), out, iostatus,
515 base64<>::crlf() );
516 break;
517 }
518 case TypeArray: {
519 int s = int( _value.asArray->size() );
520 os << '{';
521 for ( int i = 0; i < s; ++i )
522 {
523 if ( i > 0 ) os << ',';
524 _value.asArray->at( i ).write( os );
525 }
526 os << '}';
527 break;
528 }
529 case TypeStruct: {
530 os << '[';
531 ValueStruct::const_iterator it;
532 for ( it = _value.asStruct->begin(); it != _value.asStruct->end(); ++it )
533 {
534 if ( it != _value.asStruct->begin() ) os << ',';
535 os << it->first << ':';
536 it->second.write( os );
537 }
538 os << ']';
539 break;
540 }
541 }
542
543 return os;
544 }

Member Data Documentation

◆ _doubleFormat

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

Definition at line 195 of file XmlRpcValue.h.

Referenced by getDoubleFormat(), and setDoubleFormat().

◆ _type

◆ [union]

◆ asArray

ValueArray* XmlRpc::XmlRpcValue::asArray

Definition at line 209 of file XmlRpcValue.h.

Referenced by operator=().

◆ asBinary

BinaryData* XmlRpc::XmlRpcValue::asBinary

Definition at line 208 of file XmlRpcValue.h.

Referenced by operator=().

◆ asBool

bool XmlRpc::XmlRpcValue::asBool

Definition at line 203 of file XmlRpcValue.h.

Referenced by operator=().

◆ asDouble

double XmlRpc::XmlRpcValue::asDouble

Definition at line 205 of file XmlRpcValue.h.

Referenced by operator=().

◆ asInt

int XmlRpc::XmlRpcValue::asInt

Definition at line 204 of file XmlRpcValue.h.

Referenced by operator=().

◆ asString

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

Definition at line 207 of file XmlRpcValue.h.

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

◆ asStruct

ValueStruct* XmlRpc::XmlRpcValue::asStruct

Definition at line 210 of file XmlRpcValue.h.

Referenced by operator=().

◆ asTime

struct tm* XmlRpc::XmlRpcValue::asTime

Definition at line 206 of file XmlRpcValue.h.

Referenced by operator=().


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