3 #ifndef GRAIL_ENTITY_GROUP_DATA_H
4 #define GRAIL_ENTITY_GROUP_DATA_H
7 #include "BlackboardState.h"
8 #include "Flatbuffers/EntityGroupData_generated.h"
9 #include "Flatbuffers/UintVectorOfStringMap_generated.h"
19 std::vector<unsigned int> entityIds{};
20 std::vector<BlackboardState> groupSharedBlackboardStates{};
21 std::map<unsigned int, std::vector<std::string>> groupBlackboardConnections{};
22 std::map<unsigned int, std::vector<std::string>> globalBlackboardConnections{};
25 inline flatbuffers::Offset<generated::EntityGroupData> Pack(flatbuffers::FlatBufferBuilder& builder,
28 std::vector<flatbuffers::Offset<generated::UintVectorOfStringMap>> packedGroupConnections{};
29 packedGroupConnections.reserve(entityGroupData.groupBlackboardConnections.size());
30 std::vector<flatbuffers::Offset<generated::UintVectorOfStringMap>> packedGlobalConnections{};
31 packedGlobalConnections.reserve(entityGroupData.globalBlackboardConnections.size());
32 std::vector<unsigned int> packedEntityIds{};
33 packedEntityIds.reserve(entityGroupData.entityIds.size());
34 std::vector<flatbuffers::Offset<generated::BlackboardState>> packedBlackboardStates{};
35 packedBlackboardStates.reserve(entityGroupData.groupSharedBlackboardStates.size());
36 std::for_each(entityGroupData.groupBlackboardConnections.begin(), entityGroupData.groupBlackboardConnections.end(),
37 [&packedGroupConnections, &builder](
const auto& connection)
39 packedGroupConnections.push_back(generated::CreateUintVectorOfStringMap(builder,
40 connection.first, builder.CreateVectorOfStrings(connection.second)));
42 std::for_each(entityGroupData.globalBlackboardConnections.begin(), entityGroupData.globalBlackboardConnections.end(),
43 [&packedGlobalConnections, &builder](
const auto& connection)
45 packedGlobalConnections.push_back(generated::CreateUintVectorOfStringMap(builder,
46 connection.first, builder.CreateVectorOfStrings(connection.second)));
48 std::for_each(entityGroupData.entityIds.begin(), entityGroupData.entityIds.end(), [&packedEntityIds](
const auto& entityId)
50 packedEntityIds.emplace_back(entityId);
52 std::for_each(entityGroupData.groupSharedBlackboardStates.begin(), entityGroupData.groupSharedBlackboardStates.end(),
53 [&packedBlackboardStates, & builder](
const auto& state)
55 packedBlackboardStates.emplace_back(Pack(builder, state));
57 return generated::CreateEntityGroupData(builder, builder.CreateString(entityGroupData.name), entityGroupData.id,
58 builder.CreateVector(packedEntityIds), builder.CreateVector(packedBlackboardStates),
59 builder.CreateVector(packedGroupConnections),
60 builder.CreateVector(packedGlobalConnections));
63 inline EntityGroupData Unpack(
const generated::EntityGroupData& entityGroupData)
65 EntityGroupData deserializedData{entityGroupData.name()->str(), entityGroupData.id()};
67 deserializedData.entityIds.reserve(entityGroupData.entityIds()->size());
68 for(
const auto&
id : *entityGroupData.entityIds())
70 deserializedData.entityIds.emplace_back(
id);
72 deserializedData.groupSharedBlackboardStates.reserve(entityGroupData.groupSharedBlackboardStates()->size());
73 for(
const auto& blackboardState : *entityGroupData.groupSharedBlackboardStates())
75 deserializedData.groupSharedBlackboardStates.emplace_back(Unpack(*blackboardState));
77 for(
const auto& groupConnection : *entityGroupData.groupBlackboardConnections())
79 std::vector<std::string> blackboardIds{};
80 for(
const auto& entry : *groupConnection->value())
82 blackboardIds.emplace_back(entry->str());
84 deserializedData.groupBlackboardConnections.insert({groupConnection->key(), blackboardIds});
86 for(
const auto& globalConnection : *entityGroupData.globalBlackboardConnections())
88 std::vector<std::string> blackboardIds{};
89 for(
const auto& entry : *globalConnection->value())
91 blackboardIds.emplace_back(entry->str());
93 deserializedData.globalBlackboardConnections.insert({globalConnection->key(), blackboardIds});
95 return deserializedData;