MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SimpleProperties.hpp
1 /*
2  Copyright (C) 2003-2008 MySQL AB, 2008 Sun Microsystems, Inc.
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 SIMPLE_PROPERTIES_HPP
20 #define SIMPLE_PROPERTIES_HPP
21 
22 #include <ndb_global.h>
23 #include <NdbOut.hpp>
24 
39 public:
43  enum ValueType {
44  Uint32Value = 0,
45  StringValue = 1,
46  BinaryValue = 2,
47  InvalidValue = 3
48  };
49 
54  Uint16 Key;
55  Uint32 Offset;
56  ValueType Type;
57  Uint32 minValue;
58  Uint32 maxValue;
59  Uint32 Length_Offset; // Offset used for looking up length of
60  // data if Type = BinaryValue
61  };
62 
66  enum UnpackStatus {
67  Eof = 0, // Success, end of SimpleProperties object reached
68  Break = 1, // Success
69  TypeMismatch = 2,
70  ValueTooLow = 3,
71  ValueTooHigh = 4,
72  UnknownKey = 5,
73  OutOfMemory = 6 // Only used when packing
74  };
75 
79  class Reader;
80  static UnpackStatus unpack(class Reader & it,
81  void * dst,
82  const SP2StructMapping[], Uint32 mapSz,
83  bool ignoreMinMax,
84  bool ignoreUnknownKeys);
85 
86  class Writer;
87  static UnpackStatus pack(class Writer &,
88  const void * src,
89  const SP2StructMapping[], Uint32 mapSz,
90  bool ignoreMinMax);
91 
95  class Reader {
96  public:
97  virtual ~Reader() {}
98 
103  bool first();
104 
109  bool next();
110 
114  bool valid() const;
115 
120  Uint16 getKey() const;
121 
126  Uint16 getValueLen() const;
127 
132  ValueType getValueType() const;
133 
138  Uint32 getUint32() const;
139  char * getString(char * dst) const;
140 
144  void printAll(NdbOut& ndbout);
145 
146  private:
147  bool readValue();
148 
149  Uint16 m_key;
150  Uint16 m_itemLen;
151  union {
152  Uint32 m_ui32_value;
153  Uint32 m_strLen; // Including 0-byte in words
154  };
155  ValueType m_type;
156  protected:
157  Reader();
158  virtual void reset() = 0;
159 
160  virtual bool step(Uint32 len) = 0;
161  virtual bool getWord(Uint32 * dst) = 0;
162  virtual bool peekWord(Uint32 * dst) const = 0;
163  virtual bool peekWords(Uint32 * dst, Uint32 len) const = 0;
164  };
165 
169  class Writer {
170  public:
171  Writer() {}
172 
173  bool first();
174  bool add(Uint16 key, Uint32 value);
175  bool add(Uint16 key, const char * value);
176  bool add(Uint16 key, const void* value, int len);
177  protected:
178  virtual ~Writer() {}
179  virtual bool reset() = 0;
180  virtual bool putWord(Uint32 val) = 0;
181  virtual bool putWords(const Uint32 * src, Uint32 len) = 0;
182  private:
183  bool add(const char* value, int len);
184  };
185 };
186 
191 public:
192  SimplePropertiesLinearReader(const Uint32 * src, Uint32 len);
193  virtual ~SimplePropertiesLinearReader() {}
194 
195  virtual void reset();
196  virtual bool step(Uint32 len);
197  virtual bool getWord(Uint32 * dst);
198  virtual bool peekWord(Uint32 * dst) const ;
199  virtual bool peekWords(Uint32 * dst, Uint32 len) const;
200 private:
201  Uint32 m_len;
202  Uint32 m_pos;
203  const Uint32 * m_src;
204 };
205 
210 public:
211  LinearWriter(Uint32 * src, Uint32 len);
212  virtual ~LinearWriter() {}
213 
214  virtual bool reset();
215  virtual bool putWord(Uint32 val);
216  virtual bool putWords(const Uint32 * src, Uint32 len);
217  Uint32 getWordsUsed() const;
218 private:
219  Uint32 m_len;
220  Uint32 m_pos;
221  Uint32 * m_src;
222 };
223 
228 public:
230  virtual ~UtilBufferWriter() {}
231 
232  virtual bool reset();
233  virtual bool putWord(Uint32 val);
234  virtual bool putWords(const Uint32 * src, Uint32 len);
235  Uint32 getWordsUsed() const;
236 private:
237  class UtilBuffer & m_buf;
238 };
239 
247 public:
249  class SectionSegmentPool &);
250  virtual ~SimplePropertiesSectionReader() {}
251 
252  virtual void reset();
253  virtual bool step(Uint32 len);
254  virtual bool getWord(Uint32 * dst);
255  virtual bool peekWord(Uint32 * dst) const ;
256  virtual bool peekWords(Uint32 * dst, Uint32 len) const;
257  Uint32 getSize() const;
258  bool getWords(Uint32 * dst, Uint32 len);
259 
260 private:
261  Uint32 m_pos;
262  Uint32 m_len;
263  class SectionSegmentPool & m_pool;
264  struct SectionSegment * m_head;
265  struct SectionSegment * m_currentSegment;
266 };
267 
268 inline
269 Uint32 SimplePropertiesSectionReader::getSize() const
270 {
271  return m_len;
272 }
273 
281 public:
284 
285  virtual bool reset();
286  virtual bool putWord(Uint32 val);
287  virtual bool putWords(const Uint32 * src, Uint32 len);
288  Uint32 getWordsUsed() const;
289 
293  void getPtr(struct SegmentedSectionPtr & dst);
294 
295 private:
296  void release();
297 
298  Int32 m_pos;
299  Uint32 m_sz;
300 
301  class SectionSegmentPool & m_pool;
302  class SimulatedBlock & m_block;
303  struct SectionSegment * m_head;
304  Uint32 m_prevPtrI; // Prev to m_currentSegment
305  struct SectionSegment * m_currentSegment;
306 };
307 
308 #endif