XmlLocalValue.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 _XMLLOCALVALUE_H_
4 #define _XMLLOCALVALUE_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 XmlLocal {
22 
24  // should probably refcount them...
26  public:
27 
28 
29  enum Type {
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  {
56  _value.asString = new std::string(value);
57  }
58 
59  XmlRpcValue(const char* value) : _type(TypeString)
60  {
61  _value.asString = new std::string(value);
62  }
63 
64  XmlRpcValue(struct tm* value) : _type(TypeDateTime)
65  {
66  _value.asTime = new struct tm(*value);
67  }
68 
69 
70  XmlRpcValue(void* value, int nBytes) : _type(TypeBase64)
71  {
72  _value.asBinary = new BinaryData((char*)value, ((char*)value) + nBytes);
73  }
74 
76  XmlRpcValue(std::string const& xml, int* offset) : _type(TypeInvalid)
77  {
78  if (!fromXml(xml, offset)) _type = TypeInvalid;
79  }
80 
82  XmlRpcValue(XmlRpcValue const& rhs) : _type(TypeInvalid) { *this = rhs; }
83 
85  /*virtual*/ ~XmlRpcValue() { invalidate(); }
86 
88  void clear() { invalidate(); }
89 
90  // Operators
91  XmlRpcValue& operator=(XmlRpcValue const& rhs);
92  XmlRpcValue& operator=(int const& rhs) { return operator=(XmlRpcValue(rhs)); }
93  XmlRpcValue& operator=(double const& rhs) { return operator=(XmlRpcValue(rhs)); }
94  XmlRpcValue& operator=(const char* rhs) { return operator=(XmlRpcValue(std::string(rhs))); }
95 
96  bool operator==(XmlRpcValue const& other) const;
97  bool operator!=(XmlRpcValue const& other) const;
98 
99  operator bool&() { assertTypeOrInvalid(TypeBoolean); return _value.asBool; }
100  operator int&() { assertTypeOrInvalid(TypeInt); return _value.asInt; }
101  operator double&() { assertTypeOrInvalid(TypeDouble); return _value.asDouble; }
102  operator std::string&() { assertTypeOrInvalid(TypeString); return *_value.asString; }
103  operator BinaryData&() { assertTypeOrInvalid(TypeBase64); return *_value.asBinary; }
104  operator struct tm&() { assertTypeOrInvalid(TypeDateTime); return *_value.asTime; }
105 
106  XmlRpcValue const& operator[](int i) const { assertArray(i + 1); return _value.asArray->at(i); }
107  XmlRpcValue& operator[](int i) { assertArray(i + 1); return _value.asArray->at(i); }
108 
109  XmlRpcValue& operator[](std::string const& k) { assertStruct(); return (*_value.asStruct)[k]; }
110  XmlRpcValue& operator[](const char* k) { assertStruct(); std::string s(k); return (*_value.asStruct)[s]; }
111 
112  iterator begin() { assertStruct(); return (*_value.asStruct).begin(); }
113  iterator end() { assertStruct(); return (*_value.asStruct).end(); }
114 
115  // Accessors
117  bool valid() const { return _type != TypeInvalid; }
118 
120  Type const &getType() const { return _type; }
121 
123  int size() const;
124 
126  void setSize(int size) { assertArray(size); }
127 
129  bool hasMember(const std::string& name) const;
130 
132  bool fromXml(std::string const& valueXml, int* offset);
133 
135  std::string toXml() const;
136 
138  std::ostream& write(std::ostream& os) const;
139 
140  // Formatting
142  static std::string const& getDoubleFormat() { return _doubleFormat; }
143 
145  static void setDoubleFormat(const char* f) { _doubleFormat = f; }
146 
147 
148  protected:
149  // Clean up
150  void invalidate();
151 
152  // Type checking
153  void assertTypeOrInvalid(Type t);
154  void assertArray(int size) const;
155  void assertArray(int size);
156  void assertStruct();
157 
158  // XML decoding
159  bool boolFromXml(std::string const& valueXml, int* offset);
160  bool intFromXml(std::string const& valueXml, int* offset);
161  bool doubleFromXml(std::string const& valueXml, int* offset);
162  bool stringFromXml(std::string const& valueXml, int* offset);
163  bool timeFromXml(std::string const& valueXml, int* offset);
164  bool binaryFromXml(std::string const& valueXml, int* offset);
165  bool arrayFromXml(std::string const& valueXml, int* offset);
166  bool structFromXml(std::string const& valueXml, int* offset);
167 
168  // XML encoding
169  std::string boolToXml() const;
170  std::string intToXml() const;
171  std::string doubleToXml() const;
172  std::string stringToXml() const;
173  std::string timeToXml() const;
174  std::string binaryToXml() const;
175  std::string arrayToXml() const;
176  std::string structToXml() const;
177 
178  // Format strings
179  static std::string _doubleFormat;
180 
181  // Type tag and values
183 
184  // At some point I will split off Arrays and Structs into
185  // separate ref-counted objects for more efficient copying.
186  union {
187  bool asBool;
188  int asInt;
189  double asDouble;
190  struct tm* asTime;
191  std::string* asString;
195  } _value;
196 
197  };
198 } // namespace XmlRpc
199 
200 
201 std::ostream& operator<<(std::ostream& os, XmlLocal::XmlRpcValue& v);
202 
203 
204 #endif // _XMLRPCVALUE_H_
XmlLocal::XmlRpcValue::operator[]
XmlRpcValue const & operator[](int i) const
Definition: XmlLocalValue.h:106
XmlLocal::XmlRpcValue::asBool
bool asBool
Definition: XmlLocalValue.h:187
XmlLocal::XmlRpcValue::TypeInvalid
@ TypeInvalid
Definition: XmlLocalValue.h:30
XmlLocal::XmlRpcValue::operator[]
XmlRpcValue & operator[](std::string const &k)
Definition: XmlLocalValue.h:109
XmlLocal::XmlRpcValue::end
iterator end()
Definition: XmlLocalValue.h:113
XmlLocal::XmlRpcValue::XmlRpcValue
XmlRpcValue(const char *value)
Definition: XmlLocalValue.h:59
XmlLocal::XmlRpcValue::XmlRpcValue
XmlRpcValue(bool value)
Definition: XmlLocalValue.h:50
XmlLocal::XmlRpcValue::valid
bool valid() const
Return true if the value has been set to something.
Definition: XmlLocalValue.h:117
s
XmlRpcServer s
XmlLocal::XmlRpcValue::XmlRpcValue
XmlRpcValue(XmlRpcValue const &rhs)
Copy.
Definition: XmlLocalValue.h:82
XmlLocal::XmlRpcValue::TypeBoolean
@ TypeBoolean
Definition: XmlLocalValue.h:31
XmlLocal::XmlRpcValue::setDoubleFormat
static void setDoubleFormat(const char *f)
Specify the format used to write double values.
Definition: XmlLocalValue.h:145
XmlLocal::XmlRpcValue
RPC method arguments and results are represented by Values.
Definition: XmlLocalValue.h:25
XmlLocal::XmlRpcValue::XmlRpcValue
XmlRpcValue(void *value, int nBytes)
Definition: XmlLocalValue.h:70
XmlLocal::XmlRpcValue::TypeDouble
@ TypeDouble
Definition: XmlLocalValue.h:33
XmlLocal::XmlRpcValue::asTime
struct tm * asTime
Definition: XmlLocalValue.h:190
XmlLocal::XmlRpcValue::TypeString
@ TypeString
Definition: XmlLocalValue.h:34
XmlLocal::XmlRpcValue::clear
void clear()
Erase the current value.
Definition: XmlLocalValue.h:88
f
f
XmlLocal::XmlRpcValue::asStruct
ValueStruct * asStruct
Definition: XmlLocalValue.h:194
XmlLocal::XmlRpcValue::XmlRpcValue
XmlRpcValue(double value)
Definition: XmlLocalValue.h:52
XmlLocal::XmlRpcValue::BinaryData
std::vector< char > BinaryData
Definition: XmlLocalValue.h:42
operator<<
std::ostream & operator<<(std::ostream &os, XmlLocal::XmlRpcValue &v)
XmlLocal::XmlRpcValue::~XmlRpcValue
~XmlRpcValue()
Destructor (make virtual if you want to subclass)
Definition: XmlLocalValue.h:85
api.setup.name
name
Definition: python/api/setup.py:12
XmlLocal::XmlRpcValue::operator=
XmlRpcValue & operator=(const char *rhs)
Definition: XmlLocalValue.h:94
XmlLocal::XmlRpcValue::setSize
void setSize(int size)
Specify the size for array values. Array values will grow beyond this size if needed.
Definition: XmlLocalValue.h:126
XmlLocal::XmlRpcValue::ValueStruct
std::map< std::string, XmlRpcValue > ValueStruct
Definition: XmlLocalValue.h:44
XmlLocal::XmlRpcValue::XmlRpcValue
XmlRpcValue(struct tm *value)
Definition: XmlLocalValue.h:64
XmlLocal::XmlRpcValue::_type
Type _type
Definition: XmlLocalValue.h:182
operator==
bool operator==(const TiXmlString &a, const TiXmlString &b)
Definition: tinystr.h:282
XmlLocal::XmlRpcValue::asInt
int asInt
Definition: XmlLocalValue.h:188
XmlLocal::XmlRpcValue::operator=
XmlRpcValue & operator=(int const &rhs)
Definition: XmlLocalValue.h:92
XmlLocal::XmlRpcValue::XmlRpcValue
XmlRpcValue(int value)
Definition: XmlLocalValue.h:51
XmlLocal::XmlRpcValue::asBinary
BinaryData * asBinary
Definition: XmlLocalValue.h:192
XmlLocal::XmlRpcValue::TypeInt
@ TypeInt
Definition: XmlLocalValue.h:32
XmlLocal::XmlRpcValue::getDoubleFormat
static std::string const & getDoubleFormat()
Return the format used to write double values.
Definition: XmlLocalValue.h:142
XmlLocal::XmlRpcValue::XmlRpcValue
XmlRpcValue(std::string const &value)
Definition: XmlLocalValue.h:54
XmlLocal::XmlRpcValue::operator[]
XmlRpcValue & operator[](int i)
Definition: XmlLocalValue.h:107
XmlLocal::XmlRpcValue::XmlRpcValue
XmlRpcValue()
Constructors.
Definition: XmlLocalValue.h:49
XmlLocal::XmlRpcValue::XmlRpcValue
XmlRpcValue(std::string const &xml, int *offset)
Construct from xml, beginning at *offset chars into the string, updates offset.
Definition: XmlLocalValue.h:76
XmlLocal::XmlRpcValue::_doubleFormat
static std::string _doubleFormat
Definition: XmlLocalValue.h:179
XmlLocal::XmlRpcValue::operator=
XmlRpcValue & operator=(double const &rhs)
Definition: XmlLocalValue.h:93
XmlLocal::XmlRpcValue::TypeBase64
@ TypeBase64
Definition: XmlLocalValue.h:36
XmlLocal::XmlRpcValue::Type
Type
Definition: XmlLocalValue.h:29
XmlLocal::XmlRpcValue::ValueArray
std::vector< XmlRpcValue > ValueArray
Definition: XmlLocalValue.h:43
sick_scan_base.h
XMLRPCPP_DECL
#define XMLRPCPP_DECL
Definition: XmlRpcDecl.h:53
fromXml
XmlRpcValue fromXml(std::string const &data)
XmlLocal::XmlRpcValue::iterator
ValueStruct::iterator iterator
Definition: XmlLocalValue.h:45
operator!=
bool operator!=(const TiXmlString &a, const TiXmlString &b)
Definition: tinystr.h:293
XmlLocal::XmlRpcValue::getType
const Type & getType() const
Return the type of the value stored.
Definition: XmlLocalValue.h:120
XmlLocal::XmlRpcValue::TypeArray
@ TypeArray
Definition: XmlLocalValue.h:37
XmlLocal::XmlRpcValue::asArray
ValueArray * asArray
Definition: XmlLocalValue.h:193
XmlLocal
Definition: XmlLocalValue.h:21
XmlLocal::XmlRpcValue::begin
iterator begin()
Definition: XmlLocalValue.h:112
XmlLocal::XmlRpcValue::operator[]
XmlRpcValue & operator[](const char *k)
Definition: XmlLocalValue.h:110
XmlLocal::XmlRpcValue::asDouble
double asDouble
Definition: XmlLocalValue.h:189
XmlLocal::XmlRpcValue::TypeDateTime
@ TypeDateTime
Definition: XmlLocalValue.h:35
XmlLocal::XmlRpcValue::asString
std::string * asString
Definition: XmlLocalValue.h:191


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