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