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>

List of all members.


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 &sectName)
 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 &sectName, 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]

Change reporter for error messages.

Referenced by JigdoConfig::JigdoConfig().

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

Output to file.

Referenced by operator<<().

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().

size_t ConfigFile::size (  )  const [inline]

Referenced by empty(), and main().

bool ConfigFile::empty (  )  const [inline]

References size().

ConfigFile::iterator ConfigFile::begin (  )  [inline]

Referenced by rescan().

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]

References ConfigFile::iterator::p, and x.

Referenced by push_back().

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]

void ConfigFile::push_back (  )  [inline]

References insert().

Referenced by get().

void ConfigFile::push_back ( const string &  s  )  [inline]

References back(), and insert().

void ConfigFile::push_back ( const char *  s  )  [inline]

References back(), and insert().

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]

Is character a space or tab?

Referenced by isWhitespace(), and rescan().

template<class Container>
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().

Referenced by ap(), as(), and main().

string & ConfigFile::quote ( string &  s  )  [static]

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 \.

Returns reference to s.

References out, and Paranoid.


The documentation for this class was generated from the following files:

Generated on Tue Sep 23 14:27:42 2008 for jigdo by  doxygen 1.5.6