Configuration.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2000-2002  The Exult Team
00003  *
00004  *  This program 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 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program 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 this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifndef _Configuration_h_
00020 #define _Configuration_h_
00021 
00022 
00023 #include "XMLEntity.h"
00024 
00025 class Configuration
00026 {
00027 public:
00028   Configuration()
00029                : xmltree(new XMLnode("config")), rootname("config"), filename(), is_file(false)
00030     { }
00031   Configuration(const std::string &fname, const std::string &root)
00032                : xmltree(new XMLnode(root)), rootname(root), filename(), is_file(false)
00033     { if(fname.size()) read_config_file(fname); }
00034 
00035   ~Configuration() { if(xmltree!=0) delete xmltree; };
00036   
00037   bool  read_config_file(const std::string &input_filename, const std::string &root=std::string());
00038   bool  read_abs_config_file(const std::string &input_filename, const std::string &root=std::string());
00039   
00040   bool  read_config_string(const std::string &);
00041   
00042   void  value(const std::string &key, std::string &ret, const char *defaultvalue="") const;
00043   void  value(const std::string &key, bool &ret, bool defaultvalue=false) const;
00044   void  value(const std::string &key, int &ret, int defaultvalue=0) const;
00045   
00046   void  value(const char *key, std::string &ret, const char *defaultvalue="") const
00047       { value(std::string(key), ret, defaultvalue); };
00048   void  value(const char *key, bool &ret, bool defaultvalue=false) const
00049       { value(std::string(key), ret, defaultvalue); };
00050   void  value(const char *key, int &ret, int defaultvalue=0) const
00051       { value(std::string(key), ret, defaultvalue); };
00052   
00053   void    set(const std::string &key, const std::string &value, bool write_to_file);
00054   void    set(const char *key,const char *value,bool write_to_file);
00055   void    set(const char *key,const std::string &value,bool write_to_file);
00056   void    set(const char *key,int,bool write_to_file);
00057 
00058   // Return a list of keys that are subsidiary to the supplied key
00059   std::vector<std::string>  listkeys(const std::string &key,bool longformat=true);
00060   std::vector<std::string>  listkeys(const char *key,bool longformat=true);
00061 
00062   std::string dump(void); // Assembles a readable representation
00063   std::ostream &dump(std::ostream &o, const std::string &indentstr);
00064 
00065   void  write_back(void);
00066 
00067   void clear(const std::string &new_root=std::string());
00068   
00069   typedef XMLnode::KeyType     KeyType;
00070   typedef XMLnode::KeyTypeList KeyTypeList;
00071   
00072   void getsubkeys(KeyTypeList &ktl, const std::string &basekey);
00073   
00074 private:
00075   XMLnode *xmltree;
00076   std::string rootname;
00077   std::string filename;
00078   bool  is_file;
00079 };
00080 
00081 // Global Config
00082 extern Configuration *config;
00083 
00084 #endif

Generated on Mon Jul 9 14:42:44 2007 for ExultEngine by  doxygen 1.5.1