(C++)  1.1.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
ParametrizedObject.h
1 #ifndef GRAIL_PARAMETRIZED_OBJECT_H
2 #define GRAIL_PARAMETRIZED_OBJECT_H
3 
4 #include "TypedObjectParameter.h"
5 #include "../../MemoryPool.hh"
6 
7 #include <string>
8 #include <unordered_map>
9 #include <unordered_set>
10 #include <set>
11 #include <map>
12 #include <memory>
13 #include <vector>
14 #include <functional>
15 
16 namespace grail
17 {
18  namespace planning
19  {
21  {
22  public:
23  virtual ~ParametrizedObject() = default;
24 
25  //REVIEW: dox comments
26  void MergeParameters(const ParametrizedObject& other);
27 
29  std::size_t GetParametersSize() const;
30 
32  bool Contains(const std::string& paramName) const;
33 
36  template<typename ParameterType>
37  void SetParameter(const std::string& paramName, const ParameterType& paramValue)
38  {
39  parameters[paramName] = &memory.template Emplace<TypedObjectParameter<ParameterType>>(paramValue);
40  }
41 
43  template<typename ParameterType>
44  ParameterType GetParameterValue(const std::string& paramName) const
45  {
46  auto param = GetParameter(paramName);
47  if (param != nullptr)
48  {
49  return param->GetValue<ParameterType>();
50  }
51  return ParameterType();
52  }
53 
55  bool CollectionContains(const std::string& collectionName, unsigned int objectIndex) const;
56 
58  void AddCollection(const std::string& collectionName);
59  std::set<unsigned int>* GetCollection(const std::string& name);
60  const std::set<unsigned int>* GetCollection(const std::string& name) const;
61 
62  bool HasEqualParams(const ParametrizedObject& other) const;
63  void SerializeSnapshot(std::map<std::string, std::string>& nameValues) const;
64  void SetSerializeSnapshotFunction(std::function<void(const ParametrizedObject& object, std::map<std::string, std::string>& nameValues)> function);
65 
66 
67  ParametrizedObject& operator = (const ParametrizedObject& other);
68  ParametrizedObject& operator=(ParametrizedObject&& other) = delete;
69 
70  protected:
73  ParametrizedObject(ParametrizedObject&& other) = default;
74 
75  std::map<std::string, ObjectParameter*> parameters{};
76  std::map<std::string, std::set<unsigned int>> indexCollections{};
77  MemoryPool& memory;
78 
79  private:
80  const ObjectParameter* GetParameter(const std::string& paramName) const;
81  ObjectParameter* GetParameter(const std::string& paramName);
82  std::function<void(const ParametrizedObject& object, std::map<std::string, std::string>&)> serializeSnapshotFunction = nullptr;
83  };
84  }
85 }
86 #endif //GRAIL_PARAMETRIZED_OBJECT_H
The MemoryPool class - preallocated memory container for optimization issues.
Definition: MemoryPool.hh:74
Definition: ParametrizedObject.h:21
ParameterType GetParameterValue(const std::string &paramName) const
Definition: ParametrizedObject.h:44
std::size_t GetParametersSize() const
Definition: ParametrizedObject.cpp:148
void SetParameter(const std::string &paramName, const ParameterType &paramValue)
Definition: ParametrizedObject.h:37
void AddCollection(const std::string &collectionName)
Creates a new id collection under the given name.
Definition: ParametrizedObject.cpp:79
bool Contains(const std::string &paramName) const
Definition: ParametrizedObject.cpp:64
bool CollectionContains(const std::string &collectionName, unsigned int objectIndex) const
Definition: ParametrizedObject.cpp:69