Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

IConfigManager.h

Go to the documentation of this file.
00001 // mortic - A game engine for the Expanses of Naryan.
00002 // Copyright (C) 2007  Aaron Griffith
00003 // This file is under the LGPL. See mortic.h for more information.
00004 
00006 //   _____             __ _       __  __                                      //
00007 //  / ____|           / _(_)     |  \/  |                                     //
00008 // | | $   ___  _ __ | |_ _  __ _| \  / | __ _ _ __   __ _  __ _  ___ _ __    //
00009 // | | $  / _ \| '_ \|  _| |/ _` | |\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '__|   //
00010 // | |___| (_) | | | | | | | (_| | |  | | (_| | | | | (_| | (_| |  __/ |      //
00011 //  \_____\___/|_| |_|_| |_|\__, |_|  |_|\__,_|_| |_|\__,_|\__, |\___|_|      //
00012 //                           __/ |                          __/ |             //
00013 //                          |___/                          |___/              //
00014 // IConfigManager.h - Interface of ConfigManager                              //
00016 
00017 #ifndef __IConfigManager_h_INCLUDED__
00018 #define __IConfigManager_h_INCLUDED__
00019 
00020 #include "IRoot.h"
00021 #include "IObject.h"
00022 
00023 #include <sstream>
00024 #include <vector>
00025 #include <string>
00026 
00027 namespace mortic
00028 {
00030         
00039         class IConfigSet
00040         {
00041         friend class IRoot;
00042         public:
00044                 IConfigSet()
00045                 { }
00047                 ~IConfigSet()
00048                 { }
00049                 
00051                 
00057         void setOption(std::string section, std::string key, std::string value)
00058         {
00059                 sections.push_back(section);
00060                 keys.push_back(key);
00061                 values.push_back(value);
00062         }
00063 
00064         std::vector<std::string> sections;
00065         std::vector<std::string> keys;
00066         std::vector<std::string> values;
00067     };
00068                 
00070     
00091     class IConfigManager : public IObject
00092     {
00093     public:
00095         
00098         IConfigManager(IRoot* root) : IObject(root, "ConfigManager")
00099         { }
00100         
00102         
00104         virtual ~IConfigManager()
00105         { }
00106         
00108         
00119         virtual std::string getOption(std::string section, std::string key, std::string def) = 0;
00120         
00122         
00130         template<typename T> T getOption(std::string section, std::string key, T def)
00131         {
00132             std::stringstream out;
00133             std::stringstream in;
00134             T outvar;
00135             out << def;
00136             in << getOption(section, key, out.str());
00137             in >> outvar;
00138             return outvar;
00139         }
00140         
00142         
00147         virtual void setOption(std::string section, std::string key, std::string value) = 0;
00148         
00150         
00157         template<typename T> void setOption(std::string section, std::string key, T value)
00158         {
00159                 std::stringstream tmp;
00160                 tmp << value;
00161                 setOption(section, key, tmp.str());
00162         }
00163         
00164         // Loads configuration from a file.
00165         
00166         // This loads all the values in the given file into the manager
00167         // \arg \b file - the filename to read from
00168         // \sa writeConfig()
00169         //virtual void loadConfig(std::string file) = 0;
00170         
00171         // Saves configuration to a file.
00172         
00173         // This saves all the current values to the given file.
00174         // \arg \b file - the filename to write to
00175         // \sa loadConfig()
00176         //virtual void writeConfig(std::string file) = 0;
00177     };
00178 
00179 }
00180 ; // namespace mortic
00181 #endif // __IConfigManager_h_INCLUDED__

Generated on Sat Dec 30 21:21:59 2006 for mortic by  doxygen 1.4.4