| 1 |
// ConfigImpl.h |
| 2 |
// |
| 3 |
// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Matthew Flood |
| 4 |
// See file AUTHORS for contact information |
| 5 |
// |
| 6 |
// This file is part of RudeConfig. |
| 7 |
// |
| 8 |
// RudeConfig is free software; you can redistribute it and/or modify |
| 9 |
// it under the terms of the GNU General Public License as published by |
| 10 |
// the Free Software Foundation; either version 2, or (at your option) |
| 11 |
// any later version. |
| 12 |
// |
| 13 |
// RudeConfig is distributed in the hope that it will be useful, |
| 14 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
// GNU General Public License for more details. |
| 17 |
// |
| 18 |
// You should have received a copy of the GNU General Public License |
| 19 |
// along with RudeConfig; (see COPYING) if not, write to the Free Software |
| 20 |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 21 |
// 02111-1307, USA. |
| 22 |
//------------------------------------------------------------------------ |
| 23 |
|
| 24 |
#ifndef INCLUDED_RUDE_CONFIGIMPL_H |
| 25 |
#define INCLUDED_RUDE_CONFIGIMPL_H |
| 26 |
|
| 27 |
#ifndef INCLUDED_STRING |
| 28 |
#include <string> |
| 29 |
#define INCLUDED_STRING |
| 30 |
#endif |
| 31 |
|
| 32 |
#ifndef INCLUDED_IOSTREAM |
| 33 |
#include <iostream> |
| 34 |
#define INCLUDED_IOSTREAM |
| 35 |
#endif |
| 36 |
|
| 37 |
namespace rude{ |
| 38 |
namespace config{ |
| 39 |
|
| 40 |
class Section; |
| 41 |
class File; |
| 42 |
class AbstractWriter; |
| 43 |
class AbstractParser; |
| 44 |
class AbstractOrganiser; |
| 45 |
|
| 46 |
class ConfigImpl{ |
| 47 |
|
| 48 |
static std::string s_defaultConfigFile; |
| 49 |
static char s_defaultCommentChar; |
| 50 |
static char s_defaultDelimiter; |
| 51 |
static bool s_defaultPreserveDeleted; |
| 52 |
static bool s_defaultAllowDuplicate; |
| 53 |
static bool s_defaultIgnoreCase; |
| 54 |
static std::string s_returnValue; |
| 55 |
|
| 56 |
AbstractWriter *d_writer; |
| 57 |
AbstractOrganiser *d_organiser; |
| 58 |
AbstractParser *d_parser; |
| 59 |
|
| 60 |
File *d_file; |
| 61 |
std::string d_error; |
| 62 |
std::string d_errorcode; |
| 63 |
|
| 64 |
std::string d_configfile; |
| 65 |
char d_commentcharacter; |
| 66 |
char d_delimiter; |
| 67 |
bool d_preserveDeleted; |
| 68 |
bool d_allowDuplicate; |
| 69 |
bool d_ignoreCase; |
| 70 |
|
| 71 |
protected: |
| 72 |
|
| 73 |
void setError(const char *errorcode, const char *errorstring); |
| 74 |
|
| 75 |
public: |
| 76 |
|
| 77 |
////////////////////////////////////// |
| 78 |
// STATIC METHODS |
| 79 |
////////////////////////////////////// |
| 80 |
static const char *version(); |
| 81 |
|
| 82 |
// DEFAULT BEHAVIOR |
| 83 |
// |
| 84 |
static void setDefaultConfigFile(const char *filepath); |
| 85 |
static const char *getDefaultConfigFile(); |
| 86 |
|
| 87 |
static void setDefaultCommentCharacter(char c); |
| 88 |
static char getDefaultCommentCharacter(); |
| 89 |
|
| 90 |
static void setDefaultDelimiter(char c); |
| 91 |
static char getDefaultDelimiter(); |
| 92 |
|
| 93 |
static void setDefaultPreserveDeleted(bool shouldPreserve); |
| 94 |
static bool getDefaultPreserveDeleted(); |
| 95 |
|
| 96 |
// The internals are on the drawing board!! |
| 97 |
// |
| 98 |
static void setDefaultIgnoreCase(bool shouldIgnore); |
| 99 |
static void setDefaultAllowDuplicateKeys(bool shouldAllow); |
| 100 |
|
| 101 |
|
| 102 |
// DATA CONVERSION |
| 103 |
// |
| 104 |
static bool stringToBool(const char *string); |
| 105 |
static const char *boolToString(bool value); |
| 106 |
static int stringToInt(const char *string); |
| 107 |
static const char *intToString(int value); |
| 108 |
static double stringToDouble(const char *string); |
| 109 |
static const char *doubleToString(double value); |
| 110 |
static char * stringToBinary(const char *value, int &outlength); |
| 111 |
static const char *binaryToString(const char *value, int length); |
| 112 |
|
| 113 |
|
| 114 |
////////////////////////////////////// |
| 115 |
// INSTANCE METHODS |
| 116 |
////////////////////////////////////// |
| 117 |
|
| 118 |
// CONSTRUCTOR & DESTRUCTOR |
| 119 |
// |
| 120 |
ConfigImpl(); |
| 121 |
~ConfigImpl(); |
| 122 |
|
| 123 |
// STATUS |
| 124 |
// |
| 125 |
const char *getError() const; |
| 126 |
const char *getErrorCode() const; |
| 127 |
|
| 128 |
// INSTANCE BEHAVIOR |
| 129 |
// |
| 130 |
void setConfigFile(const char *filepath); |
| 131 |
const char *getConfigFile(); |
| 132 |
void setCommentCharacter(char c); |
| 133 |
void setDelimiter(char c); |
| 134 |
void preserveDeletedData(bool shouldPreserve); |
| 135 |
void ignoreCase(bool shouldIgnore); |
| 136 |
void allowDuplicateKeys(bool shouldAllow); |
| 137 |
|
| 138 |
// LOADING & SAVING & CLEARING |
| 139 |
// |
| 140 |
bool load(); |
| 141 |
bool load(const char *filepath); |
| 142 |
bool load(std::istream&); |
| 143 |
|
| 144 |
bool save(); |
| 145 |
bool save(const char *filepath); |
| 146 |
bool save(std::ostream&); |
| 147 |
|
| 148 |
void clear(); |
| 149 |
|
| 150 |
|
| 151 |
// SECTION METHODS |
| 152 |
// |
| 153 |
int getNumSections() const; |
| 154 |
const char *getSectionNameAt(int index) const; |
| 155 |
bool setSection(const char *sectionname, bool shouldCreate); |
| 156 |
bool setSection(const char *sectionname); |
| 157 |
bool deleteSection(const char *sectionname); |
| 158 |
|
| 159 |
|
| 160 |
// DATA METHODS |
| 161 |
// |
| 162 |
|
| 163 |
int getNumSourceDestMembers() const; |
| 164 |
const char *getSrcAppAt(int index) const; |
| 165 |
const char *getDestAppAt(int index) const; |
| 166 |
const char *getSrcObjAt(int index) const; |
| 167 |
const char *getDestObjAt(int index) const; |
| 168 |
const char *getWidthAt(int index) const; |
| 169 |
/* remedius |
| 170 |
* |
| 171 |
*/ |
| 172 |
const char *getCommTypeAt(int index) const; |
| 173 |
/* remedius |
| 174 |
* |
| 175 |
*/ |
| 176 |
const char *getProcMethodAt(int index) const; |
| 177 |
|
| 178 |
int getNumDataMembers() const; |
| 179 |
const char *getDataNameAt(int index) const; |
| 180 |
const char *getDataValueAt(int index) const; |
| 181 |
bool exists(const char *name) const; |
| 182 |
|
| 183 |
const char * getStringValue(const char *name) const; |
| 184 |
void setStringValue(const char *name, const char *value); |
| 185 |
bool deleteData(const char *name); |
| 186 |
|
| 187 |
// Working with Duplicate Keys |
| 188 |
// |
| 189 |
int getNumDataMembers(const char *key) const; |
| 190 |
const char * getStringValue(const char *name, int index) const; |
| 191 |
void addStringValue(const char *name, const char *value); |
| 192 |
bool deleteData(const char *name, int index); |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
}; |
| 197 |
}} // end namespace rude::config |
| 198 |
#endif |
| 199 |
|