1
/* Copyright (C) 2004-2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
#ifndef __CONFIG_VALUES_HPP
17
#define __CONFIG_VALUES_HPP
19
#include <ndb_types.h>
20
#include <UtilBuffer.hpp>
23
friend class ConfigValuesFactory;
24
ConfigValues(Uint32 sz, Uint32 data);
43
const char * m_string;
48
friend class ConfigValuesFactory;
49
const ConfigValues & m_cfg;
51
Uint32 m_currentSection;
52
ConstIterator(const ConfigValues&c) : m_cfg(c) { m_currentSection = 0;}
54
bool openSection(Uint32 key, Uint32 no);
57
bool get(Uint32 key, Entry *) const;
59
bool get(Uint32 key, Uint32 * value) const;
60
bool get(Uint32 key, Uint64 * value) const;
61
bool get(Uint32 key, const char ** value) const;
62
bool getTypeOf(Uint32 key, ValueType * type) const;
64
Uint32 get(Uint32 key, Uint32 notFound) const;
65
Uint64 get64(Uint32 key, Uint64 notFound) const;
66
const char * get(Uint32 key, const char * notFound) const;
67
ValueType getTypeOf(Uint32 key) const;
70
class Iterator : public ConstIterator {
73
Iterator(ConfigValues&c) : ConstIterator(c), m_cfg(c) {}
74
Iterator(ConfigValues&c, const ConstIterator& i):ConstIterator(c),m_cfg(c){
75
m_currentSection = i.m_currentSection;
78
bool set(Uint32 key, Uint32 value);
79
bool set(Uint32 key, Uint64 value);
80
bool set(Uint32 key, const char * value);
83
Uint32 getPackedSize() const; // get size in bytes needed to pack
84
Uint32 pack(UtilBuffer&) const;
85
Uint32 pack(void * dst, Uint32 len) const;// pack into dst(of len %d);
88
friend class Iterator;
89
friend class ConstIterator;
91
bool getByPos(Uint32 pos, Entry *) const;
92
Uint64 * get64(Uint32 index) const;
93
char ** getString(Uint32 index) const;
104
class ConfigValuesFactory {
105
Uint32 m_currentSection;
107
Uint32 m_sectionCounter;
112
ConfigValuesFactory(Uint32 keys = 50, Uint32 data = 10); // Initial
113
ConfigValuesFactory(ConfigValues * m_cfg); //
114
~ConfigValuesFactory();
116
ConfigValues * m_cfg;
117
ConfigValues * getConfigValues();
119
bool openSection(Uint32 key, Uint32 no);
120
bool put(const ConfigValues::Entry & );
121
bool put(Uint32 key, Uint32 value);
122
bool put64(Uint32 key, Uint64 value);
123
bool put(Uint32 key, const char * value);
126
void expand(Uint32 freeKeys, Uint32 freeData);
129
bool unpack(const UtilBuffer&);
130
bool unpack(const void * src, Uint32 len);
132
static ConfigValues * extractCurrentSection(const ConfigValues::ConstIterator &);
135
static ConfigValues * create(Uint32 keys, Uint32 data);
136
void put(const ConfigValues & src);
141
ConfigValues::ConstIterator::get(Uint32 key, Uint32 * value) const {
143
if(get(key, &tmp) && tmp.m_type == IntType){
152
ConfigValues::ConstIterator::get(Uint32 key, Uint64 * value) const {
154
if(get(key, &tmp) && tmp.m_type == Int64Type){
155
* value = tmp.m_int64;
163
ConfigValues::ConstIterator::get(Uint32 key, const char ** value) const {
165
if(get(key, &tmp) && tmp.m_type == StringType){
166
* value = tmp.m_string;
174
ConfigValues::ConstIterator::getTypeOf(Uint32 key, ValueType * type) const{
185
ConfigValues::ConstIterator::get(Uint32 key, Uint32 notFound) const {
187
if(get(key, &tmp) && tmp.m_type == IntType){
195
ConfigValues::ConstIterator::get64(Uint32 key, Uint64 notFound) const {
197
if(get(key, &tmp) && tmp.m_type == Int64Type){
205
ConfigValues::ConstIterator::get(Uint32 key, const char * notFound) const {
207
if(get(key, &tmp) && tmp.m_type == StringType){
214
ConfigValues::ValueType
215
ConfigValues::ConstIterator::getTypeOf(Uint32 key) const{
220
return ConfigValues::InvalidType;
225
ConfigValuesFactory::put(Uint32 key, Uint32 val){
226
ConfigValues::Entry tmp;
228
tmp.m_type = ConfigValues::IntType;
235
ConfigValuesFactory::put64(Uint32 key, Uint64 val){
236
ConfigValues::Entry tmp;
238
tmp.m_type = ConfigValues::Int64Type;
245
ConfigValuesFactory::put(Uint32 key, const char * val){
246
ConfigValues::Entry tmp;
248
tmp.m_type = ConfigValues::StringType;
255
ConfigValues::pack(UtilBuffer& buf) const {
256
Uint32 len = getPackedSize();
257
void * tmp = buf.append(len);
261
return pack(tmp, len);
266
ConfigValuesFactory::unpack(const UtilBuffer& buf){
267
return unpack(buf.get_data(), buf.length());