XmlRpcValue.h
Go to the documentation of this file.
1 #include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
2 
3 #ifndef _XMLRPCVALUE_H_
4 #define _XMLRPCVALUE_H_
5 //
6 // XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
7 //
8 #if defined(_MSC_VER)
9 # pragma warning(disable:4786) // identifier was truncated in debug info
10 #endif
11 
12 #include "xmlrpcpp/XmlRpcDecl.h"
13 
14 #ifndef MAKEDEPEND
15 # include <map>
16 # include <string>
17 # include <vector>
18 # include <time.h>
19 #endif
20 
21 namespace XmlRpc {
22 
24  // should probably refcount them...
25  class XMLRPCPP_DECL XmlRpcValue {
26  public:
27 
28 
29  enum Type {
30  TypeInvalid,
31  TypeBoolean,
32  TypeInt,
33  TypeDouble,
34  TypeString,
35  TypeDateTime,
36  TypeBase64,
37  TypeArray,
38  TypeStruct
39  };
40 
41  // Non-primitive types
42  typedef std::vector<char> BinaryData;
43  typedef std::vector<XmlRpcValue> ValueArray;
44  typedef std::map<std::string, XmlRpcValue> ValueStruct;
45  typedef ValueStruct::iterator iterator;
46 
47 
49  XmlRpcValue() : _type(TypeInvalid) { _value.asBinary = 0; }
50  XmlRpcValue(bool value) : _type(TypeBoolean) { _value.asBool = value; }
51  XmlRpcValue(int value) : _type(TypeInt) { _value.asInt = value; }
52  XmlRpcValue(double value) : _type(TypeDouble) { _value.asDouble = value; }
53 
54  XmlRpcValue(std::string const& value) : _type(TypeString)
55  { _value.asString = new std::string(value); }
56 
57  XmlRpcValue(const char* value) : _type(TypeString)
58  { _value.asString = new std::string(value); }
59 
60  XmlRpcValue(struct tm* value) : _type(TypeDateTime)
61  { _value.asTime = new struct tm(*value); }
62 
63 
64  XmlRpcValue(void* value, int nBytes) : _type(TypeBase64)
65  {
66  _value.asBinary = new BinaryData((char*)value, ((char*)value)+nBytes);
67  }
68 
70  XmlRpcValue(std::string const& xml, int* offset) : _type(TypeInvalid)
71  { if ( ! fromXml(xml,offset)) _type = TypeInvalid; }
72 
74  XmlRpcValue(XmlRpcValue const& rhs) : _type(TypeInvalid) { *this = rhs; }
75 
77  /*virtual*/ ~XmlRpcValue() { invalidate(); }
78 
80  void clear() { invalidate(); }
81 
82  // Operators
83  XmlRpcValue& operator=(XmlRpcValue const& rhs);
84  XmlRpcValue& operator=(int const& rhs) { return operator=(XmlRpcValue(rhs)); }
85  XmlRpcValue& operator=(double const& rhs) { return operator=(XmlRpcValue(rhs)); }
86  XmlRpcValue& operator=(const char* rhs) { return operator=(XmlRpcValue(std::string(rhs))); }
87 
88  bool operator==(XmlRpcValue const& other) const;
89  bool operator!=(XmlRpcValue const& other) const;
90 
91  operator bool&() { assertTypeOrInvalid(TypeBoolean); return _value.asBool; }
92  operator int&() { assertTypeOrInvalid(TypeInt); return _value.asInt; }
93  operator double&() { assertTypeOrInvalid(TypeDouble); return _value.asDouble; }
94  operator std::string&() { assertTypeOrInvalid(TypeString); return *_value.asString; }
95  operator BinaryData&() { assertTypeOrInvalid(TypeBase64); return *_value.asBinary; }
96  operator struct tm&() { assertTypeOrInvalid(TypeDateTime); return *_value.asTime; }
97 
98  XmlRpcValue const& operator[](int i) const { assertArray(i+1); return _value.asArray->at(i); }
99  XmlRpcValue& operator[](int i) { assertArray(i+1); return _value.asArray->at(i); }
100 
101  XmlRpcValue& operator[](std::string const& k) { assertStruct(); return (*_value.asStruct)[k]; }
102  XmlRpcValue& operator[](const char* k) { assertStruct(); std::string s(k); return (*_value.asStruct)[s]; }
103 
104  iterator begin() {assertStruct(); return (*_value.asStruct).begin(); }
105  iterator end() {assertStruct(); return (*_value.asStruct).end(); }
106 
107  // Accessors
109  bool valid() const { return _type != TypeInvalid; }
110 
112  Type const &getType() const { return _type; }
113 
115  int size() const;
116 
118  void setSize(int size) { assertArray(size); }
119 
121  bool hasMember(const std::string& name) const;
122 
124  bool fromXml(std::string const& valueXml, int* offset);
125 
127  std::string toXml() const;
128 
130  std::ostream& write(std::ostream& os) const;
131 
132  // Formatting
134  static std::string const& getDoubleFormat() { return _doubleFormat; }
135 
137  static void setDoubleFormat(const char* f) { _doubleFormat = f; }
138 
139 
140  protected:
141  // Clean up
142  void invalidate();
143 
144  // Type checking
145  void assertTypeOrInvalid(Type t);
146  void assertArray(int size) const;
147  void assertArray(int size);
148  void assertStruct();
149 
150  // XML decoding
151  bool boolFromXml(std::string const& valueXml, int* offset);
152  bool intFromXml(std::string const& valueXml, int* offset);
153  bool doubleFromXml(std::string const& valueXml, int* offset);
154  bool stringFromXml(std::string const& valueXml, int* offset);
155  bool timeFromXml(std::string const& valueXml, int* offset);
156  bool binaryFromXml(std::string const& valueXml, int* offset);
157  bool arrayFromXml(std::string const& valueXml, int* offset);
158  bool structFromXml(std::string const& valueXml, int* offset);
159 
160  // XML encoding
161  std::string boolToXml() const;
162  std::string intToXml() const;
163  std::string doubleToXml() const;
164  std::string stringToXml() const;
165  std::string timeToXml() const;
166  std::string binaryToXml() const;
167  std::string arrayToXml() const;
168  std::string structToXml() const;
169 
170  // Format strings
171  static std::string _doubleFormat;
172 
173  // Type tag and values
174  Type _type;
175 
176  // At some point I will split off Arrays and Structs into
177  // separate ref-counted objects for more efficient copying.
178  union {
179  bool asBool;
180  int asInt;
181  double asDouble;
182  struct tm* asTime;
183  std::string* asString;
184  BinaryData* asBinary;
185  ValueArray* asArray;
186  ValueStruct* asStruct;
187  } _value;
188 
189  };
190 } // namespace XmlRpc
191 
192 
193 std::ostream& operator<<(std::ostream& os, XmlRpc::XmlRpcValue& v);
194 
195 
196 #endif // _XMLRPCVALUE_H_
s
XmlRpcServer s
XmlRpc
f
f
operator<<
std::ostream & operator<<(std::ostream &os, XmlRpc::XmlRpcValue &v)
api.setup.name
name
Definition: python/api/setup.py:12
operator==
bool operator==(const TiXmlString &a, const TiXmlString &b)
Definition: tinystr.h:282
sick_scan_base.h
XMLRPCPP_DECL
#define XMLRPCPP_DECL
Definition: XmlRpcDecl.h:53
XmlRpc::fromXml
XmlRpcValue fromXml(std::string const &data)
operator!=
bool operator!=(const TiXmlString &a, const TiXmlString &b)
Definition: tinystr.h:293
t
geometry_msgs::TransformStamped t
XmlRpc::XmlRpcValue
RPC method arguments and results are represented by Values.
Definition: XmlRpcValue.h:25


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:13