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