Grail (C++)  1.3.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
BehaviorData.h
1 // Copyright QED Software 2023.
2 
3 #ifndef GRAIL_BEHAVIOR_DATA_H
4 #define GRAIL_BEHAVIOR_DATA_H
5 
6 #include <map>
7 #include <string>
8 
9 #include "Flatbuffers/BehaviorData_generated.h"
10 #include "Flatbuffers/StringStringMap_generated.h"
11 
12 namespace grail
13 {
14 namespace data
15 {
16  struct BehaviorData
17  {
18  std::string name{};
19  std::map<std::string, std::string> behaviorInstanceData{};
20  };
21 
22  inline flatbuffers::Offset<generated::BehaviorData> Pack(flatbuffers::FlatBufferBuilder& builder,
23  const BehaviorData& behaviorData)
24  {
25  std::vector<flatbuffers::Offset<generated::StringStringMap>> packedInstanceData{};
26  packedInstanceData.reserve(behaviorData.behaviorInstanceData.size());
27  std::for_each(behaviorData.behaviorInstanceData.begin(), behaviorData.behaviorInstanceData.end(),
28  [&packedInstanceData, &builder](const auto& instanceData)
29  {
30  packedInstanceData.push_back(generated::CreateStringStringMap(builder,
31  builder.CreateString(instanceData.first), builder.CreateString(instanceData.second)));
32  });
33  return generated::CreateBehaviorData(builder, builder.CreateString(behaviorData.name),
34  builder.CreateVector(packedInstanceData));
35  }
36 
37  inline BehaviorData Unpack(const generated::BehaviorData& behaviorData)
38  {
39  BehaviorData deserializedData{behaviorData.name()->str()};
40  for(const auto& instanceData : *behaviorData.behaviorInstanceData())
41  {
42  deserializedData.behaviorInstanceData.insert({instanceData->key()->str(), instanceData->value()->str()});
43  }
44  return deserializedData;
45  }
46 }
47 }
48 
49 #endif
grail::data::BehaviorData
Definition: BehaviorData.h:16