00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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