| 1 |
// Section.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_Section_H |
| 25 |
#define INCLUDED_Section_H |
| 26 |
|
| 27 |
#ifndef INCLUDED_STRING |
| 28 |
#include <string> |
| 29 |
#define INCLUDED_STRING |
| 30 |
#endif |
| 31 |
|
| 32 |
#ifndef INCLUDED_VECTOR |
| 33 |
#include <vector> |
| 34 |
#define INCLUDED_VECTOR |
| 35 |
#endif |
| 36 |
|
| 37 |
#ifndef INCLUDED_MAP |
| 38 |
#include <map> |
| 39 |
#define INCLUDED_MAP |
| 40 |
#endif |
| 41 |
|
| 42 |
#ifndef INCLUDED_IOSTREAM |
| 43 |
#include <iostream> |
| 44 |
#define INCLUDED_IOSTREAM |
| 45 |
#endif |
| 46 |
|
| 47 |
|
| 48 |
#ifndef INCLUDED_STRING |
| 49 |
#include <string> |
| 50 |
#define INCLUDED_STRING |
| 51 |
#endif |
| 52 |
|
| 53 |
namespace rude{ |
| 54 |
namespace config{ |
| 55 |
|
| 56 |
class DataLine; |
| 57 |
class KeyValue; |
| 58 |
class AbstractWriter; |
| 59 |
class SourceDest; |
| 60 |
|
| 61 |
//= |
| 62 |
// Section represents a single section within a configuration file. |
| 63 |
// It is identified by its section name, which can include whitespace, |
| 64 |
// and manages the set of all data and/or comments associated with that section. |
| 65 |
// |
| 66 |
// Each piece of data is identified by its name. Currently, only one piece of data |
| 67 |
// is recognized for any given name. In the case where two or more values exist for the |
| 68 |
// same name (within a section), only the last value is recognized - any previous values are discarded. |
| 69 |
//= |
| 70 |
class Section{ |
| 71 |
|
| 72 |
bool d_isDeleted; |
| 73 |
std::string d_sectionname; |
| 74 |
std::string d_sectioncomment; |
| 75 |
|
| 76 |
// Q: Should these really be mutable??? |
| 77 |
mutable std::vector<DataLine*> d_allDataVector; |
| 78 |
mutable std::vector<KeyValue*> d_kv_vector; |
| 79 |
mutable std::map<std::string, KeyValue*> d_kv_map; |
| 80 |
|
| 81 |
// Note that a source can have multiple dest, |
| 82 |
// but a dest can only have one source. |
| 83 |
// Therefor we use dest for lookups! |
| 84 |
mutable std::vector<SourceDest*> d_sd_vector; |
| 85 |
|
| 86 |
public: |
| 87 |
|
| 88 |
Section(const char *sectionname, const char *sectioncomment=0); |
| 89 |
void acceptWriter(AbstractWriter& writer) const; |
| 90 |
|
| 91 |
//= |
| 92 |
// Writes the section and all associated data to the outputstream |
| 93 |
// |
| 94 |
// <b>If the section is marked as deleted:</b> |
| 95 |
// The entire section is commented out. This means that it is still printed out, |
| 96 |
// but each line is begun with the comment character. If the comment character is |
| 97 |
// set to null, then the section is not printed out at all - it is essentially discarded. |
| 98 |
// |
| 99 |
// In normal circumstances, the '=' is the most appropriate delimiter to use. |
| 100 |
// If delimiter is null, then whie |
| 101 |
//= |
| 102 |
void write(std::ostream& outputstream, char commentchar, char delimiter, bool preserveDeleted); |
| 103 |
|
| 104 |
//= |
| 105 |
// Returns this section's name, identified by [somename] in the config/ini file |
| 106 |
//= |
| 107 |
const char *getSectionName() const; |
| 108 |
|
| 109 |
|
| 110 |
//= |
| 111 |
// Returns the section-comment (found after the section name) |
| 112 |
// |
| 113 |
// An example of a section-comment is: |
| 114 |
// |
| 115 |
// [Dogs] # this section is about dogs |
| 116 |
// |
| 117 |
//= |
| 118 |
const char *getSectionComment() const; |
| 119 |
|
| 120 |
|
| 121 |
//= |
| 122 |
// Sets the section comment (found after the section name) |
| 123 |
//= |
| 124 |
void setSectionComment(const char *newcomment); |
| 125 |
|
| 126 |
|
| 127 |
//= |
| 128 |
// Returns whether or not this section is flagged as deleted... |
| 129 |
//= |
| 130 |
bool isDeleted() const; |
| 131 |
|
| 132 |
|
| 133 |
//= |
| 134 |
// (Un)marks this section as deleted |
| 135 |
// When marked as deleted, all data members are marked as deleted |
| 136 |
// When undeleted, data members remain marked as deleted.... |
| 137 |
//= |
| 138 |
void isDeleted(bool is_it_or_not); |
| 139 |
|
| 140 |
|
| 141 |
//= |
| 142 |
// Returns the number of (non-deleted) data members |
| 143 |
// Deleted data, comments and blank lines are not included in the count. |
| 144 |
//= |
| 145 |
int getNumDataMembers() const; |
| 146 |
|
| 147 |
|
| 148 |
//= |
| 149 |
// # SourceDest objects |
| 150 |
//= |
| 151 |
int getNumSourceDestMembers() const; |
| 152 |
|
| 153 |
|
| 154 |
//= |
| 155 |
// Returns the name of the (undeleted) data member at the specified index |
| 156 |
// Returns NULL if the index is out of range |
| 157 |
//= |
| 158 |
const char *getDataNameAt(int index) const; |
| 159 |
|
| 160 |
const char *getDestAppAt(int index) const; |
| 161 |
const char *getSrcAppAt(int index) const; |
| 162 |
const char *getDestObjAt(int index) const; |
| 163 |
const char *getSrcObjAt(int index) const; |
| 164 |
|
| 165 |
const char *getWidthAt(int index) const; |
| 166 |
|
| 167 |
/* remedius |
| 168 |
* returns <collective>, <point-to-point> or "" type of communication. |
| 169 |
*/ |
| 170 |
const char *getCommTypeAt(int index) const; |
| 171 |
/* remedius |
| 172 |
* returns <tree>, <table> or "" processing method. |
| 173 |
*/ |
| 174 |
const char *getProcMethodAt(int index) const; |
| 175 |
|
| 176 |
|
| 177 |
//= |
| 178 |
// Returns the name of the (undeleted) data member at the specified index |
| 179 |
// Returns NULL if the index is out of range |
| 180 |
//= |
| 181 |
const char *getDataValueAt(int index) const; |
| 182 |
|
| 183 |
|
| 184 |
//= |
| 185 |
// Returns true if data name exists (and is not marked as deleted), false otherwise |
| 186 |
//= |
| 187 |
bool exists(const char *name) const; |
| 188 |
|
| 189 |
//= |
| 190 |
// Returns the value associated with the data identified by <i>name</i> |
| 191 |
// Returns NULL if data name does not exist (or is marked as deleted) |
| 192 |
//= |
| 193 |
const char *getValue(const char *name) const; |
| 194 |
|
| 195 |
|
| 196 |
//= |
| 197 |
// Returns the comment associated with the data identified by <i>name</i> |
| 198 |
// Returns NULL if data name does not exist (or is marked as deleted) |
| 199 |
//= |
| 200 |
const char *getComment(const char *name) const; |
| 201 |
|
| 202 |
|
| 203 |
//= |
| 204 |
// Sets the <b>value</b> for the data member identified by <i>name</i> |
| 205 |
// If a data member already exists with the given <i>name</i>, then the value is replaced. |
| 206 |
// Otherwise a new data item is created.. |
| 207 |
// If the data item already exists, but has been marked as deleted, |
| 208 |
// it will be revived (unmarked) and its value updated. |
| 209 |
// Existing comments associated with the data member are not altered. |
| 210 |
//= |
| 211 |
void setValue(const char *name, const char *value); |
| 212 |
|
| 213 |
|
| 214 |
//= |
| 215 |
// Replaces the comment for the data member identified by <i>name</i> |
| 216 |
// Sets the comment whether or not the data is marked as deleted. |
| 217 |
// If the data identified by <i>name</i> does not exist, then nothing happens |
| 218 |
//= |
| 219 |
void setComment(const char *name, const char *comment); |
| 220 |
|
| 221 |
|
| 222 |
//= |
| 223 |
// Sets the <b>value</b> and the <b>comment</b> for the data member identified by <i>name</i> |
| 224 |
// If a data member already exists with the given <i>name</i>, then the value is replaced. |
| 225 |
// Otherwise a new data item is created.. |
| 226 |
// If the data item already exists, but has been marked as deleted, |
| 227 |
// it will be revived (unmarked) and updated. |
| 228 |
//= |
| 229 |
void setValue(const char *name, const char *value, const char *comment); |
| 230 |
|
| 231 |
/* remedius |
| 232 |
* two more parameters: commType and procMethod were added due to the runtime opportunity |
| 233 |
* of choosing communication type and pre-/post-processing method. |
| 234 |
*/ |
| 235 |
void addSourceDest(const char *srcApp, const char *srcObj, const char *destApp, const char *destObj, |
| 236 |
const char *width, const char *commType, const char *procMethod, const char *comment); |
| 237 |
|
| 238 |
|
| 239 |
//= |
| 240 |
// Adds a comment line to the end of the section |
| 241 |
//= |
| 242 |
void addComment(const char *comment); |
| 243 |
|
| 244 |
//= |
| 245 |
// Adds whitespace line to the end of the section |
| 246 |
//= |
| 247 |
void addWhiteSpace(const char *whitespace); |
| 248 |
|
| 249 |
//= |
| 250 |
// Marks the data identified by name as deleted |
| 251 |
// Returns false if data does not exist within this |
| 252 |
// section (or has already been marked as deleted) |
| 253 |
//= |
| 254 |
bool deleteData(const char *name); |
| 255 |
|
| 256 |
|
| 257 |
~Section(); |
| 258 |
|
| 259 |
}; |
| 260 |
}} // end namespace rude::config |
| 261 |
#endif |
| 262 |
|