src/config.hpp

Go to the documentation of this file.
00001 //
00002 // Ephi - simulation of magnetic fields and particles
00003 // Copyright (C) 2007 Indrek Mandre <indrek(at)mare.ee>
00004 // For more information please see http://www.mare.ee/indrek/
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 2 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License along
00017 // with this program; if not, write to the Free Software Foundation, Inc.,
00018 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00019 //
00020 
00021 #ifndef __config_hpp__
00022 #define __config_hpp__
00023 
00024 #include <vector>
00025 #include <string>
00026 #include <list>
00027 #include <map>
00028 
00029 #include "math3d.hpp"
00030 
00032 class Config
00033 {
00034 public:
00035   void reg_num (const char *group, const char *name, prec_t deflt = 0.0);
00036   void reg_vect3d (const char *group, const char *name, const vect3d& dflt = vect3d(0, 0, 0));
00037   void reg_bool (const char *group, const char *name, bool dflt = false);
00038   void reg_enum (const char *group, const char *name, const char *dflt, ...);
00039   void reg_str (const char *group, const char *name, const char *dflt = "");
00040 
00041   bool select_group (const char *name, size_t index);
00042 
00043   const char * get_str (const char *name);
00044   const char * get_enum (const char *name);
00045   prec_t get_prec (const char *name);
00046   size_t get_size (const char *name);
00047   vect3d& get_vect3d (const char *name, vect3d& res);
00048   bool get_bool (const char *name);
00049 
00050   bool load (const char *path);
00051 
00052 private:
00053 
00054   struct type_t;
00055 
00056   struct value_t
00057   {
00058     value_t() : value_prec(0) { }
00059     type_t *t;
00060     prec_t value_prec;
00061     vect3d value_vect3d;
00062     bool value_bool;
00063     std::string value_enum;
00064     std::string value_str;
00065   };
00066 
00067   struct group_t;
00068 
00069   struct type_t
00070   {
00071     enum et { PREC, VECT3D, BOOL, ENUM, STR };
00072     et t;
00073     std::string name;
00074     group_t *group;
00075     std::list<std::string> enums;
00076     value_t dflt;
00077   };
00078 
00079   typedef std::map<std::string, type_t> types_t;
00080   types_t types;
00081 
00082   typedef std::map<std::string, value_t> values_t;
00083 
00084   struct group_t
00085   {
00086     group_t() : ref(0) { }
00087     std::string name;
00088     std::vector<values_t> instances;
00089     values_t *ref;
00090   };
00091 
00092   typedef std::map<std::string, group_t> groups_t;
00093   groups_t groups;
00094 
00095   value_t& get_value (const char *name, type_t::et t);
00096 };
00097 
00098 #endif // !__config_hpp__
00099 

Generated on Thu Dec 6 20:31:14 2007 for Ephi by  doxygen 1.5.0