Game Develop Core: Variable.h Source File

| Game Develop Core Core library for developing platforms and tools compatible with Game Develop.

- Main Page
- Modules
- Classes

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Macros Groups Pages
Variable.h
Go to the documentation of this file.
1
6 #ifndef GDCORE_VARIABLE_H
7 #define GDCORE_VARIABLE_H
8 #include <string>
9 #include <map>
10 class TiXmlElement;
11
12 namespace gd
13 {
14
22 class GD_CORE_API Variable
23 {
24 public:
25
29 Variable() : value(0), isNumber(true), isStructure(false) {};
30 virtual ~Variable() {};
31
35
40 const std::string & GetString() const;
41
45 virtual void SetString(const std::string & newStr)
46 {
47 str = newStr;
48 isNumber = false;
49 isStructure = false;
50 }
51
55 double GetValue() const;
56
60 virtual void SetValue(double val)
61 {
62 value = val;
63 isNumber = true;
64 isStructure = false;
65 }
66
67 //Operators are overloaded to allow accessing to variable using a simple int-like semantic.
68 void operator=(double val) {SetValue(val);};
69 void operator+=(double val) {SetValue(val+GetValue());}
70 void operator-=(double val) {SetValue(GetValue()-val);}
71 void operator*=(double val) {SetValue(val*GetValue());}
72 void operator/=(double val) {SetValue(GetValue()/val);}
73
74 bool operator<=(double val) const { return GetValue() <= val;};
75 bool operator>=(double val) const { return GetValue() >= val;};
76 bool operator<(double val) const { return GetValue() < val;};
77 bool operator>(double val) const { return GetValue() > val;};
78 bool operator==(double val) const { return GetValue() == val;};
79 bool operator!=(double val) const { return GetValue() != val;};
80
81 //Operators are overloaded to allow accessing to variable using a simple string-like semantic.
82 void operator=(const std::string & val) {SetString(val);};
83 void operator+=(const std::string & val) {SetString(GetString()+val);}
84
85 bool operator==(const std::string & val) const { return GetString() == val;};
86 bool operator!=(const std::string & val) const { return GetString() != val;};
87
91 bool IsNumber() const { return !isStructure && isNumber; }
93
97
102 bool IsStructure() const { return isStructure; }
103
107 virtual bool HasChild(const std::string & name) const;
108
115 virtual Variable & GetChild(const std::string & name);
116
123 virtual const Variable & GetChild(const std::string & name) const;
124
131 void RemoveChild(const std::string & name);
132
136 const std::map<std::string, Variable> & GetAllChildren() const { return children; }
137
139
143
147 void SaveToXml(TiXmlElement * element) const;
148
152 void LoadFromXml(const TiXmlElement * element);
154
155
156 private:
157 mutable double value;
158 mutable std::string str;
159 mutable bool isNumber;
160 mutable bool isStructure;
161 mutable std::map<std::string, Variable> children;
162 };
163
164 }
165
166 #endif // GDCORE_VARIABLE_H