(C++)  1.0.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
ObjectParameter.h
1 #ifndef GRAIL_OBJECT_PARAMETER_H
2 #define GRAIL_OBJECT_PARAMETER_H
3 
4 #include "../../../GrailSystem/consts.h"
5 #include "../../../GrailSystem/Logger/LoggerManager.hh"
6 
7 #include <memory>
8 #include <string>
9 #include <sstream>
10 #include <typeindex>
11 
12 namespace grail
13 {
14  class MemoryPool;
15  namespace planning
16  {
18  {
19  public:
20  template<typename ParameterType>
21  const ParameterType& GetValue() const
22  {
23  if (type != std::type_index{ typeid(ParameterType) })
24  GRAIL_LOG(consts::DEFAULT_GRAIL_LOG_GROUP, Severity::CRITICAL, "Getting value with inappriopriate type\n");
25 
26  return *(static_cast<const ParameterType*>(GetUncastValue()));
27  }
28 
29  template<typename ParameterType>
30  void SetValue(const ParameterType& value)
31  {
32  if (type != std::type_index{ typeid(ParameterType) })
33  GRAIL_LOG(consts::DEFAULT_GRAIL_LOG_GROUP, Severity::CRITICAL, "Setting value with inappriopriate type\n");
34 
35  ParameterType* val = static_cast<ParameterType*>(GetUncastValue());
36  *val = value;
37  }
38 
39  virtual ObjectParameter* Clone(MemoryPool& memory) const = 0;
40  virtual bool operator==(const ObjectParameter& other) const = 0;
41  virtual bool operator < (const ObjectParameter& other) const = 0;
42 
43  protected:
44  ObjectParameter(std::type_index type)
45  : type{ type }
46  {
47  }
48 
49  ObjectParameter(const ObjectParameter&) = default;
50  ObjectParameter(ObjectParameter&&) = default;
51 
52  ObjectParameter& operator = (const ObjectParameter&) = default;
53  ObjectParameter& operator = (ObjectParameter&&) = default;
54 
55  virtual const void* GetUncastValue() const = 0;
56  virtual void* GetUncastValue() = 0;
57 
58  private:
59  std::type_index type;
60  };
61  }
62 }
63 #endif //GRAIL_OBJECT_PARAMETER_H
The MemoryPool class - preallocated memory container for optimization issues.
Definition: MemoryPool.hh:74
Definition: ObjectParameter.h:18