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