(C++)  1.0.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  void MergeParameters(const ParametrizedObject& other);
26 
28  std::size_t GetParametersSize() const;
29 
31  bool Contains(const std::string& paramName) const;
32 
35  template<typename ParameterType>
36  void SetParameter(const std::string& paramName, const ParameterType& paramValue)
37  {
38  parameters[paramName] = &memory.template Emplace<TypedObjectParameter<ParameterType>>(paramValue);
39  }
40 
42  template<typename ParameterType>
43  ParameterType GetParameterValue(const std::string& paramName) const
44  {
45  auto param = GetParameter(paramName);
46  if (param != nullptr)
47  {
48  return param->GetValue<ParameterType>();
49  }
50  return ParameterType();
51  }
52 
54  bool CollectionContains(const std::string& collectionName, unsigned int objectIndex) const;
55 
57  void AddCollection(const std::string& collectionName);
58  std::set<unsigned int>* GetCollection(const std::string& name);
59  const std::set<unsigned int>* GetCollection(const std::string& name) const;
60 
61  bool HasEqualParams(const ParametrizedObject& other) const;
62  void SerializeForGUI(std::map<std::string, std::string>& nameValues) const;
63  void SetSerializeForGUIFunction(std::function<void(const ParametrizedObject& object, std::map<std::string, std::string>& nameValues)> function);
64 
65  ParametrizedObject& operator = (const ParametrizedObject& other);
66  ParametrizedObject& operator=(ParametrizedObject&& other) = delete;
67 
68  protected:
71  ParametrizedObject(ParametrizedObject&& other) = default;
72 
73  std::map<std::string, ObjectParameter*> parameters{};
74  std::map<std::string, std::set<unsigned int>> indexCollections{};
75  MemoryPool& memory;
76 
77  private:
78  const ObjectParameter* GetParameter(const std::string& paramName) const;
79  ObjectParameter* GetParameter(const std::string& paramName);
80 
81  std::function<void(const ParametrizedObject& object, std::map<std::string, std::string>&)> serializeGUIFunction = nullptr;
82  };
83  }
84 }
85 #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:43
std::size_t GetParametersSize() const
Definition: ParametrizedObject.cpp:149
void SetParameter(const std::string &paramName, const ParameterType &paramValue)
Definition: ParametrizedObject.h:36
void AddCollection(const std::string &collectionName)
Creates a new id collection under the given name.
Definition: ParametrizedObject.cpp:80
bool Contains(const std::string &paramName) const
Definition: ParametrizedObject.cpp:65
bool CollectionContains(const std::string &collectionName, unsigned int objectIndex) const
Definition: ParametrizedObject.cpp:70