• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/configuration/ConfigurationSettings.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #ifndef _configurationsettings_h
00018 #define _configurationsettings_h
00019 
00020 #include <spl/types.h>
00021 #include <spl/Debug.h>
00022 
00023 #include <spl/configuration/ConfigurationSection.h>
00024 #include <spl/io/DelimitedFile.h>
00025 #include <spl/collection/Hashtable.h>
00026 #include <spl/Memory.h>
00027 #include <spl/RefCountPtr.h>
00028 #include <spl/xml/XmlDocument.h>
00029 
00035 class ConfigurationSettings;
00036 typedef RefCountPtr<ConfigurationSettings> ConfigurationSettingsPtr;
00037 
00040 class ConfigurationSettings : public IMemoryValidate
00041 {
00042 protected:
00043         String m_filename;
00044         Hashtable<String, ConfigurationSection> m_sections;
00045 
00046 public:
00047         ConfigurationSettings(const String& filename);
00048         ConfigurationSettings(const ConfigurationSettings& config);
00049         ConfigurationSettings();
00050         virtual ~ConfigurationSettings();
00051 
00052         ConfigurationSettings& operator =(const ConfigurationSettings& config);
00053 
00054         ConfigurationSection& Section(const String& name);
00055 
00056         void Add(const String& section, const String& key, const String& value);
00057         bool ContainsKey(const String& section, const String& key);
00058         
00059         StringPtr Value(const String& section, const String& key);
00060         List<StringPtr>& Values(const String& section, const String& key);
00061 
00062         void Load(XmlDocument& appconfig);
00063         void Load(const DelimitedFile& inifile);
00064         void Load(const String& filename);
00065 
00066         StringPtr ToXmlString();
00067         StringPtr ToIniString();
00068 
00069         void SaveToIniFile(const String& filename);
00070         void SaveToXmlFile(const String& filename);
00071         void SaveToRegistry();
00072 
00073         static ConfigurationSettingsPtr LoadAppConfig();
00074 
00075 #ifdef DEBUG
00076         void ValidateMem() const;
00077         void CheckMem() const;
00078 #endif
00079 };
00080 
00081 REGISTER_TYPEOF( 410, ConfigurationSettings );
00082 
00085 #endif