swconfig.h

00001 /******************************************************************************
00002  *  swconfig.h   - definition of Class SWConfig used for saving and retrieval
00003  *                              of configuration information
00004  *
00005  * $Id: swconfig.h 2094 2007-09-29 00:34:03Z chrislit $
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 <map>
00027 
00028 #include <defs.h>
00029 #include <multimapwdef.h>
00030 #include <swbuf.h>
00031 
00032 SWORD_NAMESPACE_START
00033 
00034 typedef multimapwithdefault < SWBuf, SWBuf, std::less < SWBuf > >ConfigEntMap;
00035 typedef std::map < SWBuf, ConfigEntMap, std::less < SWBuf > >SectionMap;
00036 
00040 class SWDLLEXPORT SWConfig {
00041 private:
00042         char getline(int fd, SWBuf &line);
00043 public:
00047         SWBuf filename;
00051         SectionMap Sections;
00052 
00056         SWConfig(const char *ifilename);
00057         virtual ~SWConfig();
00058 
00062         virtual void Load();
00063 
00067         virtual void Save();
00068 
00072         virtual void augment(SWConfig &addFrom);
00073         virtual SWConfig & operator +=(SWConfig &addFrom) { augment(addFrom); return *this; }
00074 
00084         virtual ConfigEntMap & operator [](const char *section);
00085         };
00086 SWORD_NAMESPACE_END
00087 #endif