jigdo API
ConfigFile Class Reference
General approach: Reading/changes/writing of config should be possible, and all formatting and comments made by any human editing the file should be preserved. More...
#include <configfile.hh>
Public Types | |
| typedef string & | reference |
| Standard list interface. | |
| typedef const string & | const_reference |
Public Member Functions | |
| ConfigFile (ProgressReporter &pr=noReport) | |
| ~ConfigFile () | |
| void | rescan (bool printErrors=false) |
| This must be called after *sections* have been added/removed/ renamed, to update the list of sections present in the config file. | |
| void | setReporter (ProgressReporter &pr) |
| Change reporter for error messages. | |
| istream & | get (istream &s) |
| Input from file, append to this. | |
| ostream & | put (ostream &s) const |
| Output to file. | |
| iterator | firstSection () |
| Return iterator to first real [section] line in the file. | |
| iterator | firstSection (const string §Name) |
| Return iterator to first section with given name, or to end(). | |
| size_t | size () const |
| bool | empty () const |
| iterator | begin () |
| iterator | end () |
| reference | front () |
| reference | back () |
| iterator | find (const string §Name, const string &line) |
| iterator | insert (iterator pos) |
| iterator | insert (iterator pos, const_reference s) |
| iterator | insert (iterator pos, const char *s) |
| iterator | erase (iterator pos) |
| void | push_back () |
| void | push_back (const string &s) |
| void | push_back (const char *s) |
Static Public Member Functions | |
| static bool | advanceWhitespace (string::const_iterator &x, const string::const_iterator &end) |
| Helper function: Advance x until it points to end or a non-space, non-tab character. | |
| static bool | advanceWhitespace (string::iterator &x, const string::const_iterator &end) |
| static bool | isWhitespace (char x) |
| Is character a space or tab? | |
| template<class Container> | |
| static void | split (Container &out, const string &s, size_t offset=0) |
| Helper function, useful to post-process entry values: Given a string and an offset in it, extract the entry value (everything starting with the specified offset) and break it into whitespace-separated words, which are appended to out. | |
| static string & | quote (string &s) |
| Related to above; if necessary, modifies s in such a way that it stays one word: If it contains whitespace, " or \ then enclose it in '' and if it contains ' then enclose it in "" and additionally escape other problematical characters with \. | |
Classes | |
| class | Find |
| Class to enumerate all lines in the config file which match a given section & label name. More... | |
| class | iterator |
| The iterators hide the fact that a ConfigFile is not a list<string>. More... | |
| struct | Line |
| class | ProgressReporter |
| Class allowing ConfigFile to convey information back to the creator of a ConfigFile object. More... | |
Detailed Description
General approach: Reading/changes/writing of config should be possible, and all formatting and comments made by any human editing the file should be preserved.Consequently, a ConfigFile behaves like a list<string> simply containing the raw data as read from the file. Access is possible via a subset of the list<> methods, or higher-level methods to find sections/entries.
NB: Changing/writing to disc of config not currently supported.
Member Typedef Documentation
| typedef string& ConfigFile::reference |
Standard list interface.
| typedef const string& ConfigFile::const_reference |
Constructor & Destructor Documentation
| ConfigFile::ConfigFile | ( | ProgressReporter & | pr = noReport |
) | [inline] |
| ConfigFile::~ConfigFile | ( | ) |
Member Function Documentation
| void ConfigFile::rescan | ( | bool | printErrors = false |
) |
This must be called after *sections* have been added/removed/ renamed, to update the list of sections present in the config file.
No need to call it after insertion/deletion of lines, whitespace/comment changes of [section] lines, or any changes to entries.
- Parameters:
-
printErrors If true, perform extra syntax checks and call ProgressReporter object for syntax errors.
References _, advanceWhitespace(), begin(), end(), ConfigFile::ProgressReporter::error(), isWhitespace(), ConfigFile::iterator::nextSect(), s1, s2, subst, and x.
Referenced by get().
| void ConfigFile::setReporter | ( | ProgressReporter & | pr | ) | [inline] |
| istream & ConfigFile::get | ( | istream & | s | ) |
Input from file, append to this.
Makes a call to rescan(true).
References back(), Paranoid, push_back(), rescan(), and swap().
Referenced by operator>>().
| ostream & ConfigFile::put | ( | ostream & | s | ) | const |
| iterator ConfigFile::firstSection | ( | ) | [inline] |
Return iterator to first real [section] line in the file.
Referenced by find(), and JigdoConfig::rescan().
| ConfigFile::iterator ConfigFile::firstSection | ( | const string & | sectName | ) | [inline] |
Return iterator to first section with given name, or to end().
References end(), and ConfigFile::iterator::nextSection().
| bool ConfigFile::empty | ( | ) | const [inline] |
References size().
| ConfigFile::iterator ConfigFile::begin | ( | ) | [inline] |
Referenced by rescan().
| ConfigFile::iterator ConfigFile::end | ( | ) | [inline] |
| ConfigFile::reference ConfigFile::front | ( | ) | [inline] |
| ConfigFile::reference ConfigFile::back | ( | ) | [inline] |
Referenced by get(), and push_back().
| ConfigFile::iterator ConfigFile::find | ( | const string & | sectName, | |
| const string & | line | |||
| ) |
| ConfigFile::iterator ConfigFile::insert | ( | iterator | pos | ) | [inline] |
| ConfigFile::iterator ConfigFile::insert | ( | iterator | pos, | |
| const_reference | s | |||
| ) | [inline] |
References ConfigFile::iterator::p, and x.
| ConfigFile::iterator ConfigFile::insert | ( | iterator | pos, | |
| const char * | s | |||
| ) | [inline] |
References ConfigFile::iterator::p, and x.
| ConfigFile::iterator ConfigFile::erase | ( | iterator | pos | ) | [inline] |
References ConfigFile::iterator::p, and Paranoid.
| bool ConfigFile::advanceWhitespace | ( | string::const_iterator & | x, | |
| const string::const_iterator & | end | |||
| ) | [inline, static] |
Helper function: Advance x until it points to end or a non-space, non-tab character.
Returns true if at end of string (or '#' comment).
Referenced by advanceWhitespace(), ConfigFile::iterator::isSection(), ConfigFile::iterator::nextLabel(), ConfigFile::iterator::prevLabel(), rescan(), ConfigFile::iterator::setLabelOffsets(), and skipPrevComments().
| bool ConfigFile::advanceWhitespace | ( | string::iterator & | x, | |
| const string::const_iterator & | end | |||
| ) | [inline, static] |
| static bool ConfigFile::isWhitespace | ( | char | x | ) | [inline, static] |
| void ConfigFile::split | ( | Container & | out, | |
| const string & | s, | |||
| size_t | offset = 0 | |||
| ) | [inline, static] |
Helper function, useful to post-process entry values: Given a string and an offset in it, extract the entry value (everything starting with the specified offset) and break it into whitespace-separated words, which are appended to out.
This does many things that a shell does:
- Allow quoting with "" or ''. Whitespace between quotes does not cause the word to be split there.
- Except inside '', escaping double quote, space, # or backslash with \ is possible.
- A comment can be added at the end of the line. Escapes like \012, \xff, \n, \t are *not* supported, behaviour is undefined. (Possible future extension, TODO: Allow \ at end of line for multi-line entries?)
References swap().
| string & ConfigFile::quote | ( | string & | s | ) | [static] |
The documentation for this class was generated from the following files:
- util/configfile.hh
- util/configfile.cc
Generated on Tue Sep 23 14:27:42 2008 for jigdo by
1.5.6