Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

SWConfig Class Reference

The class to read and save settings using a file on disk. More...

#include <swconfig.h>

List of all members.

Public Methods

 SWConfig (const char *ifilename)
 Constructor of SWConfig. More...

virtual ~SWConfig ()
virtual void Load ()
 Load from disk Load the contzent from disk.

virtual void Save ()
 Save to disk Save the content of this config object to disk.

virtual SWConfig & operator+= (SWConfig &addFrom)
 Merges the values of addFrom. More...

virtual ConfigEntMap & operator[] (const char *section)
 Get a section This is an easy way to get and store config values. More...


Public Attributes

string filename
 The filename used by this SWConfig object.

SectionMap Sections
 Map of available sections The map of available sections.


Private Methods

char getline (FILE *fp, string &line)


Detailed Description

The class to read and save settings using a file on disk.

Definition at line 44 of file swconfig.h.


Constructor & Destructor Documentation

SWConfig::SWConfig const char *    ifilename
 

Constructor of SWConfig.

Parameters:
ifilename  The file, which should be used for this config.

Definition at line 27 of file swconfig.cpp.

References filename, and Load().

00027                                          {
00028         filename = ifilename;
00029         Load();
00030 }


Member Function Documentation

SWConfig & SWConfig::operator+= SWConfig &    addFrom [virtual]
 

Merges the values of addFrom.

Parameters:
The  config which values should be merged to this config object. Already existing values will be overwritten.

Definition at line 134 of file swconfig.cpp.

References Sections.

00135 {
00136 
00137         SectionMap::iterator section;
00138         ConfigEntMap::iterator entry, start, end;
00139 
00140         for (section = addFrom.Sections.begin(); section != addFrom.Sections.end(); section++) {
00141                 for (entry = (*section).second.begin(); entry != (*section).second.end(); entry++) {
00142                         start = Sections[section->first].lower_bound(entry->first);
00143                         end   = Sections[section->first].upper_bound(entry->first);
00144                         if (start != end) {
00145                                 if (((++start) != end)
00146                                                 || ((++(addFrom.Sections[section->first].lower_bound(entry->first))) != addFrom.Sections[section->first].upper_bound(entry->first))) {
00147                                         for (--start; start != end; start++) {
00148                                                 if (!strcmp(start->second.c_str(), entry->second.c_str()))
00149                                                         break;
00150                                         }
00151                                         if (start == end)
00152                                                 Sections[(*section).first].insert(ConfigEntMap::value_type((*entry).first, (*entry).second));
00153                                 }
00154                                 else    Sections[section->first][entry->first.c_str()] = entry->second.c_str();
00155                         }               
00156                         else    Sections[section->first][entry->first.c_str()] = entry->second.c_str();
00157                 }
00158         }
00159         return *this;
00160 }

ConfigEntMap & SWConfig::operator[] const char *    section [virtual]
 

Get a section This is an easy way to get and store config values.

The following will work:

 SWConfig config("/home/user/.setttings");
 config["Colors"]["Background"] = "red";

Definition at line 163 of file swconfig.cpp.

References Sections.

00163                                                          {
00164     return Sections[section];
00165 }


The documentation for this class was generated from the following files:
Generated on Thu Jun 20 22:13:03 2002 for The Sword Project by doxygen1.2.15