Hummingbird Framework
 All Classes Functions Variables Modules Pages
DataRepository.h
1 #ifndef HB_DATA_REPOSITORY_H
2 #define HB_DATA_REPOSITORY_H
3 #include <string>
4 #include <unordered_map>
5 
6 namespace hb
7 {
13  {
14  public:
16  ~DataRepository();
17 
18  void setInt(const std::string& name, int value);
19  int getInt(const std::string& name, int default_value = -1);
20  void setUInt(const std::string& name, unsigned int value);
21  int getUInt(const std::string& name, unsigned int default_value = 0);
22  void setDouble(const std::string& name, double value);
23  double getDouble(const std::string& name, double default_value = -1.);
24  void setFloat(const std::string& name, float value);
25  float getFloat(const std::string& name, float default_value = -1.f);
26  void setChar(const std::string& name, char value);
27  char getChar(const std::string& name, char default_value = 0x00);
28  void setBool(const std::string& name, bool value);
29  bool getBool(const std::string& name, bool default_value = false);
30  void setPointer(const std::string& name, void* value);
31  template <typename T>
32  T* getPointer(const std::string& name, T* default_value = nullptr)
33  {
34  auto it = m_data.find(name);
35  if (it != m_data.end())
36  return static_cast<T*>(m_data[name].p);
37  return default_value;
38  }
39 
40  private:
41  union Data
42  {
43  int i;
44  unsigned int ui;
45  double d;
46  float f;
47  char c;
48  bool b;
49  void* p;
50  };
51  std::unordered_map<std::string, Data> m_data;
52  };
53 }
54 #endif
Definition: DataRepository.h:12
Definition: Box2DPlugin.h:6