00001
00002
00003
00004
00005
00007
00008 #ifndef HGEPROPERTIES_H__
00009 #define HGEPROPERTIES_H__
00010
00011
00012 #include <string>
00013 #include <vector>
00014 #include <ios>
00015 #include <sstream>
00016
00017
00018 #include "hgeResourceReader.h"
00019
00020
00022
00023
00024 struct hgeKeyValue
00025 {
00026 std::string keyName;
00027 std::string keyValue;
00028
00029 std::string datatype;
00030
00031 hgeKeyValue() { return; }
00032 hgeKeyValue(std::string nam, std::string val) { keyName = nam; keyValue = val; }
00033 hgeKeyValue(std::string nam, int val) { keyName = nam; char tmp[16]; sprintf_s(tmp, "%i", val); keyValue = tmp; }
00034 hgeKeyValue(std::string nam, float val) { keyName = nam; char tmp[16]; sprintf_s(tmp, "%.6f", val); keyValue = tmp; }
00035 hgeKeyValue(std::string nam, DWORD col) { keyName = nam; char tmp[16]; sprintf_s(tmp, "0x%2d%2d%2d%2d", GETA(col), GETR(col), GETG(col), GETB(col)); keyValue = tmp; }
00036
00037
00038 hgeKeyValue(const hgeKeyValue &b)
00039 {
00040 keyName = b.keyName;
00041 keyValue = b.keyValue;
00042 }
00043 };
00044
00045
00047
00048
00049 class hgeProperties
00050 {
00051 protected:
00052
00053
00054 std::vector<hgeKeyValue> kv;
00055
00056
00057 std::string ReadString(hgeResourceReader *fil);
00058
00059 public:
00060
00061
00062 std::string classname;
00063
00064
00065 inline hgeKeyValue GetProperty(int index) { return kv[index]; }
00066
00067
00068 hgeKeyValue GetProperty(std::string name);
00069
00070
00071 inline int GetPropertyCount() { return (int)kv.size(); }
00072
00073
00074 inline std::string GetString(std::string name)
00075 {
00076 return GetProperty(name).keyValue;
00077 }
00078
00079
00080 inline float GetFloat(std::string name)
00081 {
00082 return (float)atof(GetProperty(name).keyValue.c_str());
00083 }
00084
00085
00086 inline int GetInt(std::string name)
00087 {
00088 return atoi(GetProperty(name).keyValue.c_str());
00089 }
00090
00091
00092 DWORD GetColor(std::string name);
00093
00094
00095 bool EditProperty(std::string name, std::string value);
00096 bool EditProperty(int index, std::string value);
00097
00098
00099 inline void AddProperty(std::string name, std::string value) { kv.push_back(hgeKeyValue(name, value)); }
00100 inline void AddProperty(std::string name, int value) { kv.push_back(hgeKeyValue(name, value)); }
00101 inline void AddProperty(std::string name, float value) { kv.push_back(hgeKeyValue(name, value)); }
00102 inline void AddProperty(std::string name, DWORD col) { kv.push_back(hgeKeyValue(name, col)); }
00103
00104
00105 inline void AddProperty(hgeKeyValue kvpair)
00106 {
00107 kv.push_back(kvpair);
00108 }
00109
00110
00111 void Copy(hgeProperties *props);
00112
00113
00114 void Load(hgeResourceReader *fil);
00115
00116 inline void Clear()
00117 {
00118 classname = "";
00119 kv.clear();
00120 }
00121
00122
00123 hgeProperties() {}
00124
00125 hgeProperties(hgeProperties *props)
00126 {
00127 Copy(props);
00128 }
00129 };
00130
00131 #endif