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