libutil++  1.9.3
 All Classes Functions Variables
Object.h
1 /*
2 ** libutil++
3 ** $Id: Object.h 1702 2016-08-13 23:26:06Z 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__Object_H__
10 #define __libutilxx__sella__variant__Object_H__
11 
12 #include "../../common.h"
13 #include "TypeCastException.h"
14 #include "Nullable.h"
15 
16 #include <memory>
17 
18 #include <boost/regex.hpp>
19 
20 namespace sella {
21  namespace variant {
22  class Object;
23  class Variant;
24  }
25 }
26 
28  public:
29  typedef std::map<std::string, Variant>::iterator iterator;
30  typedef std::map<std::string, Variant>::const_iterator const_iterator;
31 
32  static const boost::regex & Pattern(void) { static boost::regex regex("^\\{(.*)\\}$"); return regex; }
33  static const boost::regex NodePattern;
34  static const int Type = 0x51;
35 
36  public:
37  /* Constructors */
38  Object() throw ();
39  Object(const std::string &value) throw (TypeCastException);
40  Object(const std::vector<std::string> &token) throw (TypeCastException);
41  Object(sella::util::MessagePack &mpack, uint32_t &offset) throw (TypeCastException);
42  Object(const std::map<std::string, Variant> &value) throw ();
43  Object(std::map<std::string, Variant> &&value) throw ();
44 
45  Object(const Object &other) throw ();
46  Object(Object &&other) throw ();
47  virtual ~Object() throw ();
48 
49  /* Operators */
50  bool operator==(const Object &other) const throw ();
51  bool operator!=(const Object &other) const throw ();
52  Object& operator=(const Object &other) throw ();
53  Object& operator=(Object &&other) throw ();
54  Object& operator+=(const Variant &other) throw ();
55  Object& operator+=(Variant &&other) throw ();
56  Variant& operator[](const std::string &key) throw ();
57  Variant& operator[](std::string &&key) throw ();
58 
59  /* Public Member Functions */
60  iterator begin() throw (UnsupportedOperatorException);
61  iterator end() throw (UnsupportedOperatorException);
62  const_iterator cbegin() const throw (UnsupportedOperatorException);
63  const_iterator cend() const throw (UnsupportedOperatorException);
64 
65  const std::map<std::string, Variant>& get() const throw (UnsupportedOperatorException);
66  std::map<std::string, Variant>& get() throw (UnsupportedOperatorException);
67 
68  size_t size() const throw ();
69  bool empty() const throw ();
70  void clear() throw();
71  bool erase(const std::string &key) throw ();
72 
73 #if 1
74  virtual void msgpack(sella::util::MessagePack &mpack, uint32_t &offset) const throw (TypeCastException);
75 #else
76  virtual uint32_t msgpack(sella::util::MessagePack &mpack, uint32_t &offset) const throw (TypeCastException);
77 #endif
78  virtual void msgpackBufferSize(size_t &size) const throw ();
79  virtual std::string str(int type) const throw ();
80  virtual int getType(void) throw () { return Type; }
81 
82  static bool isType(const std::string &value) throw () { return isType(value.c_str(), value.size()); }
83  static bool isType(const char *value, size_t size) throw ();
84 
85  private:
86  std::string json() const throw ();
87  std::string cjson() const throw ();
88  std::string xml() const throw ();
89  std::string csv() const throw ();
90 
91  void parse(const std::vector<std::string> &token) throw (TypeCastException);
92  void unmsgpack(sella::util::MessagePack &mpack, uint32_t &offset) throw (TypeCastException);
93 
94  std::map<std::string, Variant>::iterator it;
95 };
96 
97 #endif
98 
99 /*
100 ** vim: noet ts=3 sw=3
101 */