libutil++  1.9.3
 All Classes Functions Variables
Variant.h
1 /*
2 ** libutil++
3 ** $Id: Variant.h 1892 2017-06-23 17:23:36Z sella $
4 ** Copyright (c) 2011-2016 Digital Genesis, LLC. All Rights Reserved.
5 ** Released under the LGPL Version 2.1 License.
6 ** http://www.digitalgenesis.com
7 */
8 
9 #ifndef __libutilxx__sella__variant__Variant_H__
10 #define __libutilxx__sella__variant__Variant_H__
11 
12 #include "../../common.h"
13 #include "TypeCastException.h"
14 #include "UnsupportedOperatorException.h"
15 #include "RangeException.h"
16 #include "Nullable.h"
17 #include "Null.h"
18 #include "Boolean.h"
19 #include "Signed.h"
20 #include "Unsigned.h"
21 #include "Double.h"
22 #include "String.h"
23 #include "UUID.h"
24 #include "Binary.h"
25 #include "Pointer.h"
26 #include "IPAddress.h"
27 #include "IPPrefix.h"
28 #include "Interval.h"
29 #include "Time.h"
30 #include "Date.h"
31 #include "TimeStamp.h"
32 #include "Vector.h"
33 #include "Object.h"
34 
35 #include <ctype.h>
36 #include <iostream>
37 #include <memory>
38 #include <algorithm>
39 
40 #include <boost/regex.hpp>
41 #include <boost/iterator/iterator_facade.hpp>
42 
43 namespace sella {
44  namespace variant {
45  class Variant;
46  class Variant_iterator;
47 
48  struct iterator_t {
49  int type;
50  std::vector<Variant>::iterator vit;
51  std::map<std::string, Variant>::iterator oit;
52  Variant *v;
53  };
54  }
55 }
56 
58  public:
59  friend class Vector;
60  friend class Object;
61 
62  public:
63  typedef std::shared_ptr<Variant> shared;
64  typedef Variant *ptr;
65  typedef Variant_iterator iterator;
66  typedef const Variant_iterator const_iterator;
67 
68  public:
69  /* Public Static Attributes */
70  const static int TypeAuto = 0x00;
71 
72  const static int TypeNull = 0x01;
73 
74  const static int TypeBoolean = 0x02;
75  const static int TypeSigned = 0x03;
76  const static int TypeUnsigned = 0x04;
77  const static int TypeDouble = 0x05;
78  const static int TypeString = 0x06;
79  const static int TypeUUID = 0x07;
80  const static int TypeBinary = 0x08;
81  const static int TypePointer = 0x09;
82  const static int TypeIPAddress = 0x10;
83  const static int TypeIPPrefix = 0x11;
84 
85  const static int TypeInterval = 0x20;
86  const static int TypeTime = 0x21;
87  const static int TypeDate = 0x22;
88  const static int TypeTimeStamp = 0x23;
89 
90  const static int TypeVector = 0x50;
91  const static int TypeObject = 0x51;
92 
93  const static int TypeJSON = 0x60;
94  const static int TypeQuoted = 0x61;
95  const static int TypeNonQuoted = 0x62;
96  const static int TypeMsgPack = 0x63;
97 
98  const static int JSON = 0x00;
99  const static int CJSON = 0x01; /* Compact */
100  const static int MSGPACK = 0x02;
101  const static int XML = 0x03;
102  const static int CSV = 0x04;
103 
104  const static int IterScalar = 0x00;
105  const static int IterVector = 0x01;
106  const static int IterObject = 0x02;
107 
108  /* Constructors */
109  Variant() throw ();
110  explicit Variant(const std::shared_ptr<Nullable> &value) throw (TypeCastException);
111  explicit Variant(std::shared_ptr<Nullable> &&value) throw (TypeCastException);
112  explicit Variant(const char *value, int type = TypeAuto) throw (TypeCastException); /* TypeAuto chosen to make auto casting to Variant work as expected. */
113  explicit Variant(const std::string &value, int type = TypeString) throw (TypeCastException);
114  explicit Variant(uint32_t size, uint8_t *buffer) throw (TypeCastException); /* MessagePack */
115  explicit Variant(std::string &&value, int type = TypeString) throw (TypeCastException);
116  explicit Variant(const sella::util::UUID &value) throw ();
117  explicit Variant(sella::util::UUID &&value) throw ();
118  explicit Variant(uuid_t &value) throw ();
119  explicit Variant(void *ptr) throw ();
120  explicit Variant(const sella::net::IPAddress &value) throw ();
121  explicit Variant(sella::net::IPAddress &&value) throw ();
122  explicit Variant(const sella::net::IPPrefix &value) throw ();
123  explicit Variant(sella::net::IPPrefix &&value) throw ();
124  explicit Variant(bool value) throw ();
125  explicit Variant(uint8_t value) throw ();
126  explicit Variant(uint16_t value) throw ();
127  explicit Variant(unsigned int value) throw ();
128  explicit Variant(uint64_t value) throw ();
129  explicit Variant(int8_t value) throw ();
130  explicit Variant(int16_t value) throw ();
131  explicit Variant(int value) throw ();
132  explicit Variant(int64_t value) throw ();
133  explicit Variant(float value) throw ();
134  explicit Variant(double value) throw ();
135  explicit Variant(const std::vector<std::string> &token) throw (TypeCastException);
136 #ifdef __LP64__
137  explicit Variant(unsigned long long value) throw ();
138  explicit Variant(long long value) throw ();
139 #else
140  explicit Variant(unsigned long value) throw ();
141  explicit Variant(long value) throw ();
142 #endif
143 
144  Variant(const Variant &other) throw ();
145  Variant(Variant &&other) throw ();
146  virtual ~Variant() throw ();
147 
148  iterator begin() throw ();
149  iterator end() throw ();
150 
151  /* Public Member Functions */
152  int getType() const throw ();
153  void setType(int type) throw (TypeCastException);
154  const char* getTypeName(int type = -1) const throw ();
155  Variant& parse(const std::string &value, int type = TypeAuto) throw (TypeCastException);
156  void zero() throw (); /* Resets Variant to a 0 value or empty for containers. */
157  void clear() throw (); /* Sets Variant to null */
158  size_t size() const throw ();
159  bool empty() const throw ();
160  bool isScalar() const throw ();
161  bool isNumeric() const throw ();
162  bool isTemporal() const throw ();
163  bool isNetwork() const throw ();
164  bool isNull() const throw ();
165  bool isBoolean() const throw ();
166  bool isSigned() const throw ();
167  bool isUnsigned() const throw ();
168  bool isDouble() const throw ();
169  bool isString() const throw ();
170  bool isUUID() const throw ();
171  bool isBinary() const throw ();
172  bool isPointer() const throw ();
173  bool isIPAddress() const throw ();
174  bool isIPPrefix() const throw ();
175  bool isInterval() const throw ();
176  bool isTime() const throw ();
177  bool isDate() const throw ();
178  bool isTimeStamp() const throw ();
179  bool isVector() const throw ();
180  bool isObject() const throw ();
181 
182  template <class T> bool contains(const T &value) const throw (UnsupportedOperatorException) {
183  Variant v(value);
184 
185  if (this->type == TypeObject) {
186  const auto &r = get<Object>().get();
187 
188  return (r.find(v.str()) != r.end());
189  } else if (this->type == TypeVector) {
190  const auto &r = get<Vector>().get();
191 
192  return (std::find(r.begin(), r.end(), v) != r.end());
193  }
194 
195  return (*this == v);
196  }
197 
198  bool erase(const Variant &value) throw ();
199  bool erase(const std::string &value) throw ();
200  bool erase(unsigned int index) throw ();
201  void shrink_to_fit() throw ();
202  void sort(void) throw (UnsupportedOperatorException);
203  void unique(void) throw (UnsupportedOperatorException);
204 
205  const std::vector<Variant>& asVector(void) const throw (TypeCastException);
206  std::vector<Variant>& asVector(void) throw (TypeCastException);
207  const std::map<std::string, Variant>& asMap(void) const throw (TypeCastException);
208  std::map<std::string, Variant>& asMap(void) throw (TypeCastException);
209 
210  template <class T> void push_back(const T &value) throw (UnsupportedOperatorException) {
211  if (this->type != TypeVector) {
212  (*this)[(size_t) 0] = value; /* Forces conversion and assigns. */
213  } else {
214  if (isNull()) {
215  this->value = std::make_shared<Vector>(""); /* Force an empty vector (not null) */
216  }
217 
218  this->get<Vector>().get().push_back(Variant(value));
219  }
220  }
221 
222  void push_back(Variant &&value) throw (UnsupportedOperatorException) {
223  if (this->type != TypeVector) {
224  (*this)[(size_t) 0] = std::move(value); /* Forces conversion and assigns. */
225  } else {
226  if (isNull()) {
227  this->value = std::make_shared<Vector>(""); /* Force an empty vector (not null) */
228  }
229 
230  this->get<Vector>().get().push_back(std::move(value));
231  }
232  }
233 
234  template <class T> const T& get() const throw () {
235  return *std::static_pointer_cast<T>(this->value);
236  }
237 
238  template <class T> T& get() throw () {
239  return *std::static_pointer_cast<T>(this->value);
240  }
241 
242  const std::shared_ptr<Nullable>& get() const throw () {
243  return value;
244  }
245 
246  template <class T> T cast() const throw (TypeCastException);
247  template <class T> T cast() throw (TypeCastException);
248 
249  const std::string& str(int type = JSON) const throw (); /* Not thread safe due to internal buffer */
250  const char* c_str(int type = JSON) const throw (); /* Not thread safe due to internal buffer */
251 
252  Variant& unjson(const std::string &json) throw (TypeCastException);
253  Variant& unmsgpack(const std::string &msgpack) throw (TypeCastException);
254 
255  const std::string& json(void) const throw () { return str(JSON); }
256  const char* c_json(void) const throw () { return c_str(JSON); }
257  const std::string& cjson(void) const throw () { return str(CJSON); }
258  const char* c_cjson(void) const throw () { return c_str(CJSON); }
259  const std::string& msgpack(void) const throw () { return str(MSGPACK); }
260  const char* c_msgpack(void) const throw () { return c_str(MSGPACK); }
261  const std::string& xml(void) const throw () { return str(XML); }
262  const char* c_xml(void) const throw () { return c_str(XML); }
263  const std::string& csv(void) const throw () { return str(CSV); }
264  const char* c_csv(void) const throw () { return c_str(CSV); }
265 
266  size_t msgpack(std::string &buffer, uint32_t size = 0) const throw (TypeCastException);
267  size_t msgpack(uint8_t *buffer, uint32_t size) const throw (TypeCastException);
268  Variant& unmsgpack(uint8_t *buffer, uint32_t size) throw (TypeCastException);
269 
270  size_t msgpackBufferSize(void) const throw ();
271 
272  void swap(Variant& other);
273 
274  /* Operators - See Operators.cpp */
275  Variant& operator=(const Variant &other) throw ();
276  Variant& operator=(Variant &&other) throw ();
277  Variant& operator=(const std::shared_ptr<Nullable> &value) throw ();
278  Variant& operator=(std::shared_ptr<Nullable> &&value) throw ();
279  Variant& operator=(const std::string &value) throw ();
280  Variant& operator=(std::string &&value) throw ();
281  Variant& operator=(const char *value) throw ();
282  Variant& operator=(const sella::util::UUID &value) throw ();
283  Variant& operator=(sella::util::UUID &&value) throw ();
284  Variant& operator=(uuid_t &value) throw ();
285  Variant& operator=(void *ptr) throw (); /* Must assign as '(void*) NULL' to use. */
286  Variant& operator=(const sella::net::IPAddress &value) throw ();
287  Variant& operator=(sella::net::IPAddress &&value) throw ();
288  Variant& operator=(const sella::net::IPPrefix &value) throw ();
289  Variant& operator=(sella::net::IPPrefix &&value) throw ();
290  Variant& operator=(bool value) throw ();
291  Variant& operator=(uint8_t value) throw ();
292  Variant& operator=(uint16_t value) throw ();
293  Variant& operator=(unsigned int value) throw ();
294  Variant& operator=(uint64_t value) throw ();
295  Variant& operator=(int8_t value) throw ();
296  Variant& operator=(int16_t value) throw ();
297  Variant& operator=(int value) throw ();
298  Variant& operator=(int64_t value) throw ();
299  Variant& operator=(float value) throw ();
300  Variant& operator=(double value) throw ();
301 #ifdef __LP64__
302  Variant& operator=(unsigned long long value) throw ();
303  Variant& operator=(long long value) throw ();
304 #else
305  Variant& operator=(unsigned long value) throw ();
306  Variant& operator=(long value) throw ();
307 #endif
308 
309  bool operator!() throw (UnsupportedOperatorException);
310  Variant& operator++() throw (UnsupportedOperatorException);
311  Variant operator++(int) throw (UnsupportedOperatorException);
312  Variant& operator--() throw (UnsupportedOperatorException);
313  Variant operator--(int) throw (UnsupportedOperatorException);
314 
315  const Variant& operator[](const char *key) const throw (UnsupportedOperatorException, RangeException);
316  const Variant& operator[](const std::string &key) const throw (UnsupportedOperatorException, RangeException);
317  Variant& operator[](const char *key) throw ();
318  Variant& operator[](const std::string &key) throw ();
319  Variant& operator[](std::string &&key) throw ();
320  const Variant& operator[](int index) const throw (UnsupportedOperatorException, RangeException);
321  const Variant& operator[](size_t index) const throw (UnsupportedOperatorException, RangeException);
322  Variant& operator[](int index) throw ();
323  Variant& operator[](size_t index) throw ();
324 
325  explicit operator const char*() const throw (TypeCastException);
326  explicit operator const std::string&() const throw (TypeCastException); /* Constructor results in ambiguous non-const cast operator. */
327  explicit operator const sella::util::UUID&() const throw (TypeCastException);
328  explicit operator const sella::net::IPAddress&() const throw (TypeCastException); /* Constructor results in ambiguous non-const cast operator. */
329  explicit operator const sella::net::IPPrefix&() const throw (TypeCastException); /* Constructor results in ambiguous non-const cast operator. */
330  explicit operator bool() const throw (TypeCastException);
331  explicit operator uint8_t() const throw (TypeCastException);
332  explicit operator uint16_t() const throw (TypeCastException);
333  explicit operator uint32_t() const throw (TypeCastException);
334  explicit operator uint64_t() const throw (TypeCastException);
335  explicit operator int8_t() const throw (TypeCastException);
336  explicit operator int16_t() const throw (TypeCastException);
337  explicit operator int32_t() const throw (TypeCastException);
338  explicit operator int64_t() const throw (TypeCastException);
339  explicit operator float() const throw (TypeCastException);
340  explicit operator double() const throw (TypeCastException);
341 #ifdef __LP64__
342  explicit operator unsigned long long() const throw (TypeCastException);
343  explicit operator long long() const throw (TypeCastException);
344 #else
345  explicit operator unsigned long() const throw (TypeCastException);
346  explicit operator long() const throw (TypeCastException);
347 #endif
348  explicit operator void*() const throw (TypeCastException);
349 
350  /* Friends */
351  friend bool operator==(const Variant &a, const Variant &b) throw ();
352  friend bool operator!=(const Variant &a, const Variant &b) throw ();
353  friend bool operator>(const Variant &a, const Variant &b) throw (UnsupportedOperatorException);
354  friend bool operator<(const Variant &a, const Variant &b) throw (UnsupportedOperatorException);
355  friend bool operator>=(const Variant &a, const Variant &b) throw (UnsupportedOperatorException);
356  friend bool operator<=(const Variant &a, const Variant &b) throw (UnsupportedOperatorException);
357 
358  friend Variant& operator+=(Variant &a, const Variant &b) throw (UnsupportedOperatorException);
359  friend Variant& operator+=(Variant &a, const std::string &b) throw (UnsupportedOperatorException);
360  friend Variant& operator+=(Variant &a, int b) throw (UnsupportedOperatorException) { return a += (int64_t) b; }
361  friend Variant& operator+=(Variant &a, int64_t b) throw (UnsupportedOperatorException);
362  friend Variant& operator+=(Variant &a, unsigned int b) throw (UnsupportedOperatorException) { return a += (uint64_t) b; }
363  friend Variant& operator+=(Variant &a, uint64_t b) throw (UnsupportedOperatorException);
364  friend Variant& operator+=(Variant &a, double b) throw (UnsupportedOperatorException);
365  friend Variant& operator+=(Variant &a, Variant &&b) throw (UnsupportedOperatorException);
366  friend Variant& operator+=(Variant &a, std::string &&b) throw (UnsupportedOperatorException);
367  friend Variant& operator-=(Variant &a, const Variant &b) throw (UnsupportedOperatorException);
368  friend Variant& operator-=(Variant &a, int b) throw (UnsupportedOperatorException) { return a -= (int64_t) b; }
369  friend Variant& operator-=(Variant &a, int64_t b) throw (UnsupportedOperatorException);
370  friend Variant& operator-=(Variant &a, unsigned int b) throw (UnsupportedOperatorException) { return a -= (uint64_t) b; }
371  friend Variant& operator-=(Variant &a, uint64_t b) throw (UnsupportedOperatorException);
372  friend Variant& operator-=(Variant &a, double b) throw (UnsupportedOperatorException);
373  friend Variant& operator*=(Variant &a, const Variant &b) throw (UnsupportedOperatorException);
374  friend Variant& operator/=(Variant &a, const Variant &b) throw (UnsupportedOperatorException);
375  friend Variant& operator^=(Variant &a, const Variant &b) throw (UnsupportedOperatorException);
376  friend Variant& operator%=(Variant &a, const Variant &b) throw (UnsupportedOperatorException);
377  friend Variant& operator&=(Variant &a, const Variant &b) throw (UnsupportedOperatorException);
378  friend Variant& operator|=(Variant &a, const Variant &b) throw (UnsupportedOperatorException);
379  friend Variant& operator<<=(Variant &a, const Variant &b) throw (UnsupportedOperatorException);
380  friend Variant& operator>>=(Variant &a, const Variant &b) throw (UnsupportedOperatorException);
381 
382  friend Variant operator+(const Variant &a, const Variant &b) throw (UnsupportedOperatorException);
383  friend Variant operator-(const Variant &a, const Variant &b) throw (UnsupportedOperatorException);
384  friend Variant operator*(const Variant &a, const Variant &b) throw (UnsupportedOperatorException);
385  friend Variant operator/(const Variant &a, const Variant &b) throw (UnsupportedOperatorException);
386  friend Variant operator^(const Variant &a, const Variant &b) throw (UnsupportedOperatorException);
387  friend Variant operator%(const Variant &a, const Variant &b) throw (UnsupportedOperatorException);
388  friend Variant operator&(const Variant &a, const Variant &b) throw (UnsupportedOperatorException);
389  friend Variant operator|(const Variant &a, const Variant &b) throw (UnsupportedOperatorException);
390  friend Variant operator<<(const Variant &a, const Variant &b) throw (UnsupportedOperatorException);
391  friend Variant operator>>(const Variant &a, const Variant &b) throw (UnsupportedOperatorException);
392 
393  /* Specialized operators */
394  friend bool operator==(const Variant &a, const char *b) throw (TypeCastException) { return (a.isString() && a.str().compare(b) == 0); }
395  friend bool operator==(const char *a, const Variant &b) throw (TypeCastException) { return (b.isString() && b.str().compare(a) == 0); }
396  friend bool operator==(const Variant &a, const std::string &b) throw (TypeCastException) { return (a.isString() && a.str().compare(b) == 0); }
397  friend bool operator==(const std::string &a, const Variant &b) throw (TypeCastException) { return (b.isString() && b.str().compare(a) == 0); }
398  friend bool operator==(const Variant &a, bool b) throw (TypeCastException) { return (a.isBoolean() && (bool) a == b); }
399  friend bool operator==(bool a, const Variant &b) throw (TypeCastException) { return (b.isBoolean() && (bool) b == a); }
400  friend bool operator==(uint8_t a, const Variant &b) throw (TypeCastException) { return (b.isUnsigned() && (uint8_t) b == a); }
401  friend bool operator==(const Variant &a, uint8_t b) throw (TypeCastException) { return (a.isUnsigned() && (uint8_t) a == b); }
402  friend bool operator==(uint16_t a, const Variant &b) throw (TypeCastException) { return (b.isUnsigned() && (uint16_t) b == a); }
403  friend bool operator==(const Variant &a, uint16_t b) throw (TypeCastException) { return (a.isUnsigned() && (uint16_t) a == b); }
404  friend bool operator==(uint32_t a, const Variant &b) throw (TypeCastException) { return (b.isUnsigned() && (uint32_t) b == a); }
405  friend bool operator==(const Variant &a, uint32_t b) throw (TypeCastException) { return (a.isUnsigned() && (uint32_t) a == b); }
406  friend bool operator==(uint64_t a, const Variant &b) throw (TypeCastException) { return (b.isUnsigned() && (uint64_t) b == a); }
407  friend bool operator==(const Variant &a, uint64_t b) throw (TypeCastException) { return (a.isUnsigned() && (uint64_t) a == b); }
408  friend bool operator==(int16_t a, const Variant &b) throw (TypeCastException) { return (b.isSigned() && (int16_t) b == a); }
409  friend bool operator==(const Variant &a, int16_t b) throw (TypeCastException) { return (a.isSigned() && (int16_t) a == b); }
410  friend bool operator==(int32_t a, const Variant &b) throw (TypeCastException) { return (b.isSigned() && (int32_t) b == a); }
411  friend bool operator==(const Variant &a, int32_t b) throw (TypeCastException) { return (a.isSigned() && (int32_t) a == b); }
412  friend bool operator==(int64_t a, const Variant &b) throw (TypeCastException) { return (b.isSigned() && (int64_t) b == a); }
413  friend bool operator==(const Variant &a, int64_t b) throw (TypeCastException) { return (a.isSigned() && (int64_t) a == b); }
414  friend bool operator==(float a, const Variant &b) throw (TypeCastException) { return (b.isDouble() && (double) b == a); }
415  friend bool operator==(const Variant &a, float b) throw (TypeCastException) { return (a.isDouble() && (double) a == b); }
416  friend bool operator==(double a, const Variant &b) throw (TypeCastException) { return (b.isDouble() && (double) b == a); }
417  friend bool operator==(const Variant &a, double b) throw (TypeCastException) { return (a.isDouble() && (double) a == b); }
418 #ifdef __LP64__
419  friend bool operator==(unsigned long long a, const Variant &b) throw (TypeCastException) { return (b.isUnsigned() && (unsigned long long) b == a); }
420  friend bool operator==(const Variant &a, unsigned long long b) throw (TypeCastException) { return (a.isUnsigned() && (unsigned long long) a == b); }
421  friend bool operator==(long long a, const Variant &b) throw (TypeCastException) { return (b.isSigned() && (long long) b == a); }
422  friend bool operator==(const Variant &a, long long b) throw (TypeCastException) { return (a.isSigned() && (long long) a == b); }
423 #else
424  friend bool operator==(unsigned long a, const Variant &b) throw (TypeCastException) { return (b.isUnsigned() && (unsigned long) b == a); }
425  friend bool operator==(const Variant &a, unsigned long b) throw (TypeCastException) { return (a.isUnsigned() && (unsigned long) a == b); }
426  friend bool operator==(long a, const Variant &b) throw (TypeCastException) { return (b.isSigned() && (long) b == a); }
427  friend bool operator==(const Variant &a, long b) throw (TypeCastException) { return (a.isSigned() && (long) a == b); }
428 #endif
429 
430  friend bool operator!=(const Variant &a, const char *b) throw (TypeCastException) { return !(a == b); }
431  friend bool operator!=(const char *a, const Variant &b) throw (TypeCastException) { return !(a == b); }
432  friend bool operator!=(const Variant &a, const std::string &b) throw (TypeCastException) { return !(a == b); }
433  friend bool operator!=(const std::string &a, const Variant &b) throw (TypeCastException) { return !(a == b); }
434  friend bool operator!=(const Variant &a, bool b) throw (TypeCastException) { return !(a == b); }
435  friend bool operator!=(bool a, const Variant &b) throw (TypeCastException) { return !(a == b); }
436  friend bool operator!=(uint8_t a, const Variant &b) throw (TypeCastException) { return !(a == b); }
437  friend bool operator!=(const Variant &a, uint8_t b) throw (TypeCastException) { return !(a == b); }
438  friend bool operator!=(uint16_t a, const Variant &b) throw (TypeCastException) { return !(a == b); }
439  friend bool operator!=(const Variant &a, uint16_t b) throw (TypeCastException) { return !(a == b); }
440  friend bool operator!=(uint32_t a, const Variant &b) throw (TypeCastException) { return !(a == b); }
441  friend bool operator!=(const Variant &a, uint32_t b) throw (TypeCastException) { return !(a == b); }
442  friend bool operator!=(uint64_t a, const Variant &b) throw (TypeCastException) { return !(a == b); }
443  friend bool operator!=(const Variant &a, uint64_t b) throw (TypeCastException) { return !(a == b); }
444  friend bool operator!=(int16_t a, const Variant &b) throw (TypeCastException) { return !(a == b); }
445  friend bool operator!=(const Variant &a, int16_t b) throw (TypeCastException) { return !(a == b); }
446  friend bool operator!=(int32_t a, const Variant &b) throw (TypeCastException) { return !(a == b); }
447  friend bool operator!=(const Variant &a, int32_t b) throw (TypeCastException) { return !(a == b); }
448  friend bool operator!=(int64_t a, const Variant &b) throw (TypeCastException) { return !(a == b); }
449  friend bool operator!=(const Variant &a, int64_t b) throw (TypeCastException) { return !(a == b); }
450  friend bool operator!=(float a, const Variant &b) throw (TypeCastException) { return !(a == b); }
451  friend bool operator!=(const Variant &a, float b) throw (TypeCastException) { return !(a == b); }
452  friend bool operator!=(double a, const Variant &b) throw (TypeCastException) { return !(a == b); }
453  friend bool operator!=(const Variant &a, double b) throw (TypeCastException) { return !(a == b); }
454 #ifdef __LP64__
455  friend bool operator!=(unsigned long long a, const Variant &b) throw (TypeCastException) { return !(a == b); }
456  friend bool operator!=(const Variant &a, unsigned long long b) throw (TypeCastException) { return !(a == b); }
457  friend bool operator!=(long long a, const Variant &b) throw (TypeCastException) { return !(a == b); }
458  friend bool operator!=(const Variant &a, long long b) throw (TypeCastException) { return !(a == b); }
459 #else
460  friend bool operator!=(unsigned long a, const Variant &b) throw (TypeCastException) { return !(a == b); }
461  friend bool operator!=(const Variant &a, unsigned long b) throw (TypeCastException) { return !(a == b); }
462  friend bool operator!=(long a, const Variant &b) throw (TypeCastException) { return !(a == b); }
463  friend bool operator!=(const Variant &a, long b) throw (TypeCastException) { return !(a == b); }
464 #endif
465 
466  friend bool operator>(const Variant &a, const char *b) throw (UnsupportedOperatorException) { return a > Variant(b, TypeString); }
467  friend bool operator>(const char *a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a, TypeString) > b; }
468  friend bool operator>(const Variant &a, const std::string &b) throw (UnsupportedOperatorException) { return a > Variant(b); }
469  friend bool operator>(const std::string &a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) > b; }
470  friend bool operator>(const Variant &a, bool b) throw (UnsupportedOperatorException) { return a > Variant(b); }
471  friend bool operator>(bool a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) > b; }
472  friend bool operator>(uint8_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) > b; }
473  friend bool operator>(const Variant &a, uint8_t b) throw (UnsupportedOperatorException) { return a > Variant(b); }
474  friend bool operator>(uint16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) > b; }
475  friend bool operator>(const Variant &a, uint16_t b) throw (UnsupportedOperatorException) { return a > Variant(b); }
476  friend bool operator>(uint32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) > b; }
477  friend bool operator>(const Variant &a, uint32_t b) throw (UnsupportedOperatorException) { return a > Variant(b); }
478  friend bool operator>(uint64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) > b; }
479  friend bool operator>(const Variant &a, uint64_t b) throw (UnsupportedOperatorException) { return a > Variant(b); }
480  friend bool operator>(int16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) > b; }
481  friend bool operator>(const Variant &a, int16_t b) throw (UnsupportedOperatorException) { return a > Variant(b); }
482  friend bool operator>(int32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) > b; }
483  friend bool operator>(const Variant &a, int32_t b) throw (UnsupportedOperatorException) { return a > Variant(b); }
484  friend bool operator>(int64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) > b; }
485  friend bool operator>(const Variant &a, int64_t b) throw (UnsupportedOperatorException) { return a > Variant(b); }
486  friend bool operator>(float a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) > b; }
487  friend bool operator>(const Variant &a, float b) throw (UnsupportedOperatorException) { return a > Variant(b); }
488  friend bool operator>(double a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) > b; }
489  friend bool operator>(const Variant &a, double b) throw (UnsupportedOperatorException) { return a > Variant(b); }
490 #ifdef __LP64__
491  friend bool operator>(unsigned long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) > b; }
492  friend bool operator>(const Variant &a, unsigned long long b) throw (UnsupportedOperatorException) { return a > Variant(b); }
493  friend bool operator>(long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) > b; }
494  friend bool operator>(const Variant &a, long long b) throw (UnsupportedOperatorException) { return a > Variant(b); }
495 #else
496  friend bool operator>(unsigned long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) > b; }
497  friend bool operator>(const Variant &a, unsigned long b) throw (UnsupportedOperatorException) { return a > Variant(b); }
498  friend bool operator>(long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) > b; }
499  friend bool operator>(const Variant &a, long b) throw (UnsupportedOperatorException) { return a > Variant(b); }
500 #endif
501 
502  friend bool operator<(const Variant &a, const char *b) throw (UnsupportedOperatorException) { return a < Variant(b, TypeString); }
503  friend bool operator<(const char *a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a, TypeString) < b; }
504  friend bool operator<(const Variant &a, const std::string &b) throw (UnsupportedOperatorException) { return a < Variant(b); }
505  friend bool operator<(const std::string &a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) < b; }
506  friend bool operator<(const Variant &a, bool b) throw (UnsupportedOperatorException) { return a < Variant(b); }
507  friend bool operator<(bool a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) < b; }
508  friend bool operator<(uint8_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) < b; }
509  friend bool operator<(const Variant &a, uint8_t b) throw (UnsupportedOperatorException) { return a < Variant(b); }
510  friend bool operator<(uint16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) < b; }
511  friend bool operator<(const Variant &a, uint16_t b) throw (UnsupportedOperatorException) { return a < Variant(b); }
512  friend bool operator<(uint32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) < b; }
513  friend bool operator<(const Variant &a, uint32_t b) throw (UnsupportedOperatorException) { return a < Variant(b); }
514  friend bool operator<(uint64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) < b; }
515  friend bool operator<(const Variant &a, uint64_t b) throw (UnsupportedOperatorException) { return a < Variant(b); }
516  friend bool operator<(int16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) < b; }
517  friend bool operator<(const Variant &a, int16_t b) throw (UnsupportedOperatorException) { return a < Variant(b); }
518  friend bool operator<(int32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) < b; }
519  friend bool operator<(const Variant &a, int32_t b) throw (UnsupportedOperatorException) { return a < Variant(b); }
520  friend bool operator<(int64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) < b; }
521  friend bool operator<(const Variant &a, int64_t b) throw (UnsupportedOperatorException) { return a < Variant(b); }
522  friend bool operator<(float a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) < b; }
523  friend bool operator<(const Variant &a, float b) throw (UnsupportedOperatorException) { return a < Variant(b); }
524  friend bool operator<(double a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) < b; }
525  friend bool operator<(const Variant &a, double b) throw (UnsupportedOperatorException) { return a < Variant(b); }
526 #ifdef __LP64__
527  friend bool operator<(unsigned long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) < b; }
528  friend bool operator<(const Variant &a, unsigned long long b) throw (UnsupportedOperatorException) { return a < Variant(b); }
529  friend bool operator<(long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) < b; }
530  friend bool operator<(const Variant &a, long long b) throw (UnsupportedOperatorException) { return a < Variant(b); }
531 #else
532  friend bool operator<(unsigned long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) < b; }
533  friend bool operator<(const Variant &a, unsigned long b) throw (UnsupportedOperatorException) { return a < Variant(b); }
534  friend bool operator<(long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) < b; }
535  friend bool operator<(const Variant &a, long b) throw (UnsupportedOperatorException) { return a < Variant(b); }
536 #endif
537 
538  friend bool operator>=(const Variant &a, const char *b) throw (UnsupportedOperatorException) { return a >= Variant(b, TypeString); }
539  friend bool operator>=(const char *a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a, TypeString) >= b; }
540  friend bool operator>=(const Variant &a, const std::string &b) throw (UnsupportedOperatorException) { return a >= Variant(b); }
541  friend bool operator>=(const std::string &a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >= b; }
542  friend bool operator>=(const Variant &a, bool b) throw (UnsupportedOperatorException) { return a >= Variant(b); }
543  friend bool operator>=(bool a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >= b; }
544  friend bool operator>=(uint8_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >= b; }
545  friend bool operator>=(const Variant &a, uint8_t b) throw (UnsupportedOperatorException) { return a >= Variant(b); }
546  friend bool operator>=(uint16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >= b; }
547  friend bool operator>=(const Variant &a, uint16_t b) throw (UnsupportedOperatorException) { return a >= Variant(b); }
548  friend bool operator>=(uint32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >= b; }
549  friend bool operator>=(const Variant &a, uint32_t b) throw (UnsupportedOperatorException) { return a >= Variant(b); }
550  friend bool operator>=(uint64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >= b; }
551  friend bool operator>=(const Variant &a, uint64_t b) throw (UnsupportedOperatorException) { return a >= Variant(b); }
552  friend bool operator>=(int16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >= b; }
553  friend bool operator>=(const Variant &a, int16_t b) throw (UnsupportedOperatorException) { return a >= Variant(b); }
554  friend bool operator>=(int32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >= b; }
555  friend bool operator>=(const Variant &a, int32_t b) throw (UnsupportedOperatorException) { return a >= Variant(b); }
556  friend bool operator>=(int64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >= b; }
557  friend bool operator>=(const Variant &a, int64_t b) throw (UnsupportedOperatorException) { return a >= Variant(b); }
558  friend bool operator>=(float a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >= b; }
559  friend bool operator>=(const Variant &a, float b) throw (UnsupportedOperatorException) { return a >= Variant(b); }
560  friend bool operator>=(double a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >= b; }
561  friend bool operator>=(const Variant &a, double b) throw (UnsupportedOperatorException) { return a >= Variant(b); }
562 #ifdef __LP64__
563  friend bool operator>=(unsigned long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >= b; }
564  friend bool operator>=(const Variant &a, unsigned long long b) throw (UnsupportedOperatorException) { return a >= Variant(b); }
565  friend bool operator>=(long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >= b; }
566  friend bool operator>=(const Variant &a, long long b) throw (UnsupportedOperatorException) { return a >= Variant(b); }
567 #else
568  friend bool operator>=(unsigned long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >= b; }
569  friend bool operator>=(const Variant &a, unsigned long b) throw (UnsupportedOperatorException) { return a >= Variant(b); }
570  friend bool operator>=(long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >= b; }
571  friend bool operator>=(const Variant &a, long b) throw (UnsupportedOperatorException) { return a >= Variant(b); }
572 #endif
573 
574  friend bool operator<=(const Variant &a, const char *b) throw (UnsupportedOperatorException) { return a <= Variant(b, TypeString); }
575  friend bool operator<=(const char *a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a, TypeString) <= b; }
576  friend bool operator<=(const Variant &a, const std::string &b) throw (UnsupportedOperatorException) { return a <= Variant(b); }
577  friend bool operator<=(const std::string &a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) <= b; }
578  friend bool operator<=(const Variant &a, bool b) throw (UnsupportedOperatorException) { return a <= Variant(b); }
579  friend bool operator<=(bool a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) <= b; }
580  friend bool operator<=(uint8_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) <= b; }
581  friend bool operator<=(const Variant &a, uint8_t b) throw (UnsupportedOperatorException) { return a <= Variant(b); }
582  friend bool operator<=(uint16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) <= b; }
583  friend bool operator<=(const Variant &a, uint16_t b) throw (UnsupportedOperatorException) { return a <= Variant(b); }
584  friend bool operator<=(uint32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) <= b; }
585  friend bool operator<=(const Variant &a, uint32_t b) throw (UnsupportedOperatorException) { return a <= Variant(b); }
586  friend bool operator<=(uint64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) <= b; }
587  friend bool operator<=(const Variant &a, uint64_t b) throw (UnsupportedOperatorException) { return a <= Variant(b); }
588  friend bool operator<=(int16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) <= b; }
589  friend bool operator<=(const Variant &a, int16_t b) throw (UnsupportedOperatorException) { return a <= Variant(b); }
590  friend bool operator<=(int32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) <= b; }
591  friend bool operator<=(const Variant &a, int32_t b) throw (UnsupportedOperatorException) { return a <= Variant(b); }
592  friend bool operator<=(int64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) <= b; }
593  friend bool operator<=(const Variant &a, int64_t b) throw (UnsupportedOperatorException) { return a <= Variant(b); }
594  friend bool operator<=(float a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) <= b; }
595  friend bool operator<=(const Variant &a, float b) throw (UnsupportedOperatorException) { return a <= Variant(b); }
596  friend bool operator<=(double a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) <= b; }
597  friend bool operator<=(const Variant &a, double b) throw (UnsupportedOperatorException) { return a <= Variant(b); }
598 #ifdef __LP64__
599  friend bool operator<=(unsigned long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) <= b; }
600  friend bool operator<=(const Variant &a, unsigned long long b) throw (UnsupportedOperatorException) { return a <= Variant(b); }
601  friend bool operator<=(long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) <= b; }
602  friend bool operator<=(const Variant &a, long long b) throw (UnsupportedOperatorException) { return a <= Variant(b); }
603 #else
604  friend bool operator<=(unsigned long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) <= b; }
605  friend bool operator<=(const Variant &a, unsigned long b) throw (UnsupportedOperatorException) { return a <= Variant(b); }
606  friend bool operator<=(long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) <= b; }
607  friend bool operator<=(const Variant &a, long b) throw (UnsupportedOperatorException) { return a <= Variant(b); }
608 #endif
609 
610  friend Variant operator+(const Variant &a, const char *b) throw (UnsupportedOperatorException) { return a + Variant(b, TypeString); }
611  friend Variant operator+(const char *a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a, TypeString) + b; }
612  friend Variant operator+(const Variant &a, const std::string &b) throw (UnsupportedOperatorException) { return a + Variant(b); }
613  friend Variant operator+(const std::string &a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) + b; }
614  friend Variant operator+(const Variant &a, bool b) throw (UnsupportedOperatorException) { return a + Variant(b); }
615  friend Variant operator+(bool a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) + b; }
616  friend Variant operator+(uint8_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) + b; }
617  friend Variant operator+(const Variant &a, uint8_t b) throw (UnsupportedOperatorException) { return a + Variant(b); }
618  friend Variant operator+(uint16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) + b; }
619  friend Variant operator+(const Variant &a, uint16_t b) throw (UnsupportedOperatorException) { return a + Variant(b); }
620  friend Variant operator+(uint32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) + b; }
621  friend Variant operator+(const Variant &a, uint32_t b) throw (UnsupportedOperatorException) { return a + Variant(b); }
622  friend Variant operator+(uint64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) + b; }
623  friend Variant operator+(const Variant &a, uint64_t b) throw (UnsupportedOperatorException) { return a + Variant(b); }
624  friend Variant operator+(int16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) + b; }
625  friend Variant operator+(const Variant &a, int16_t b) throw (UnsupportedOperatorException) { return a + Variant(b); }
626  friend Variant operator+(int32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) + b; }
627  friend Variant operator+(const Variant &a, int32_t b) throw (UnsupportedOperatorException) { return a + Variant(b); }
628  friend Variant operator+(int64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) + b; }
629  friend Variant operator+(const Variant &a, int64_t b) throw (UnsupportedOperatorException) { return a + Variant(b); }
630  friend Variant operator+(float a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) + b; }
631  friend Variant operator+(const Variant &a, float b) throw (UnsupportedOperatorException) { return a + Variant(b); }
632  friend Variant operator+(double a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) + b; }
633  friend Variant operator+(const Variant &a, double b) throw (UnsupportedOperatorException) { return a + Variant(b); }
634 #ifdef __LP64__
635  friend Variant operator+(unsigned long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) + b; }
636  friend Variant operator+(const Variant &a, unsigned long long b) throw (UnsupportedOperatorException) { return a + Variant(b); }
637  friend Variant operator+(long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) + b; }
638  friend Variant operator+(const Variant &a, long long b) throw (UnsupportedOperatorException) { return a + Variant(b); }
639 #else
640  friend Variant operator+(unsigned long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) + b; }
641  friend Variant operator+(const Variant &a, unsigned long b) throw (UnsupportedOperatorException) { return a + Variant(b); }
642  friend Variant operator+(long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) + b; }
643  friend Variant operator+(const Variant &a, long b) throw (UnsupportedOperatorException) { return a + Variant(b); }
644 #endif
645 
646  friend Variant operator-(const Variant &a, const std::string &b) throw (UnsupportedOperatorException) { return a - Variant(b); }
647  friend Variant operator-(const std::string &a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) - b; }
648  friend Variant operator-(const Variant &a, const char *b) throw (UnsupportedOperatorException) { return a - Variant(b, TypeString); }
649  friend Variant operator-(const char *a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a, TypeString) - b; }
650  friend Variant operator-(const Variant &a, bool b) throw (UnsupportedOperatorException) { return a - Variant(b); }
651  friend Variant operator-(bool a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) - b; }
652  friend Variant operator-(uint8_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) - b; }
653  friend Variant operator-(const Variant &a, uint8_t b) throw (UnsupportedOperatorException) { return a - Variant(b); }
654  friend Variant operator-(uint16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) - b; }
655  friend Variant operator-(const Variant &a, uint16_t b) throw (UnsupportedOperatorException) { return a - Variant(b); }
656  friend Variant operator-(uint32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) - b; }
657  friend Variant operator-(const Variant &a, uint32_t b) throw (UnsupportedOperatorException) { return a - Variant(b); }
658  friend Variant operator-(uint64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) - b; }
659  friend Variant operator-(const Variant &a, uint64_t b) throw (UnsupportedOperatorException) { return a - Variant(b); }
660  friend Variant operator-(int16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) - b; }
661  friend Variant operator-(const Variant &a, int16_t b) throw (UnsupportedOperatorException) { return a - Variant(b); }
662  friend Variant operator-(int32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) - b; }
663  friend Variant operator-(const Variant &a, int32_t b) throw (UnsupportedOperatorException) { return a - Variant(b); }
664  friend Variant operator-(int64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) - b; }
665  friend Variant operator-(const Variant &a, int64_t b) throw (UnsupportedOperatorException) { return a - Variant(b); }
666  friend Variant operator-(float a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) - b; }
667  friend Variant operator-(const Variant &a, float b) throw (UnsupportedOperatorException) { return a - Variant(b); }
668  friend Variant operator-(double a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) - b; }
669  friend Variant operator-(const Variant &a, double b) throw (UnsupportedOperatorException) { return a - Variant(b); }
670 #ifdef __LP64__
671  friend Variant operator-(unsigned long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) - b; }
672  friend Variant operator-(const Variant &a, unsigned long long b) throw (UnsupportedOperatorException) { return a - Variant(b); }
673  friend Variant operator-(long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) - b; }
674  friend Variant operator-(const Variant &a, long long b) throw (UnsupportedOperatorException) { return a - Variant(b); }
675 #else
676  friend Variant operator-(unsigned long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) - b; }
677  friend Variant operator-(const Variant &a, unsigned long b) throw (UnsupportedOperatorException) { return a - Variant(b); }
678  friend Variant operator-(long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) - b; }
679  friend Variant operator-(const Variant &a, long b) throw (UnsupportedOperatorException) { return a - Variant(b); }
680 #endif
681 
682  friend Variant operator*(const Variant &a, const char *b) throw (UnsupportedOperatorException) { return a * Variant(b, TypeString); }
683  friend Variant operator*(const char *a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a, TypeString) * b; }
684  friend Variant operator*(const Variant &a, const std::string &b) throw (UnsupportedOperatorException) { return a * Variant(b); }
685  friend Variant operator*(const std::string &a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) * b; }
686  friend Variant operator*(const Variant &a, bool b) throw (UnsupportedOperatorException) { return a * Variant(b); }
687  friend Variant operator*(bool a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) * b; }
688  friend Variant operator*(uint8_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) * b; }
689  friend Variant operator*(const Variant &a, uint8_t b) throw (UnsupportedOperatorException) { return a * Variant(b); }
690  friend Variant operator*(uint16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) * b; }
691  friend Variant operator*(const Variant &a, uint16_t b) throw (UnsupportedOperatorException) { return a * Variant(b); }
692  friend Variant operator*(uint32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) * b; }
693  friend Variant operator*(const Variant &a, uint32_t b) throw (UnsupportedOperatorException) { return a * Variant(b); }
694  friend Variant operator*(uint64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) * b; }
695  friend Variant operator*(const Variant &a, uint64_t b) throw (UnsupportedOperatorException) { return a * Variant(b); }
696  friend Variant operator*(int16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) * b; }
697  friend Variant operator*(const Variant &a, int16_t b) throw (UnsupportedOperatorException) { return a * Variant(b); }
698  friend Variant operator*(int32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) * b; }
699  friend Variant operator*(const Variant &a, int32_t b) throw (UnsupportedOperatorException) { return a * Variant(b); }
700  friend Variant operator*(int64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) * b; }
701  friend Variant operator*(const Variant &a, int64_t b) throw (UnsupportedOperatorException) { return a * Variant(b); }
702  friend Variant operator*(float a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) * b; }
703  friend Variant operator*(const Variant &a, float b) throw (UnsupportedOperatorException) { return a * Variant(b); }
704  friend Variant operator*(double a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) * b; }
705  friend Variant operator*(const Variant &a, double b) throw (UnsupportedOperatorException) { return a * Variant(b); }
706 #ifdef __LP64__
707  friend Variant operator*(unsigned long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) * b; }
708  friend Variant operator*(const Variant &a, unsigned long long b) throw (UnsupportedOperatorException) { return a * Variant(b); }
709  friend Variant operator*(long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) * b; }
710  friend Variant operator*(const Variant &a, long long b) throw (UnsupportedOperatorException) { return a * Variant(b); }
711 #else
712  friend Variant operator*(unsigned long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) * b; }
713  friend Variant operator*(const Variant &a, unsigned long b) throw (UnsupportedOperatorException) { return a * Variant(b); }
714  friend Variant operator*(long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) * b; }
715  friend Variant operator*(const Variant &a, long b) throw (UnsupportedOperatorException) { return a * Variant(b); }
716 #endif
717 
718  friend Variant operator/(const Variant &a, const char *b) throw (UnsupportedOperatorException) { return a / Variant(b, TypeString); }
719  friend Variant operator/(const char *a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a, TypeString) / b; }
720  friend Variant operator/(const Variant &a, const std::string &b) throw (UnsupportedOperatorException) { return a / Variant(b); }
721  friend Variant operator/(const std::string &a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) / b; }
722  friend Variant operator/(const Variant &a, bool b) throw (UnsupportedOperatorException) { return a / Variant(b); }
723  friend Variant operator/(bool a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) / b; }
724  friend Variant operator/(uint8_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) / b; }
725  friend Variant operator/(const Variant &a, uint8_t b) throw (UnsupportedOperatorException) { return a / Variant(b); }
726  friend Variant operator/(uint16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) / b; }
727  friend Variant operator/(const Variant &a, uint16_t b) throw (UnsupportedOperatorException) { return a / Variant(b); }
728  friend Variant operator/(uint32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) / b; }
729  friend Variant operator/(const Variant &a, uint32_t b) throw (UnsupportedOperatorException) { return a / Variant(b); }
730  friend Variant operator/(uint64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) / b; }
731  friend Variant operator/(const Variant &a, uint64_t b) throw (UnsupportedOperatorException) { return a / Variant(b); }
732  friend Variant operator/(int16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) / b; }
733  friend Variant operator/(const Variant &a, int16_t b) throw (UnsupportedOperatorException) { return a / Variant(b); }
734  friend Variant operator/(int32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) / b; }
735  friend Variant operator/(const Variant &a, int32_t b) throw (UnsupportedOperatorException) { return a / Variant(b); }
736  friend Variant operator/(int64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) / b; }
737  friend Variant operator/(const Variant &a, int64_t b) throw (UnsupportedOperatorException) { return a / Variant(b); }
738  friend Variant operator/(float a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) / b; }
739  friend Variant operator/(const Variant &a, float b) throw (UnsupportedOperatorException) { return a / Variant(b); }
740  friend Variant operator/(double a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) / b; }
741  friend Variant operator/(const Variant &a, double b) throw (UnsupportedOperatorException) { return a / Variant(b); }
742 #ifdef __LP64__
743  friend Variant operator/(unsigned long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) / b; }
744  friend Variant operator/(const Variant &a, unsigned long long b) throw (UnsupportedOperatorException) { return a / Variant(b); }
745  friend Variant operator/(long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) / b; }
746  friend Variant operator/(const Variant &a, long long b) throw (UnsupportedOperatorException) { return a / Variant(b); }
747 #else
748  friend Variant operator/(unsigned long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) / b; }
749  friend Variant operator/(const Variant &a, unsigned long b) throw (UnsupportedOperatorException) { return a / Variant(b); }
750  friend Variant operator/(long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) / b; }
751  friend Variant operator/(const Variant &a, long b) throw (UnsupportedOperatorException) { return a / Variant(b); }
752 #endif
753 
754  friend Variant operator^(const Variant &a, const char *b) throw (UnsupportedOperatorException) { return a ^ Variant(b, TypeString); }
755  friend Variant operator^(const char *a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a, TypeString) ^ b; }
756  friend Variant operator^(const Variant &a, const std::string &b) throw (UnsupportedOperatorException) { return a ^ Variant(b); }
757  friend Variant operator^(const std::string &a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) ^ b; }
758  friend Variant operator^(const Variant &a, bool b) throw (UnsupportedOperatorException) { return a ^ Variant(b); }
759  friend Variant operator^(bool a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) ^ b; }
760  friend Variant operator^(uint8_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) ^ b; }
761  friend Variant operator^(const Variant &a, uint8_t b) throw (UnsupportedOperatorException) { return a ^ Variant(b); }
762  friend Variant operator^(uint16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) ^ b; }
763  friend Variant operator^(const Variant &a, uint16_t b) throw (UnsupportedOperatorException) { return a ^ Variant(b); }
764  friend Variant operator^(uint32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) ^ b; }
765  friend Variant operator^(const Variant &a, uint32_t b) throw (UnsupportedOperatorException) { return a ^ Variant(b); }
766  friend Variant operator^(uint64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) ^ b; }
767  friend Variant operator^(const Variant &a, uint64_t b) throw (UnsupportedOperatorException) { return a ^ Variant(b); }
768  friend Variant operator^(int16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) ^ b; }
769  friend Variant operator^(const Variant &a, int16_t b) throw (UnsupportedOperatorException) { return a ^ Variant(b); }
770  friend Variant operator^(int32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) ^ b; }
771  friend Variant operator^(const Variant &a, int32_t b) throw (UnsupportedOperatorException) { return a ^ Variant(b); }
772  friend Variant operator^(int64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) ^ b; }
773  friend Variant operator^(const Variant &a, int64_t b) throw (UnsupportedOperatorException) { return a ^ Variant(b); }
774 #ifdef __LP64__
775  friend Variant operator^(unsigned long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) ^ b; }
776  friend Variant operator^(const Variant &a, unsigned long long b) throw (UnsupportedOperatorException) { return a ^ Variant(b); }
777  friend Variant operator^(long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) ^ b; }
778  friend Variant operator^(const Variant &a, long long b) throw (UnsupportedOperatorException) { return a ^ Variant(b); }
779 #else
780  friend Variant operator^(unsigned long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) ^ b; }
781  friend Variant operator^(const Variant &a, unsigned long b) throw (UnsupportedOperatorException) { return a ^ Variant(b); }
782  friend Variant operator^(long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) ^ b; }
783  friend Variant operator^(const Variant &a, long b) throw (UnsupportedOperatorException) { return a ^ Variant(b); }
784 #endif
785 
786  friend Variant operator%(const Variant &a, const char *b) throw (UnsupportedOperatorException) { return a % Variant(b, TypeString); }
787  friend Variant operator%(const char *a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a, TypeString) % b; }
788  friend Variant operator%(const Variant &a, const std::string &b) throw (UnsupportedOperatorException) { return a % Variant(b); }
789  friend Variant operator%(const std::string &a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) % b; }
790  friend Variant operator%(const Variant &a, bool b) throw (UnsupportedOperatorException) { return a % Variant(b); }
791  friend Variant operator%(bool a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) % b; }
792  friend Variant operator%(uint8_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) % b; }
793  friend Variant operator%(const Variant &a, uint8_t b) throw (UnsupportedOperatorException) { return a % Variant(b); }
794  friend Variant operator%(uint16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) % b; }
795  friend Variant operator%(const Variant &a, uint16_t b) throw (UnsupportedOperatorException) { return a % Variant(b); }
796  friend Variant operator%(uint32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) % b; }
797  friend Variant operator%(const Variant &a, uint32_t b) throw (UnsupportedOperatorException) { return a % Variant(b); }
798  friend Variant operator%(uint64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) % b; }
799  friend Variant operator%(const Variant &a, uint64_t b) throw (UnsupportedOperatorException) { return a % Variant(b); }
800  friend Variant operator%(int16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) % b; }
801  friend Variant operator%(const Variant &a, int16_t b) throw (UnsupportedOperatorException) { return a % Variant(b); }
802  friend Variant operator%(int32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) % b; }
803  friend Variant operator%(const Variant &a, int32_t b) throw (UnsupportedOperatorException) { return a % Variant(b); }
804  friend Variant operator%(int64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) % b; }
805  friend Variant operator%(const Variant &a, int64_t b) throw (UnsupportedOperatorException) { return a % Variant(b); }
806 #ifdef __LP64__
807  friend Variant operator%(unsigned long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) % b; }
808  friend Variant operator%(const Variant &a, unsigned long long b) throw (UnsupportedOperatorException) { return a % Variant(b); }
809  friend Variant operator%(long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) % b; }
810  friend Variant operator%(const Variant &a, long long b) throw (UnsupportedOperatorException) { return a % Variant(b); }
811 #else
812  friend Variant operator%(unsigned long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) % b; }
813  friend Variant operator%(const Variant &a, unsigned long b) throw (UnsupportedOperatorException) { return a % Variant(b); }
814  friend Variant operator%(long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) % b; }
815  friend Variant operator%(const Variant &a, long b) throw (UnsupportedOperatorException) { return a % Variant(b); }
816 #endif
817 
818  friend Variant operator&(const Variant &a, const char *b) throw (UnsupportedOperatorException) { return a & Variant(b, TypeString); }
819  friend Variant operator&(const char *a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a, TypeString) & b; }
820  friend Variant operator&(const Variant &a, const std::string &b) throw (UnsupportedOperatorException) { return a & Variant(b); }
821  friend Variant operator&(const std::string &a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) & b; }
822  friend Variant operator&(const Variant &a, bool b) throw (UnsupportedOperatorException) { return a & Variant(b); }
823  friend Variant operator&(bool a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) & b; }
824  friend Variant operator&(uint8_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) & b; }
825  friend Variant operator&(const Variant &a, uint8_t b) throw (UnsupportedOperatorException) { return a & Variant(b); }
826  friend Variant operator&(uint16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) & b; }
827  friend Variant operator&(const Variant &a, uint16_t b) throw (UnsupportedOperatorException) { return a & Variant(b); }
828  friend Variant operator&(uint32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) & b; }
829  friend Variant operator&(const Variant &a, uint32_t b) throw (UnsupportedOperatorException) { return a & Variant(b); }
830  friend Variant operator&(uint64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) & b; }
831  friend Variant operator&(const Variant &a, uint64_t b) throw (UnsupportedOperatorException) { return a & Variant(b); }
832  friend Variant operator&(int16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) & b; }
833  friend Variant operator&(const Variant &a, int16_t b) throw (UnsupportedOperatorException) { return a & Variant(b); }
834  friend Variant operator&(int32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) & b; }
835  friend Variant operator&(const Variant &a, int32_t b) throw (UnsupportedOperatorException) { return a & Variant(b); }
836  friend Variant operator&(int64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) & b; }
837  friend Variant operator&(const Variant &a, int64_t b) throw (UnsupportedOperatorException) { return a & Variant(b); }
838 #ifdef __LP64__
839  friend Variant operator&(unsigned long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) & b; }
840  friend Variant operator&(const Variant &a, unsigned long long b) throw (UnsupportedOperatorException) { return a & Variant(b); }
841  friend Variant operator&(long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) & b; }
842  friend Variant operator&(const Variant &a, long long b) throw (UnsupportedOperatorException) { return a & Variant(b); }
843 #else
844  friend Variant operator&(unsigned long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) & b; }
845  friend Variant operator&(const Variant &a, unsigned long b) throw (UnsupportedOperatorException) { return a & Variant(b); }
846  friend Variant operator&(long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) & b; }
847  friend Variant operator&(const Variant &a, long b) throw (UnsupportedOperatorException) { return a & Variant(b); }
848 #endif
849 
850  friend Variant operator|(const Variant &a, const char *b) throw (UnsupportedOperatorException) { return a | Variant(b, TypeString); }
851  friend Variant operator|(const char *a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a, TypeString) | b; }
852  friend Variant operator|(const Variant &a, const std::string &b) throw (UnsupportedOperatorException) { return a | Variant(b); }
853  friend Variant operator|(const std::string &a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) | b; }
854  friend Variant operator|(const Variant &a, bool b) throw (UnsupportedOperatorException) { return a | Variant(b); }
855  friend Variant operator|(bool a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) | b; }
856  friend Variant operator|(uint8_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) | b; }
857  friend Variant operator|(const Variant &a, uint8_t b) throw (UnsupportedOperatorException) { return a | Variant(b); }
858  friend Variant operator|(uint16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) | b; }
859  friend Variant operator|(const Variant &a, uint16_t b) throw (UnsupportedOperatorException) { return a | Variant(b); }
860  friend Variant operator|(uint32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) | b; }
861  friend Variant operator|(const Variant &a, uint32_t b) throw (UnsupportedOperatorException) { return a | Variant(b); }
862  friend Variant operator|(uint64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) | b; }
863  friend Variant operator|(const Variant &a, uint64_t b) throw (UnsupportedOperatorException) { return a | Variant(b); }
864  friend Variant operator|(int16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) | b; }
865  friend Variant operator|(const Variant &a, int16_t b) throw (UnsupportedOperatorException) { return a | Variant(b); }
866  friend Variant operator|(int32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) | b; }
867  friend Variant operator|(const Variant &a, int32_t b) throw (UnsupportedOperatorException) { return a | Variant(b); }
868  friend Variant operator|(int64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) | b; }
869  friend Variant operator|(const Variant &a, int64_t b) throw (UnsupportedOperatorException) { return a | Variant(b); }
870 #ifdef __LP64__
871  friend Variant operator|(unsigned long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) | b; }
872  friend Variant operator|(const Variant &a, unsigned long long b) throw (UnsupportedOperatorException) { return a | Variant(b); }
873  friend Variant operator|(long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) | b; }
874  friend Variant operator|(const Variant &a, long long b) throw (UnsupportedOperatorException) { return a | Variant(b); }
875 #else
876  friend Variant operator|(unsigned long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) | b; }
877  friend Variant operator|(const Variant &a, unsigned long b) throw (UnsupportedOperatorException) { return a | Variant(b); }
878  friend Variant operator|(long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) | b; }
879  friend Variant operator|(const Variant &a, long b) throw (UnsupportedOperatorException) { return a | Variant(b); }
880 #endif
881 
882  friend Variant operator>>(const Variant &a, const char *b) throw (UnsupportedOperatorException) { return a >> Variant(b, TypeString); }
883  friend Variant operator>>(const char *a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a, TypeString) >> b; }
884  friend Variant operator>>(const Variant &a, const std::string &b) throw (UnsupportedOperatorException) { return a >> Variant(b); }
885  friend Variant operator>>(const std::string &a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >> b; }
886  friend Variant operator>>(const Variant &a, bool b) throw (UnsupportedOperatorException) { return a >> Variant(b); }
887  friend Variant operator>>(bool a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >> b; }
888  friend Variant operator>>(uint8_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >> b; }
889  friend Variant operator>>(const Variant &a, uint8_t b) throw (UnsupportedOperatorException) { return a >> Variant(b); }
890  friend Variant operator>>(uint16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >> b; }
891  friend Variant operator>>(const Variant &a, uint16_t b) throw (UnsupportedOperatorException) { return a >> Variant(b); }
892  friend Variant operator>>(uint32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >> b; }
893  friend Variant operator>>(const Variant &a, uint32_t b) throw (UnsupportedOperatorException) { return a >> Variant(b); }
894  friend Variant operator>>(uint64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >> b; }
895  friend Variant operator>>(const Variant &a, uint64_t b) throw (UnsupportedOperatorException) { return a >> Variant(b); }
896  friend Variant operator>>(int16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >> b; }
897  friend Variant operator>>(const Variant &a, int16_t b) throw (UnsupportedOperatorException) { return a >> Variant(b); }
898  friend Variant operator>>(int32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >> b; }
899  friend Variant operator>>(const Variant &a, int32_t b) throw (UnsupportedOperatorException) { return a >> Variant(b); }
900  friend Variant operator>>(int64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >> b; }
901  friend Variant operator>>(const Variant &a, int64_t b) throw (UnsupportedOperatorException) { return a >> Variant(b); }
902 #ifdef __LP64__
903  friend Variant operator>>(unsigned long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >> b; }
904  friend Variant operator>>(const Variant &a, unsigned long long b) throw (UnsupportedOperatorException) { return a >> Variant(b); }
905  friend Variant operator>>(long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >> b; }
906  friend Variant operator>>(const Variant &a, long long b) throw (UnsupportedOperatorException) { return a >> Variant(b); }
907 #else
908  friend Variant operator>>(unsigned long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >> b; }
909  friend Variant operator>>(const Variant &a, unsigned long b) throw (UnsupportedOperatorException) { return a >> Variant(b); }
910  friend Variant operator>>(long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) >> b; }
911  friend Variant operator>>(const Variant &a, long b) throw (UnsupportedOperatorException) { return a >> Variant(b); }
912 #endif
913 
914  friend Variant operator<<(const Variant &a, const char *b) throw (UnsupportedOperatorException) { return a << Variant(b, TypeString); }
915  friend Variant operator<<(const char *a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a, TypeString) << b; }
916  friend Variant operator<<(const Variant &a, const std::string &b) throw (UnsupportedOperatorException) { return a << Variant(b); }
917  friend Variant operator<<(const std::string &a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) << b; }
918  friend Variant operator<<(const Variant &a, bool b) throw (UnsupportedOperatorException) { return a << Variant(b); }
919  friend Variant operator<<(bool a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) << b; }
920  friend Variant operator<<(uint8_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) << b; }
921  friend Variant operator<<(const Variant &a, uint8_t b) throw (UnsupportedOperatorException) { return a << Variant(b); }
922  friend Variant operator<<(uint16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) << b; }
923  friend Variant operator<<(const Variant &a, uint16_t b) throw (UnsupportedOperatorException) { return a << Variant(b); }
924  friend Variant operator<<(uint32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) << b; }
925  friend Variant operator<<(const Variant &a, uint32_t b) throw (UnsupportedOperatorException) { return a << Variant(b); }
926  friend Variant operator<<(uint64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) << b; }
927  friend Variant operator<<(const Variant &a, uint64_t b) throw (UnsupportedOperatorException) { return a << Variant(b); }
928  friend Variant operator<<(int16_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) << b; }
929  friend Variant operator<<(const Variant &a, int16_t b) throw (UnsupportedOperatorException) { return a << Variant(b); }
930  friend Variant operator<<(int32_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) << b; }
931  friend Variant operator<<(const Variant &a, int32_t b) throw (UnsupportedOperatorException) { return a << Variant(b); }
932  friend Variant operator<<(int64_t a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) << b; }
933  friend Variant operator<<(const Variant &a, int64_t b) throw (UnsupportedOperatorException) { return a << Variant(b); }
934 #ifdef __LP64__
935  friend Variant operator<<(unsigned long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) << b; }
936  friend Variant operator<<(const Variant &a, unsigned long long b) throw (UnsupportedOperatorException) { return a << Variant(b); }
937  friend Variant operator<<(long long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) << b; }
938  friend Variant operator<<(const Variant &a, long long b) throw (UnsupportedOperatorException) { return a << Variant(b); }
939 #else
940  friend Variant operator<<(unsigned long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) << b; }
941  friend Variant operator<<(const Variant &a, unsigned long b) throw (UnsupportedOperatorException) { return a << Variant(b); }
942  friend Variant operator<<(long a, const Variant &b) throw (UnsupportedOperatorException) { return Variant(a) << b; }
943  friend Variant operator<<(const Variant &a, long b) throw (UnsupportedOperatorException) { return a << Variant(b); }
944 #endif
945 
946  friend std::istream& operator>>(std::istream &is, Variant &value) throw (TypeCastException);
947  friend std::ostream& operator<<(std::ostream &os, const Variant &value) throw (TypeCastException);
948 
949  private:
950  std::shared_ptr<Nullable> value;
951  int type;
952  mutable std::string cache;
953 
954  std::shared_ptr<Null>& null(void) const {
955  static std::shared_ptr<Null> n = std::make_shared<Null>();
956 
957  return n;
958  }
959 };
960 
961 namespace sella {
962  namespace variant {
963  template <> inline const char* Variant::cast<const char*>() const throw (TypeCastException) {
964  if (this->type != TypeString) {
965  return c_str();
966  }
967 
968  return this->get<sella::variant::String>().get().c_str();
969  }
970 
971  template <> inline const std::string& Variant::cast<const std::string&>() const throw (TypeCastException) {
972  if (this->type != TypeString) {
973  return str();
974  }
975 
976  return this->get<sella::variant::String>().get();
977  }
978 
979  template <> inline std::string Variant::cast<std::string>() throw (TypeCastException) {
980  return str();
981  }
982 
983  template <> inline const sella::util::UUID& Variant::cast<const sella::util::UUID&>() const throw (TypeCastException) {
984  if (this->type != TypeUUID) {
985  THROW(TypeCastException, "unable to cast from %s to a UUID", getTypeName());
986  }
987 
988  return this->get<sella::variant::UUID>().get();
989  }
990 
991  template <> inline sella::util::UUID& Variant::cast<sella::util::UUID&>() throw (TypeCastException) {
992  if (this->type != TypeUUID) {
993  THROW(TypeCastException, "unable to cast from %s to a UUID", getTypeName());
994  }
995 
996  return this->get<sella::variant::UUID>().get();
997  }
998 
999  template <> inline const sella::net::IPAddress Variant::cast<const sella::net::IPAddress>() const throw (TypeCastException) {
1000  switch (this->type) {
1001  case TypeIPAddress:
1002  return this->get<sella::variant::IPAddress>().get();
1003 
1004  case TypeIPPrefix:
1005  return this->get<sella::variant::IPPrefix>().get().getIPAddress();
1006 
1007  case TypeString:
1008  try {
1009  return sella::net::IPAddress(str());
1010  } catch (Exception &e) {
1011  THROW(TypeCastException, "unable to cast from %s to a IPAddress value (%s)", getTypeName(), e.what());
1012  }
1013 
1014  default:
1015  THROW(TypeCastException, "unable to cast from %s to IPAddress", getTypeName());
1016  }
1017  }
1018 
1019  template <> inline sella::net::IPAddress Variant::cast<sella::net::IPAddress>() throw (TypeCastException) {
1020  switch (this->type) {
1021  case TypeIPAddress:
1022  return this->get<sella::variant::IPAddress>().get();
1023 
1024  case TypeIPPrefix:
1025  return this->get<sella::variant::IPPrefix>().get().getIPAddress();
1026 
1027  case TypeString:
1028  try {
1029  return sella::net::IPAddress(str());
1030  } catch (Exception &e) {
1031  THROW(TypeCastException, "unable to cast from %s to a IPAddress value (%s)", getTypeName(), e.what());
1032  }
1033 
1034  default:
1035  THROW(TypeCastException, "unable to cast from %s to IPAddress", getTypeName());
1036  }
1037  }
1038 
1039  template <> inline const sella::net::IPAddress& Variant::cast<const sella::net::IPAddress&>() const throw (TypeCastException) {
1040  switch (this->type) {
1041  case TypeIPAddress:
1042  return this->get<sella::variant::IPAddress>().get();
1043 
1044  case TypeIPPrefix:
1045  return this->get<sella::variant::IPPrefix>().get().getIPAddress();
1046 
1047  default:
1048  THROW(TypeCastException, "unable to cast from %s to IPAddress", getTypeName());
1049  }
1050  }
1051 
1052  template <> inline sella::net::IPAddress& Variant::cast<sella::net::IPAddress&>() throw (TypeCastException) {
1053  switch (this->type) {
1054  case TypeIPAddress:
1055  return this->get<sella::variant::IPAddress>().get();
1056 
1057  case TypeIPPrefix:
1058  return this->get<sella::variant::IPPrefix>().get().getIPAddress();
1059 
1060  default:
1061  THROW(TypeCastException, "unable to cast from %s to IPAddress", getTypeName());
1062  }
1063  }
1064 
1065  template <> inline sella::net::IPPrefix Variant::cast<sella::net::IPPrefix>() const throw (TypeCastException) {
1066  switch (this->type) {
1067  case TypeIPPrefix:
1068  return this->get<sella::variant::IPPrefix>().get();
1069 
1070  case TypeIPAddress:
1071  return this->get<sella::variant::IPPrefix>().get().getIPAddress();
1072 
1073 
1074  case TypeString:
1075  try {
1076  return sella::net::IPPrefix(str());
1077  } catch (Exception &e) {
1078  THROW(TypeCastException, "unable to cast from %s to a IPPrefix value (%s)", getTypeName(), e.what());
1079  }
1080 
1081  default:
1082  THROW(TypeCastException, "unable to cast from %s to IPPrefix", getTypeName());
1083  }
1084  }
1085 
1086  template <> inline sella::net::IPPrefix Variant::cast<sella::net::IPPrefix>() throw (TypeCastException) {
1087  switch (this->type) {
1088  case TypeIPPrefix:
1089  return this->get<sella::variant::IPPrefix>().get();
1090 
1091  case TypeIPAddress:
1092  return this->get<sella::variant::IPPrefix>().get().getIPAddress();
1093 
1094  case TypeString:
1095  try {
1096  return sella::net::IPPrefix(str());
1097  } catch (Exception &e) {
1098  THROW(TypeCastException, "unable to cast from %s to a IPPrefix value (%s)", getTypeName(), e.what());
1099  }
1100 
1101  default:
1102  THROW(TypeCastException, "unable to cast from %s to IPPrefix", getTypeName());
1103  }
1104  }
1105 
1106  template <> inline const sella::net::IPPrefix& Variant::cast<const sella::net::IPPrefix&>() const throw (TypeCastException) {
1107  if (this->type != TypeIPPrefix) {
1108  THROW(TypeCastException, "unable to cast from %s to IPPrefix", getTypeName());
1109  }
1110 
1111  return this->get<sella::variant::IPPrefix>().get();
1112  }
1113 
1114  template <> inline sella::net::IPPrefix& Variant::cast<sella::net::IPPrefix&>() throw (TypeCastException) {
1115  if (this->type != TypeIPPrefix) {
1116  THROW(TypeCastException, "unable to cast from %s to IPPrefix", getTypeName());
1117  }
1118 
1119  return this->get<sella::variant::IPPrefix>().get();
1120  }
1121 
1122  template <> inline const std::vector<Variant>& Variant::cast<const std::vector<Variant>&>() const throw (TypeCastException) {
1123  if (this->type != TypeVector) {
1124  THROW(TypeCastException, "unable to cast from %s to std::vector<Variant>", getTypeName());
1125  }
1126 
1127  return this->get<Vector>().get();
1128  }
1129 
1130  template <> inline std::vector<Variant>& Variant::cast<std::vector<Variant>&>() throw (TypeCastException) {
1131  if (this->type != TypeVector) {
1132  THROW(TypeCastException, "unable to cast from %s to std::vector<Variant>", getTypeName());
1133  }
1134 
1135  return this->get<Vector>().get();
1136  }
1137 
1138  template <> inline const std::map<std::string, Variant>& Variant::cast<const std::map<std::string, Variant>&>() const throw (TypeCastException) {
1139  if (this->type != TypeObject) {
1140  THROW(TypeCastException, "unable to cast from %s to std::map<std::string, Variant>", getTypeName());
1141  }
1142 
1143  return this->get<Object>().get();
1144  }
1145 
1146  template <> inline std::map<std::string, Variant>& Variant::cast<std::map<std::string, Variant>&>() throw (TypeCastException) {
1147  if (this->type != TypeObject) {
1148  THROW(TypeCastException, "unable to cast from %s to std::map<std::string, Variant>", getTypeName());
1149  }
1150 
1151  return this->get<Object>().get();
1152  }
1153 
1154  template <> inline bool Variant::cast<bool>() const throw (TypeCastException) {
1155  if (!this->value->isNull()) {
1156  switch (this->type) {
1157  case TypeBoolean:
1158  return this->get<sella::variant::Boolean>().get();
1159 
1160  case TypeSigned:
1161  return static_cast<bool>(this->get<sella::variant::Signed>().get());
1162 
1163  case TypeUnsigned:
1164  return static_cast<bool>(this->get<sella::variant::Unsigned>().get());
1165 
1166  case TypeDouble:
1167  return static_cast<bool>(this->get<sella::variant::Double>().get());
1168 
1169  case TypeString:
1170  if (boost::regex_match(this->get<sella::variant::String>().get(), Boolean::Pattern())) {
1171  return (tolower(this->get<sella::variant::String>().get()[0]) == 't');
1172  }
1173  THROW(TypeCastException, "unable to cast from %s to a boolean value (invalid string)", getTypeName());
1174 
1175  case TypeInterval:
1176  return static_cast<bool>(this->get<sella::variant::Interval>().getUsec());
1177 
1178  case TypeTime:
1179  return static_cast<bool>(this->get<sella::variant::Time>().getUsec());
1180 
1181  case TypeDate:
1182  return static_cast<bool>(this->get<sella::variant::Date>().getUsec());
1183 
1184  case TypeTimeStamp:
1185  return static_cast<bool>(this->get<sella::variant::TimeStamp>().getUsec());
1186 
1187  case TypeVector:
1188  return this->get<sella::variant::Vector>().empty();
1189 
1190  case TypeObject:
1191  return this->get<sella::variant::Object>().empty();
1192 
1193  case TypeBinary:
1194  return this->get<sella::variant::Binary>().empty();
1195 
1196  default:
1197  THROW(TypeCastException, "unable to cast from %s to bool", getTypeName());
1198  }
1199  }
1200 
1201  return false;
1202  }
1203 
1204  template <> inline bool Variant::cast<bool>() throw (TypeCastException) {
1205  if (!this->value->isNull()) {
1206  switch (this->type) {
1207  case TypeBoolean:
1208  return this->get<sella::variant::Boolean>().get();
1209 
1210  case TypeSigned:
1211  return static_cast<bool>(this->get<sella::variant::Signed>().get());
1212 
1213  case TypeUnsigned:
1214  return static_cast<bool>(this->get<sella::variant::Unsigned>().get());
1215 
1216  case TypeDouble:
1217  return static_cast<bool>(this->get<sella::variant::Double>().get());
1218 
1219  case TypeString:
1220  if (boost::regex_match(this->get<sella::variant::String>().get(), Boolean::Pattern())) {
1221  return (tolower(this->get<sella::variant::String>().get()[0]) == 't');
1222  }
1223  THROW(TypeCastException, "unable to cast from %s to a boolean value (invalid string)", getTypeName());
1224 
1225  case TypeInterval:
1226  return static_cast<bool>(this->get<sella::variant::Interval>().getUsec());
1227 
1228  case TypeTime:
1229  return static_cast<bool>(this->get<sella::variant::Time>().getUsec());
1230 
1231  case TypeDate:
1232  return static_cast<bool>(this->get<sella::variant::Date>().getUsec());
1233 
1234  case TypeTimeStamp:
1235  return static_cast<bool>(this->get<sella::variant::TimeStamp>().getUsec());
1236 
1237  case TypeVector:
1238  return this->get<sella::variant::Vector>().empty();
1239 
1240  case TypeObject:
1241  return this->get<sella::variant::Object>().empty();
1242 
1243  case TypeBinary:
1244  return this->get<sella::variant::Binary>().empty();
1245 
1246  default:
1247  THROW(TypeCastException, "unable to cast from %s to bool", getTypeName());
1248  }
1249  }
1250 
1251  return false;
1252  }
1253 
1254  template <> inline uint64_t Variant::cast<uint64_t>() const throw (TypeCastException) {
1255  if (!this->value->isNull()) {
1256  switch (this->type) {
1257  case TypeBoolean:
1258  return (this->get<sella::variant::Boolean>().get()) ? 1 : 0;
1259 
1260  case TypeSigned:
1261  if (this->get<sella::variant::Signed>().get() >= 0) {
1262  return static_cast<uint64_t>(this->get<sella::variant::Signed>().get());
1263  }
1264  THROW(TypeCastException, "unable to cast from %s to an unsigned value (value is negative)", getTypeName());
1265 
1266  case TypeUnsigned:
1267  return this->get<sella::variant::Unsigned>().get();
1268 
1269  case TypeDouble:
1270  if (this->get<sella::variant::Double>().get() >= 0) {
1271  if (this->get<sella::variant::Double>().get() <= std::numeric_limits<uint64_t>::max()) {
1272  return static_cast<uint64_t>(this->get<sella::variant::Double>().get());
1273  }
1274  THROW(TypeCastException, "unable to cast from %s to an unsigned value (value too large)", getTypeName());
1275  }
1276  THROW(TypeCastException, "unable to cast from %s to an unsigned value (value is negative)", getTypeName());
1277 
1278  case TypeString:
1279  try {
1280  return std::stoull(this->get<sella::variant::String>().get());
1281  } catch (std::invalid_argument &e) {
1282  THROW(TypeCastException, "unable to cast from %s to a signed value (invalid string)", getTypeName());
1283  } catch (std::out_of_range &e) {
1284  THROW(TypeCastException, "unable to cast from %s to a signed value (overflow/underflow)", getTypeName());
1285  }
1286 
1287  case TypeInterval:
1288  if (this->get<sella::variant::Interval>().getUsec() >= 0) {
1289  return this->get<sella::variant::Interval>().getUsec();
1290  }
1291  THROW(TypeCastException, "unable to cast from %s to an unsigned value (value is negative)", getTypeName());
1292 
1293  case TypeTime:
1294  if (this->get<sella::variant::Time>().getUsec() >= 0) {
1295  return this->get<sella::variant::Time>().getUsec();
1296  }
1297  THROW(TypeCastException, "unable to cast from %s to an unsigned value (value is negative)", getTypeName());
1298 
1299  case TypeDate:
1300  if (this->get<sella::variant::Date>().getUsec() >= 0) {
1301  return this->get<sella::variant::Date>().getUsec();
1302  }
1303  THROW(TypeCastException, "unable to cast from %s to an unsigned value (value is negative)", getTypeName());
1304 
1305  case TypeTimeStamp:
1306  if (this->get<sella::variant::TimeStamp>().getUsec() >= 0) {
1307  return this->get<sella::variant::TimeStamp>().getUsec();
1308  }
1309  THROW(TypeCastException, "unable to cast from %s to an unsigned value (value is negative)", getTypeName());
1310 
1311  case TypeVector:
1312  case TypeObject:
1313  case TypeBinary:
1314  default:
1315  THROW(TypeCastException, "unable to cast from %s to uint64_t", getTypeName());
1316  }
1317  }
1318 
1319  return 0;
1320  }
1321 
1322  template <> inline uint64_t Variant::cast<uint64_t>() throw (TypeCastException) {
1323  if (!this->value->isNull()) {
1324  switch (this->type) {
1325  case TypeBoolean:
1326  return (this->get<sella::variant::Boolean>().get()) ? 1 : 0;
1327 
1328  case TypeSigned:
1329  if (this->get<sella::variant::Signed>().get() >= 0) {
1330  return static_cast<uint64_t>(this->get<sella::variant::Signed>().get());
1331  }
1332  THROW(TypeCastException, "unable to cast from %s to an unsigned value (value is negative)", getTypeName());
1333 
1334  case TypeUnsigned:
1335  return this->get<sella::variant::Unsigned>().get();
1336 
1337  case TypeDouble:
1338  if (this->get<sella::variant::Double>().get() >= 0) {
1339  if (this->get<sella::variant::Double>().get() <= std::numeric_limits<uint64_t>::max()) {
1340  return static_cast<uint64_t>(this->get<sella::variant::Double>().get());
1341  }
1342  THROW(TypeCastException, "unable to cast from %s to an unsigned value (value too large)", getTypeName());
1343  }
1344  THROW(TypeCastException, "unable to cast from %s to an unsigned value (value is negative)", getTypeName());
1345 
1346  case TypeString:
1347  try {
1348  return std::stoull(this->get<sella::variant::String>().get());
1349  } catch (std::invalid_argument &e) {
1350  THROW(TypeCastException, "unable to cast from %s to a signed value (invalid string)", getTypeName());
1351  } catch (std::out_of_range &e) {
1352  THROW(TypeCastException, "unable to cast from %s to a signed value (overflow/underflow)", getTypeName());
1353  }
1354 
1355  case TypeInterval:
1356  if (this->get<sella::variant::Interval>().getUsec() >= 0) {
1357  return this->get<sella::variant::Interval>().getUsec();
1358  }
1359  THROW(TypeCastException, "unable to cast from %s to an unsigned value (value is negative)", getTypeName());
1360 
1361  case TypeTime:
1362  if (this->get<sella::variant::Time>().getUsec() >= 0) {
1363  return this->get<sella::variant::Time>().getUsec();
1364  }
1365  THROW(TypeCastException, "unable to cast from %s to an unsigned value (value is negative)", getTypeName());
1366 
1367  case TypeDate:
1368  if (this->get<sella::variant::Date>().getUsec() >= 0) {
1369  return this->get<sella::variant::Date>().getUsec();
1370  }
1371  THROW(TypeCastException, "unable to cast from %s to an unsigned value (value is negative)", getTypeName());
1372 
1373  case TypeTimeStamp:
1374  if (this->get<sella::variant::TimeStamp>().getUsec() >= 0) {
1375  return this->get<sella::variant::TimeStamp>().getUsec();
1376  }
1377  THROW(TypeCastException, "unable to cast from %s to an unsigned value (value is negative)", getTypeName());
1378 
1379  case TypeVector:
1380  case TypeObject:
1381  case TypeBinary:
1382  default:
1383  THROW(TypeCastException, "unable to cast from %s to uint64_t", getTypeName());
1384  }
1385  }
1386 
1387  return 0;
1388  }
1389 
1390  template <> inline uint32_t Variant::cast<uint32_t>() const throw (TypeCastException) {
1391  return (uint32_t) this->cast<uint64_t>();
1392  }
1393 
1394  template <> inline uint32_t Variant::cast<uint32_t>() throw (TypeCastException) {
1395  return (uint32_t) this->cast<uint64_t>();
1396  }
1397 
1398  template <> inline uint16_t Variant::cast<uint16_t>() const throw (TypeCastException) {
1399  return (uint16_t) this->cast<uint64_t>();
1400  }
1401 
1402  template <> inline uint16_t Variant::cast<uint16_t>() throw (TypeCastException) {
1403  return (uint16_t) this->cast<uint64_t>();
1404  }
1405 
1406  template <> inline uint8_t Variant::cast<uint8_t>() const throw (TypeCastException) {
1407  return (uint8_t) this->cast<uint64_t>();
1408  }
1409 
1410  template <> inline uint8_t Variant::cast<uint8_t>() throw (TypeCastException) {
1411  return (uint8_t) this->cast<uint64_t>();
1412  }
1413 
1414  template <> inline int64_t Variant::cast<int64_t>() const throw (TypeCastException) {
1415  if (!this->value->isNull()) {
1416  switch (this->type) {
1417  case TypeBoolean:
1418  return (this->get<sella::variant::Boolean>().get()) ? 1 : 0;
1419 
1420  case TypeSigned:
1421  return this->get<sella::variant::Signed>().get();
1422 
1423  case TypeUnsigned:
1424  if (this->get<sella::variant::Unsigned>().get() <= static_cast<uint64_t>(std::numeric_limits<int64_t>::max())) {
1425  return static_cast<int64_t>(this->get<sella::variant::Unsigned>().get());
1426  }
1427  THROW(TypeCastException, "unable to cast from %s to a signed value (value too large)", getTypeName());
1428 
1429  case TypeDouble:
1430  if (this->get<sella::variant::Double>().get() < static_cast<double>(std::numeric_limits<int64_t>::max())) {
1431  return static_cast<int64_t>(this->get<sella::variant::Double>().get());
1432  }
1433  THROW(TypeCastException, "unable to cast from %s to a signed value (value too large)", getTypeName());
1434 
1435  case TypeString:
1436  try {
1437  return std::stoll(this->get<sella::variant::String>().get());
1438  } catch (std::invalid_argument &e) {
1439  THROW(TypeCastException, "unable to cast from %s to a signed value (invalid string)", getTypeName());
1440  } catch (std::out_of_range &e) {
1441  THROW(TypeCastException, "unable to cast from %s to a signed value (overflow/underflow)", getTypeName());
1442  }
1443 
1444  case TypeInterval:
1445  return this->get<sella::variant::Interval>().getUsec();
1446 
1447  case TypeTime:
1448  return this->get<sella::variant::Time>().getUsec();
1449 
1450  case TypeDate:
1451  return this->get<sella::variant::Date>().getUsec();
1452 
1453  case TypeTimeStamp:
1454  return this->get<sella::variant::TimeStamp>().getUsec();
1455 
1456  case TypeVector:
1457  case TypeObject:
1458  case TypeBinary:
1459  default:
1460  THROW(TypeCastException, "unable to cast from %s to int64_t", getTypeName());
1461  }
1462  }
1463 
1464  return 0;
1465  }
1466 
1467  template <> inline int64_t Variant::cast<int64_t>() throw (TypeCastException) {
1468  if (!this->value->isNull()) {
1469  switch (this->type) {
1470  case TypeBoolean:
1471  return (this->get<sella::variant::Boolean>().get()) ? 1 : 0;
1472 
1473  case TypeSigned:
1474  return this->get<sella::variant::Signed>().get();
1475 
1476  case TypeUnsigned:
1477  if (this->get<sella::variant::Unsigned>().get() <= static_cast<uint64_t>(std::numeric_limits<int64_t>::max())) {
1478  return static_cast<int64_t>(this->get<sella::variant::Unsigned>().get());
1479  }
1480  THROW(TypeCastException, "unable to cast from %s to a signed value (value too large)", getTypeName());
1481 
1482  case TypeDouble:
1483  if (this->get<sella::variant::Double>().get() < static_cast<double>(std::numeric_limits<int64_t>::max())) {
1484  return static_cast<int64_t>(this->get<sella::variant::Double>().get());
1485  }
1486  THROW(TypeCastException, "unable to cast from %s to a signed value (value too large)", getTypeName());
1487 
1488  case TypeString:
1489  try {
1490  return std::stoll(this->get<sella::variant::String>().get());
1491  } catch (std::invalid_argument &e) {
1492  THROW(TypeCastException, "unable to cast from %s to a signed value (invalid string)", getTypeName());
1493  } catch (std::out_of_range &e) {
1494  THROW(TypeCastException, "unable to cast from %s to a signed value (overflow/underflow)", getTypeName());
1495  }
1496 
1497  case TypeInterval:
1498  return this->get<sella::variant::Interval>().getUsec();
1499 
1500  case TypeTime:
1501  return this->get<sella::variant::Time>().getUsec();
1502 
1503  case TypeDate:
1504  return this->get<sella::variant::Date>().getUsec();
1505 
1506  case TypeTimeStamp:
1507  return this->get<sella::variant::TimeStamp>().getUsec();
1508 
1509  case TypeVector:
1510  case TypeObject:
1511  case TypeBinary:
1512  default:
1513  THROW(TypeCastException, "unable to cast from %s to int64_t", getTypeName());
1514  }
1515  }
1516 
1517  return 0;
1518  }
1519 
1520  template <> inline int32_t Variant::cast<int32_t>() const throw (TypeCastException) {
1521  return (int32_t) this->cast<int64_t>();
1522  }
1523 
1524  template <> inline int32_t Variant::cast<int32_t>() throw (TypeCastException) {
1525  return (int32_t) this->cast<int64_t>();
1526  }
1527 
1528  template <> inline int16_t Variant::cast<int16_t>() const throw (TypeCastException) {
1529  return (int16_t) this->cast<int64_t>();
1530  }
1531 
1532  template <> inline int16_t Variant::cast<int16_t>() throw (TypeCastException) {
1533  return (int16_t) this->cast<int64_t>();
1534  }
1535 
1536  template <> inline int8_t Variant::cast<int8_t>() const throw (TypeCastException) {
1537  return (int8_t) this->cast<int64_t>();
1538  }
1539 
1540  template <> inline int8_t Variant::cast<int8_t>() throw (TypeCastException) {
1541  return (int8_t) this->cast<int64_t>();
1542  }
1543 
1544  template <> inline double Variant::cast<double>() const throw (TypeCastException) {
1545  if (!this->value->isNull()) {
1546  switch (this->type) {
1547  case TypeBoolean:
1548  return (this->get<sella::variant::Boolean>().get()) ? 1.0F : 0.0F;
1549 
1550  case TypeSigned:
1551  return static_cast<double>(this->get<sella::variant::Signed>().get());
1552 
1553  case TypeUnsigned:
1554  return static_cast<double>(this->get<sella::variant::Unsigned>().get());
1555 
1556  case TypeDouble:
1557  return this->get<sella::variant::Double>().get();
1558 
1559  case TypeString:
1560  try {
1561  return std::stod(this->get<sella::variant::String>().get());
1562  } catch (std::invalid_argument &e) {
1563  THROW(TypeCastException, "unable to cast from %s to a decimal value (invalid string)", getTypeName());
1564  } catch (std::out_of_range &e) {
1565  THROW(TypeCastException, "unable to cast from %s to a decimal value (overflow/underflow)", getTypeName());
1566  }
1567 
1568  case TypeInterval:
1569  return static_cast<double>(this->get<sella::variant::Interval>().getUsec());
1570 
1571  case TypeTime:
1572  return static_cast<double>(this->get<sella::variant::Time>().getUsec());
1573 
1574  case TypeDate:
1575  return static_cast<double>(this->get<sella::variant::Date>().getUsec());
1576 
1577  case TypeTimeStamp:
1578  return static_cast<double>(this->get<sella::variant::TimeStamp>().getUsec());
1579 
1580  case TypeVector:
1581  case TypeObject:
1582  case TypeBinary:
1583  default:
1584  THROW(TypeCastException, "unable to cast from %s to double", getTypeName());
1585  }
1586  }
1587 
1588  return 0.0F;
1589  }
1590 
1591  template <> inline double Variant::cast<double>() throw (TypeCastException) {
1592  if (!this->value->isNull()) {
1593  switch (this->type) {
1594  case TypeBoolean:
1595  return (this->get<sella::variant::Boolean>().get()) ? 1.0F : 0.0F;
1596 
1597  case TypeSigned:
1598  return static_cast<double>(this->get<sella::variant::Signed>().get());
1599 
1600  case TypeUnsigned:
1601  return static_cast<double>(this->get<sella::variant::Unsigned>().get());
1602 
1603  case TypeDouble:
1604  return this->get<sella::variant::Double>().get();
1605 
1606  case TypeString:
1607  try {
1608  return std::stod(this->get<sella::variant::String>().get());
1609  } catch (std::invalid_argument &e) {
1610  THROW(TypeCastException, "unable to cast from %s to a decimal value (invalid string)", getTypeName());
1611  } catch (std::out_of_range &e) {
1612  THROW(TypeCastException, "unable to cast from %s to a decimal value (overflow/underflow)", getTypeName());
1613  }
1614 
1615  case TypeInterval:
1616  return static_cast<double>(this->get<sella::variant::Interval>().getUsec());
1617 
1618  case TypeTime:
1619  return static_cast<double>(this->get<sella::variant::Time>().getUsec());
1620 
1621  case TypeDate:
1622  return static_cast<double>(this->get<sella::variant::Date>().getUsec());
1623 
1624  case TypeTimeStamp:
1625  return static_cast<double>(this->get<sella::variant::TimeStamp>().getUsec());
1626 
1627  case TypeVector:
1628  case TypeObject:
1629  case TypeBinary:
1630  default:
1631  THROW(TypeCastException, "unable to cast from %s to double", getTypeName());
1632  }
1633  }
1634 
1635  return 0.0F;
1636  }
1637 
1638  template <> inline float Variant::cast<float>() const throw (TypeCastException) {
1639  return (float) this->cast<double>();
1640  }
1641 
1642  template <> inline float Variant::cast<float>() throw (TypeCastException) {
1643  return (float) this->cast<double>();
1644  }
1645 
1646 #ifdef __LP64__
1647  template <> inline unsigned long long Variant::cast<unsigned long long>() const throw (TypeCastException) {
1648  return (unsigned long long) this->cast<uint64_t>();
1649  }
1650 
1651  template <> inline unsigned long long Variant::cast<unsigned long long>() throw (TypeCastException) {
1652  return (unsigned long long) this->cast<uint64_t>();
1653  }
1654 
1655  template <> inline long long Variant::cast<long long>() const throw (TypeCastException) {
1656  return (long long) this->cast<int64_t>();
1657  }
1658 
1659  template <> inline long long Variant::cast<long long>() throw (TypeCastException) {
1660  return (long long) this->cast<int64_t>();
1661  }
1662 #else
1663  template <> inline unsigned long Variant::cast<unsigned long>() const throw (TypeCastException) {
1664  return (unsigned long) this->cast<uint64_t>();
1665  }
1666 
1667  template <> inline unsigned long Variant::cast<unsigned long>() throw (TypeCastException) {
1668  return (unsigned long) this->cast<uint64_t>();
1669  }
1670 
1671  template <> inline long Variant::cast<long>() const throw (TypeCastException) {
1672  return (long) this->cast<int64_t>();
1673  }
1674 
1675  template <> inline long Variant::cast<long>() throw (TypeCastException) {
1676  return (long) this->cast<int64_t>();
1677  }
1678 #endif
1679  }
1680 }
1681 
1682 class sella::variant::Variant_iterator : public boost::iterator_facade<Variant_iterator, Variant, boost::forward_traversal_tag> {
1683  public:
1684  Variant_iterator() : it() { }
1685  Variant_iterator(const Variant_iterator &other) : it(other.it) { }
1686  Variant_iterator(const Variant_iterator &&other) : it(other.it) { }
1687  Variant_iterator(iterator_t it) : it(it) { }
1688 
1689  const std::string& key() const {
1690  static const std::string empty;
1691  if (it.type == Variant::IterObject) {
1692  return it.oit->first;
1693  }
1694  return empty;
1695  }
1696 
1697  Variant& value() const { /* Alias for dereferencing iterator */
1698  return dereference();
1699  }
1700 
1701  private:
1702  friend class boost::iterator_core_access;
1703 
1704  void increment() {
1705  if (it.type == Variant::IterObject) {
1706  ++it.oit;
1707  } else if (it.type == Variant::IterVector) {
1708  ++it.vit;
1709  } else {
1710  it.v = NULL;
1711  }
1712  }
1713 
1714  bool equal(Variant_iterator const &other) const {
1715  if (it.type != other.it.type) {
1716  return false;
1717  } else if (it.type == Variant::IterObject) {
1718  return it.oit == other.it.oit;
1719  } else if (it.type == Variant::IterVector) {
1720  return it.vit == other.it.vit;
1721  }
1722 
1723  return it.v == other.it.v;
1724  }
1725 
1726  Variant& dereference() const {
1727  if (it.type == Variant::IterObject) {
1728  return it.oit->second;
1729  } else if (it.type == Variant::IterVector) {
1730  return *it.vit;
1731  }
1732 
1733  return *it.v;
1734  }
1735 
1736  iterator_t it;
1737 };
1738 
1739 #endif
1740 
1741 /*
1742 ** vim: noet ts=3 sw=3
1743 */