Ocular Engine
Exposable.hpp
1 
17 #pragma once
18 #ifndef __H__OCULAR_CORE_EXPOSABLE__H__
19 #define __H__OCULAR_CORE_EXPOSABLE__H__
20 
21 #include "ExposedVariable.hpp"
22 #include "Buildable.hpp"
23 
24 #include "Utilities/Types.hpp"
25 #include "Utilities/StringUtils.hpp"
26 
27 #include <string>
28 #include <unordered_map>
29 
30 //------------------------------------------------------------------------------------------
31 
36 namespace Ocular
37 {
42  namespace Core
43  {
44 
67  class Exposable
68  {
69  friend class Buildable;
70 
71  public:
72 
81  void getAllExposedNames(std::vector<std::string>& names) const;
82 
91  bool getVariable(std::string const& name, ExposedVariable& var);
92 
101  template<typename T>
102  bool getVariableValue(std::string const& name, T& var)
103  {
104  bool result = false;
105  auto find = m_ExposedVariables.find(name);
106 
107  if(find != m_ExposedVariables.end())
108  {
109  if(String::IsEqual(OCULAR_TYPE(T), find->second.type))
110  {
111  value = *(T*)(find->second.ptr);
112  result = true;
113  }
114  }
115 
116  return result;
117  }
118 
129  template<typename T>
130  bool setVariableValue(std::string const& name, T const& value)
131  {
132  bool result = false;
133  auto find = m_ExposedVariables.find(name);
134 
135  if(find != m_ExposedVariables.end())
136  {
137  if(String::IsEqual(OCULAR_TYPE(T), find->second.type))
138  {
139  *(find->second.ptr) = value;
140  result = true;
141  }
142  }
143 
144  return result;
145  }
146 
151  virtual void onVariableModified(std::string const& varName);
152 
153  protected:
154 
172  void exposeVariable(std::string const& name, std::string const& type, bool isPointer, bool isExposed, void* data);
173 
174  std::unordered_map<std::string, ExposedVariable> m_ExposedVariables;
175 
176  private:
177  };
178 
182 #define OCULAR_EXPOSE(X) exposeVariable(std::string(#X), Ocular::Utils::TypeName<decltype(X)>::name, std::is_pointer<decltype(X)>::value, std::is_base_of<Ocular::Core::Exposable, decltype(X)>::value, &X)
183  }
187 }
192 //------------------------------------------------------------------------------------------
193 
194 #endif
bool setVariableValue(std::string const &name, T const &value)
Definition: Exposable.hpp:130
Definition: Exposable.hpp:67
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
Definition: Buildable.hpp:54
void exposeVariable(std::string const &name, std::string const &type, bool isPointer, bool isExposed, void *data)
Definition: Exposable.cpp:67
bool getVariable(std::string const &name, ExposedVariable &var)
Definition: Exposable.cpp:44
void getAllExposedNames(std::vector< std::string > &names) const
Definition: Exposable.cpp:33
Definition: ExposedVariable.hpp:44
virtual void onVariableModified(std::string const &varName)
Definition: Exposable.cpp:58
bool getVariableValue(std::string const &name, T &var)
Definition: Exposable.hpp:102