| 1 |
// KeyValue.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 |
|
| 25 |
#ifndef INCLUDED_KeyValue_H |
| 26 |
#define INCLUDED_KeyValue_H |
| 27 |
|
| 28 |
#ifndef INCLUDED_DataLine_H |
| 29 |
#include "DataLine.h" |
| 30 |
#endif |
| 31 |
|
| 32 |
#ifndef INCLUDED_STRING |
| 33 |
#include <string> |
| 34 |
#define INCLUDED_STRING |
| 35 |
#endif |
| 36 |
|
| 37 |
#ifndef INCLUDED_IOSTREAM |
| 38 |
#include <iostream> |
| 39 |
#define INCLUDED_IOSTREAM |
| 40 |
#endif |
| 41 |
|
| 42 |
namespace rude{ |
| 43 |
namespace config{ |
| 44 |
//= |
| 45 |
// KeyValue represents a single line/entry in a configuration file. |
| 46 |
// It can represent whitespace, a comment, or key=value data. |
| 47 |
// |
| 48 |
// <B>Current Limitations</B> |
| 49 |
// <ul> |
| 50 |
// <li> <b>Data Names:</b> it is assumed that the names for entries are valid. Invalid names are not detected. |
| 51 |
// A name containing the delimiter or comment character is invalid. |
| 52 |
// A name containing newline information is invalid. |
| 53 |
// Future releases should either detect and reject invalid names, or use an escape mechanism such as backslashing |
| 54 |
// to allow invalid characters to appear within a name. |
| 55 |
// |
| 56 |
// <li> <b>Data Values:</b> Same as data names. (see above) |
| 57 |
// </ul> |
| 58 |
//= |
| 59 |
class KeyValue: public DataLine{ |
| 60 |
|
| 61 |
|
| 62 |
std::string d_name; |
| 63 |
std::string d_value; |
| 64 |
std::string d_comment; |
| 65 |
|
| 66 |
public: |
| 67 |
|
| 68 |
// default constructor |
| 69 |
KeyValue(); |
| 70 |
KeyValue(const char *name, const char *value, const char *comment); |
| 71 |
|
| 72 |
void acceptWriter(AbstractWriter& writer) const; |
| 73 |
|
| 74 |
//= |
| 75 |
// Returns the name of the data member |
| 76 |
// Will return the name even if the data member is flagged as being deleted or a comment |
| 77 |
// Always returns at least the empty string, will never return null. |
| 78 |
//= |
| 79 |
const char *getName() const; |
| 80 |
|
| 81 |
//= |
| 82 |
// Returns the string value of the data member |
| 83 |
// Will return the value even if the data member is flagged as being deleted or a comment |
| 84 |
// Always returns at least the empty string, will never return null. |
| 85 |
//= |
| 86 |
const char *getValue() const; |
| 87 |
|
| 88 |
//= |
| 89 |
// Returns the comment associated with the data member |
| 90 |
// Will return the comment even if the data member is flagged as being deleted |
| 91 |
// Always returns at least the empty string, will never return null. |
| 92 |
//= |
| 93 |
const char *getComment() const; |
| 94 |
|
| 95 |
//= |
| 96 |
// Sets the name of the data member |
| 97 |
// Will set the name even if the data member is flagged as being deleted or a comment |
| 98 |
// Accepts null |
| 99 |
//= |
| 100 |
void setName(const char *name); |
| 101 |
|
| 102 |
//= |
| 103 |
// Sets the string value of the data member |
| 104 |
// Will set the value even if the data member is flagged as being deleted or a comment |
| 105 |
// Accepts null |
| 106 |
//= |
| 107 |
void setValue(const char *value); // un-deletes if previously deleted..... |
| 108 |
|
| 109 |
//= |
| 110 |
// Sets the comment associated with the data member |
| 111 |
// Will set the comment even if the data member is flagged as being deleted |
| 112 |
// Accepts null |
| 113 |
//= |
| 114 |
void setComment(const char *comment); |
| 115 |
|
| 116 |
~KeyValue(); |
| 117 |
|
| 118 |
}; |
| 119 |
|
| 120 |
}} // end namespace rude::config |
| 121 |
|
| 122 |
#endif |
| 123 |
|