35 #define RESOURCEMANAGERT_CC 37 #include "ResourceManager.hh" 38 #include "PropertyDefines.hh" 39 #include "TypeName.hh" 45 VertexPropertyT<T> ResourceManager::request_vertex_property(
const std::string& _name,
const T _def) {
47 return request_property<T, Entity::Vertex>(_name, _def);
51 EdgePropertyT<T> ResourceManager::request_edge_property(
const std::string& _name,
const T _def) {
53 return request_property<T, Entity::Edge>(_name, _def);
57 HalfEdgePropertyT<T> ResourceManager::request_halfedge_property(
const std::string& _name,
const T _def) {
59 return request_property<T, Entity::HalfEdge>(_name, _def);
63 FacePropertyT<T> ResourceManager::request_face_property(
const std::string& _name,
const T _def) {
65 return request_property<T, Entity::Face>(_name, _def);
69 HalfFacePropertyT<T> ResourceManager::request_halfface_property(
const std::string& _name,
const T _def) {
70 return request_property<T, Entity::HalfFace>(_name, _def);
74 CellPropertyT<T> ResourceManager::request_cell_property(
const std::string& _name,
const T _def) {
76 return request_property<T, Entity::Cell>(_name, _def);
80 MeshPropertyT<T> ResourceManager::request_mesh_property(
const std::string& _name,
const T _def) {
82 return request_property<T, Entity::Mesh>(_name, _def);
85 template<
typename T,
typename EntityTag>
86 PropertyTT<T, EntityTag>* ResourceManager::internal_find_property(
const std::string& _name)
88 using PropT = PropertyTT<T, EntityTag>;
89 auto type_name = get_type_name<T>();
90 auto &propVec = entity_props<EntityTag>();
93 for(
auto &prop: propVec)
95 if(prop->name() == _name
96 && prop->internal_type_name() == type_name)
98 return static_cast<PropT*
>(prop);
105 template<
class T,
class EntityTag>
106 PropertyTT<T, EntityTag> ResourceManager::internal_create_property(
const std::string& _name,
const T _def)
108 auto type_name = get_type_name<T>();
109 auto &propVec = entity_props<EntityTag>();
110 auto handle = PropHandleT<EntityTag>::from_unsigned(propVec.size());
111 auto prop =
new PropertyTT<T, EntityTag>(_name, type_name, *
this, handle, _def);
112 prop->resize(n<EntityTag>());
113 propVec.push_back(prop);
117 template<
typename T,
typename EntityTag>
120 auto *prop = internal_find_property<T, EntityTag>(_name);
123 return internal_create_property<T, EntityTag>(_name, _def);
128 template<
typename T,
typename EntityTag>
129 std::optional<PropertyTT<T, EntityTag>>
130 ResourceManager::create_property(
const std::string& _name,
const T _def)
132 auto *prop = internal_find_property<T, EntityTag>(_name);
135 return {*internal_create_property<T, EntityTag>(_name, _def)};
138 template<
typename T,
typename EntityTag>
139 std::optional<PropertyTT<T, EntityTag>>
140 ResourceManager::get_property(
const std::string& _name)
142 auto *prop = internal_find_property<T, EntityTag>(_name);
150 template<
typename T,
class EntityTag>
153 if(_flag == _prop->persistent())
return;
154 _prop->set_persistent(_flag);
157 template<
class StdVecT>
158 void ResourceManager::remove_property(StdVecT& _vec,
size_t _idx) {
160 auto prop_ptr = _vec[_idx];
161 prop_ptr->setResMan(
nullptr);
163 _vec.erase(_vec.begin() + _idx);
164 updatePropHandles(_vec);
167 template<
class StdVecT>
168 void ResourceManager::resize_props(StdVecT& _vec,
size_t _n) {
170 for(
typename StdVecT::iterator it = _vec.begin();
171 it != _vec.end(); ++it) {
176 template<
class StdVecT>
179 for(
typename StdVecT::iterator it = _vec.begin();
180 it != _vec.end(); ++it) {
181 (*it)->delete_element(_h.
uidx());
185 template<
class StdVecT>
186 void ResourceManager::clearVec(StdVecT& _vec) {
188 for (
auto prop: _vec) {
189 prop->setResMan(
nullptr);
195 template<
class StdVecT>
196 void ResourceManager::updatePropHandles(StdVecT &_vec)
198 size_t n = _vec.size();
199 for(
size_t i = 0; i < n; ++i) {
PropertyTT< T, EntityTag > request_property(const std::string &_name=std::string(), const T _def=T())
size_t uidx() const
return unsigned idx - handle must be valid