MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Properties.hpp
1 /*
2  Copyright (C) 2003-2006 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef PROPERTIES_HPP
20 #define PROPERTIES_HPP
21 
22 #include <ndb_global.h>
23 #include <BaseString.hpp>
24 #include <UtilBuffer.hpp>
25 
26 enum PropertiesType {
27  PropertiesType_Uint32 = 0,
28  PropertiesType_char = 1,
29  PropertiesType_Properties = 2,
30  PropertiesType_Uint64 = 3
31 };
32 
40 struct Property {
41  Property(const char* name, Uint32 val);
42  Property(const char* name, Uint64 val);
43  Property(const char* name, const char * value);
44  Property(const char* name, const class Properties * value);
45  ~Property();
46 private:
47  friend class Properties;
48  struct PropertyImpl * impl;
49 };
50 
55 class Properties {
56 public:
57  static const char delimiter;
58  static const char version[];
59 
60  Properties(bool case_insensitive= false);
61  Properties(const Properties &);
62  Properties(const Property *, int len);
63  virtual ~Properties();
64 
73  void setCaseInsensitiveNames(bool value);
74  bool getCaseInsensitiveNames() const;
75 
79  void put(const Property *, int len);
80 
81  bool put(const char * name, Uint32 value, bool replace = false);
82  bool put64(const char * name, Uint64 value, bool replace = false);
83  bool put(const char * name, const char * value, bool replace = false);
84  bool put(const char * name, const Properties * value, bool replace = false);
85 
91  bool put(const char *, Uint32 no, Uint32, bool replace = false);
92  bool put64(const char *, Uint32 no, Uint64, bool replace = false);
93  bool put(const char *, Uint32 no, const char *, bool replace = false);
94  bool put(const char *, Uint32 no, const Properties *, bool replace = false);
95 
96 
97  bool getTypeOf(const char * name, PropertiesType * type) const;
98 
100  bool contains(const char * name) const;
101 
102  bool get(const char * name, Uint32 * value) const;
103  bool get(const char * name, Uint64 * value) const;
104  bool get(const char * name, const char ** value) const;
105  bool get(const char * name, BaseString & value) const;
106  bool get(const char * name, const Properties ** value) const;
107 
108  bool getCopy(const char * name, char ** value) const;
109  bool getCopy(const char * name, Properties ** value) const;
110 
115  bool getTypeOf(const char * name, Uint32 no, PropertiesType * type) const;
116  bool contains(const char * name, Uint32 no) const;
117 
118  bool get(const char * name, Uint32 no, Uint32 * value) const;
119  bool get(const char * name, Uint32 no, Uint64 * value) const;
120  bool get(const char * name, Uint32 no, const char ** value) const;
121  bool get(const char * name, Uint32 no, const Properties ** value) const;
122 
123  bool getCopy(const char * name, Uint32 no, char ** value) const;
124  bool getCopy(const char * name, Uint32 no, Properties ** value) const;
125 
126  void clear();
127 
128  void remove(const char * name);
129 
130  void print(FILE * file = stdout, const char * prefix = 0) const;
134  class Iterator {
135  public:
136  Iterator(const Properties* prop);
137 
138  const char* first();
139  const char* next();
140  private:
141  const Properties* m_prop;
142  Uint32 m_iterator;
143  };
144  friend class Properties::Iterator;
145 
146  Uint32 getPackedSize() const;
147  bool pack(Uint32 * buf) const;
148  bool pack(UtilBuffer &buf) const;
149  bool unpack(const Uint32 * buf, Uint32 bufLen);
150  bool unpack(UtilBuffer &buf);
151 
152  Uint32 getPropertiesErrno() const { return propErrno; }
153  Uint32 getOSErrno() const { return osErrno; }
154 private:
155  Uint32 propErrno;
156  Uint32 osErrno;
157 
158  friend class PropertiesImpl;
159  class PropertiesImpl * impl;
160  class Properties * parent;
161 
162  void setErrno(Uint32 pErr, Uint32 osErr = 0) const ;
163 };
164 
172 extern const Uint32 E_PROPERTIES_OK;
173 
177 extern const Uint32 E_PROPERTIES_INVALID_NAME;
178 
182 extern const Uint32 E_PROPERTIES_NO_SUCH_ELEMENT;
183 
187 extern const Uint32 E_PROPERTIES_INVALID_TYPE;
188 
192 extern const Uint32 E_PROPERTIES_ELEMENT_ALREADY_EXISTS;
193 
197 extern const Uint32 E_PROPERTIES_INVALID_VERSION_WHILE_UNPACKING;
198 
205 extern const Uint32 E_PROPERTIES_INVALID_BUFFER_TO_SHORT;
206 
212 extern const Uint32 E_PROPERTIES_ERROR_MALLOC_WHILE_PACKING;
213 
219 extern const Uint32 E_PROPERTIES_ERROR_MALLOC_WHILE_UNPACKING;
220 
225 extern const Uint32 E_PROPERTIES_INVALID_CHECKSUM;
226 
231 extern const Uint32 E_PROPERTIES_BUFFER_TO_SMALL_WHILE_UNPACKING;
232 
233 inline bool
234 Properties::unpack(UtilBuffer &buf) {
235  return unpack((const Uint32 *)buf.get_data(), buf.length());
236 }
237 
238 inline bool
239 Properties::pack(UtilBuffer &buf) const {
240  Uint32 size = getPackedSize();
241  void *tmp_buf = buf.append(size);
242  if(tmp_buf == 0)
243  return false;
244  bool ret = pack((Uint32 *)tmp_buf);
245  if(ret == false)
246  return false;
247  return true;
248 }
249 
250 
251 
252 #endif