00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 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
00037
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