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

swconfig.h

00001 /******************************************************************************
00002  *  swconfig.h   - definition of Class SWConfig used for saving and retrieval
00003  *                              of configuration information
00004  *
00005  * $Id: swconfig.h-source.html,v 1.10 2001/05/25 10:44:22 jansorg Exp $
00006  *
00007  * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
00008  *      CrossWire Bible Society
00009  *      P. O. Box 2528
00010  *      Tempe, AZ  85280-2528
00011  *
00012  * This program is free software; you can redistribute it and/or modify it
00013  * under the terms of the GNU General Public License as published by the
00014  * Free Software Foundation version 2.
00015  *
00016  * This program is distributed in the hope that it will be useful, but
00017  * WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * General Public License for more details.
00020  *
00021  */
00022 
00023 #ifndef SWCONFIG_H
00024 #define SWCONFIG_H
00025 
00026 #include <stdio.h>
00027 
00028 #include <string>
00029 #include <map>
00030 
00031 #include <defs.h>
00032 
00033 using namespace std;
00034 
00035 
00036 // multmap that still lets you use [] to reference FIRST
00037 // entry of a key if multiples exist
00038 template <class Key, class T, class Compare>
00039 class multimapwithdefault : public multimap<Key, T, Compare> {
00040 public:
00041   typedef pair<const Key, T> value_type;
00042     T& operator[](const Key& k) {
00043         if (find(k) == end()) {
00044             insert(value_type(k, T()));
00045         }
00046         return (*(find(k))).second;
00047     }
00048 };
00049 
00050 typedef multimapwithdefault < string, string, less < string > >ConfigEntMap;
00051 typedef map < string, ConfigEntMap, less < string > >SectionMap;
00052 
00056 class SWDLLEXPORT SWConfig
00057 {
00058 private:
00059   char getline (FILE * fp, string & line);
00060 public:
00064   string filename;
00068   SectionMap Sections;
00069 
00073   SWConfig (const char *ifilename);
00074   virtual ~ SWConfig ();
00075 
00079   virtual void Load ();
00083   virtual void Save ();
00087   virtual SWConfig & operator += (SWConfig & addFrom);
00094   virtual ConfigEntMap & operator [] (const char *section);
00095 };
00096 
00097 #endif

Generated at Thu May 24 19:50:26 2001 for The Sword Project by doxygen1.1.5 written by Dimitri van Heesch, © 1997-2000