Grail (C++)  1.1.1
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 "../../../GrailCore/consts.h"
5 #include "../../../GrailLogger/LoggerManager.hh"
6 
7 #include <memory>
8 #include <sstream>
9 #include <string>
10 #include <typeindex>
11 
12 namespace grail
13 {
14  class MemoryPool;
15 
16  namespace planning
17  {
19  {
20  public:
21  template <typename ParameterType>
22  const ParameterType& GetValue() const
23  {
24  if(type != std::type_index{typeid(ParameterType)})
25  {
26  GRAIL_LOG(consts::DEFAULT_GRAIL_LOG_GROUP,
27  Severity::CRITICAL,
28  "Getting value with inappriopriate type\n");
29  }
30 
31  return *(static_cast<const ParameterType*>(GetUncastValue()));
32  }
33 
34  template <typename ParameterType>
35  void SetValue(const ParameterType& value)
36  {
37  if(type != std::type_index{typeid(ParameterType)})
38  {
39  GRAIL_LOG(consts::DEFAULT_GRAIL_LOG_GROUP,
40  Severity::CRITICAL,
41  "Setting value with inappriopriate type\n");
42  }
43 
44  ParameterType* val = static_cast<ParameterType*>(GetUncastValue());
45  *val = value;
46  }
47 
48  virtual ObjectParameter* Clone(MemoryPool& memory) const = 0;
49  virtual bool operator==(const ObjectParameter& other) const = 0;
50  virtual bool operator <(const ObjectParameter& other) const = 0;
51 
52  protected:
53  ObjectParameter(std::type_index type)
54  : type{type}
55  {
56  }
57 
58  ObjectParameter(const ObjectParameter&) = default;
59  ObjectParameter(ObjectParameter&&) = default;
60 
61  ObjectParameter& operator =(const ObjectParameter&) = default;
62  ObjectParameter& operator =(ObjectParameter&&) = default;
63 
64  virtual const void* GetUncastValue() const = 0;
65  virtual void* GetUncastValue() = 0;
66 
67  private:
68  std::type_index type;
69  };
70  }
71 }
72 #endif //GRAIL_OBJECT_PARAMETER_H
grail::MemoryPool
The MemoryPool class - preallocated memory container for optimization issues.
Definition: MemoryPool.hh:73
grail::planning::ObjectParameter
Definition: ObjectParameter.h:18