-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathentitystorage.cpp
More file actions
84 lines (68 loc) · 2.13 KB
/
entitystorage.cpp
File metadata and controls
84 lines (68 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <string>
#include <fea/entity/entitystorage.hpp>
namespace fea
{
EntityStorage::StorageEntity::StorageEntity(const std::set<std::string>& attributeList)
{
for(const auto& attribute : attributeList)
attributeData.emplace(attribute, std::shared_ptr<void>());
}
bool EntityStorage::StorageEntity::hasData(const std::string& attribute) const
{
return attributeData.find(attribute) != attributeData.end();
}
std::unordered_set<std::string> EntityStorage::StorageEntity::getAttributes() const
{
std::unordered_set<std::string> result;
for(auto& attribute : attributeData)
result.insert(attribute.first);
return result;
}
EntityStorage::EntityStorage() : mNextId(0)
{
}
uint32_t EntityStorage::addEntity(const std::set<std::string>& attributeList)
{
uint32_t newId;
if(mFreeIds.size() != 0)
{
newId = mFreeIds.top();
mFreeIds.pop();
}
else
{
newId = mNextId;
mNextId++;
}
for(auto& attribute : attributeList)
{
FEA_ASSERT(mAttributes.find(attribute) != mAttributes.end(), "Trying to create an entity with the attribute '" + attribute + "' which is invalid!");
}
mEntities.emplace(newId, StorageEntity(attributeList));
return newId;
}
void EntityStorage::removeEntity(uint32_t id)
{
mEntities.erase(id);
mFreeIds.push(id);
}
bool EntityStorage::hasData(const uint32_t id, const std::string& attribute) const
{
return mEntities.at(id).hasData(attribute);
}
bool EntityStorage::attributeIsValid(const std::string& attribute) const
{
return mAttributes.find(attribute) != mAttributes.end();
}
void EntityStorage::clear()
{
mAttributes.clear();
mEntities.clear();
mFreeIds = std::stack<uint32_t>();
mNextId = 0;
}
std::unordered_set<std::string> EntityStorage::getAttributes(uint32_t id) const
{
return mEntities.at(id).getAttributes();
}
}