-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathentitystorage.hpp
More file actions
54 lines (51 loc) · 2.01 KB
/
entitystorage.hpp
File metadata and controls
54 lines (51 loc) · 2.01 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
#pragma once
#include <fea/config.hpp>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <set>
#include <typeindex>
#include <fea/assert.hpp>
namespace fea
{
class FEA_API EntityStorage
{
class StorageEntity
{
public:
StorageEntity(const std::set<std::string>& attributeList);
template<class DataType>
void setData(const std::string& attribute, DataType inData);
template<class DataType>
const DataType& getData(const std::string& attribute) const;
template<class DataType>
DataType& getData(const std::string& attribute);
bool hasData(const std::string& attribute) const;
std::unordered_set<std::string> getAttributes() const;
private:
std::unordered_map<std::string, std::shared_ptr<void>> attributeData;
};
public:
EntityStorage();
uint32_t addEntity(const std::set<std::string>& attributeList);
void removeEntity(uint32_t id);
template<class DataType>
void registerAttribute(const std::string& attribute);
template<class DataType>
void setData(const uint32_t id, const std::string& attribute, DataType inData);
template<class DataType>
const DataType& getData(const uint32_t id, const std::string& attribute) const;
template<class DataType>
DataType& getData(const uint32_t id, const std::string& attribute);
bool hasData(const uint32_t id, const std::string& attribute) const;
bool attributeIsValid(const std::string& attribute) const;
void clear();
std::unordered_set<std::string> getAttributes(uint32_t id) const;
std::unordered_map<std::string, std::type_index> mAttributes;
std::unordered_map<uint32_t, StorageEntity> mEntities;
std::stack<uint32_t> mFreeIds;
uint32_t mNextId;
};
#include <fea/entity/entitystorage.inl>
}