From: Christian P. <cp...@us...> - 2005-06-22 11:35:35
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/App In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13726/include/pclasses/App Modified Files: Makefile.am Added Files: ConfigStore.h Config.h Log Message: - Added ConfigStore, ConfigValue, ConfigSection, Config --- NEW FILE: Config.h --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow, SecuLogiX GmbH * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_App_Config_h #define P_App_Config_h #include <pclasses/Export.h> #include <pclasses/Exception.h> #include <pclasses/StringList.h> #include <pclasses/Unicode/String.h> #include <pclasses/IO/IOError.h> #include <pclasses/IO/URL.h> #include <pclasses/App/ConfigStore.h> #include <string> namespace P { namespace App { class PAPP_EXPORT ConfigError: public RuntimeError { public: ConfigError(const char* what, const SourceInfo& si) throw(); ~ConfigError() throw(); }; class PAPP_EXPORT ConfigValue { public: ConfigValue(); ConfigValue(const std::string& value); ConfigValue(const Unicode::String& value); template <class StringType> ConfigValue(const StringList<StringType>& value) : _value(value.join(",")) { } ConfigValue(double value); ~ConfigValue() throw(); const Unicode::String& value() const throw(); private: Unicode::String _value; }; class PAPP_EXPORT ConfigSection { public: typedef std::list<ConfigSection*> section_list; typedef section_list::iterator section_iterator; typedef section_list::const_iterator section_const_iterator; typedef std::map<std::string, ConfigValue> value_map; typedef value_map::iterator value_iterator; typedef value_map::const_iterator value_const_iterator; const std::string& name() const throw(); section_iterator sectionsBegin() throw(); section_const_iterator sectionsBegin() const throw(); section_iterator sectionsEnd() throw(); section_const_iterator sectionsEnd() const throw(); section_iterator findSection(const std::string& name) throw(); section_const_iterator findSection(const std::string& name) const throw(); ConfigSection& section(const std::string& name, bool add = false) throw(ConfigError); bool removeSection(const std::string& name) throw(); value_iterator valuesBegin() throw(); value_const_iterator valuesBegin() const throw(); value_iterator valuesEnd() throw(); value_const_iterator valuesEnd() const throw(); value_iterator findValue(const std::string& name) throw(); value_const_iterator findValue(const std::string& name) const throw(); const ConfigValue& value(const std::string& name, bool add = false) throw(ConfigError); const ConfigValue& value(const std::string& name, const ConfigValue& defaultVal, bool add = false); void setValue(const std::string& name, const ConfigValue& val); bool removeValue(const std::string& name) throw(); bool hasValue(const std::string& name) const throw(); protected: friend class Config; ConfigSection(Config* cfg, const std::string& name); ~ConfigSection() throw(); private: Config* _cfg; std::string _name; section_list _sections; value_map _values; }; class PAPP_EXPORT Config { public: Config(const IO::URL& url, const std::string& cfgStoreType) throw(ConfigError, IO::IOError); ~Config() throw(); void reload() throw(IO::IOError); void save() throw(IO::IOError); void saveAs(const IO::URL& url, const std::string& cfgStoreType, bool clearModified = false) throw(ConfigError, IO::IOError); ConfigSection& root() throw(); protected: friend class ConfigSection; void setModified() throw(); private: static ConfigStore* createConfigStore(const std::string& cfgStoreType) throw(ConfigError); ConfigStore* _store; bool _modified; ConfigSection _root; }; } // !namespace App } // !namespace P #endif // !P_App_Config_h Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/App/Makefile.am,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Makefile.am 20 Jan 2005 11:05:56 -0000 1.4 +++ Makefile.am 22 Jun 2005 11:35:18 -0000 1.5 @@ -3,4 +3,5 @@ INCLUDES = METASOURCES = AUTO pclasses_app_include_HEADERS = AppDetails.h LogMessage.h LogTarget.h \ - LogChannel.h LogManager.h SimpleApp.h BackgroundApp.h CmdLine.h + LogChannel.h LogManager.h SimpleApp.h BackgroundApp.h CmdLine.h \ + ConfigStore.h Config.h --- NEW FILE: ConfigStore.h --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow, SecuLogiX GmbH * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_App_ConfigStore_h #define P_App_ConfigStore_h #include <pclasses/Export.h> #include <pclasses/IO/IOError.h> #include <pclasses/IO/URL.h> namespace P { namespace App { class Config; class PAPP_EXPORT ConfigStore { public: ConfigStore() throw(); virtual ~ConfigStore() throw(); void init(Config* cfg, const IO::URL& url) throw(); virtual void load() throw(IO::IOError) = 0; virtual void save() throw(IO::IOError) = 0; protected: Config* config() const throw(); const IO::URL& url() const throw(); private: Config* _config; IO::URL _url; }; } // !namespace App } // !namespace P #endif // !P_App_ConfigStore_h |