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 internal_request_property<std::vector<BaseProperty*>,VertexPropertyT<T>,VertexPropHandle,T>(vertex_props_, _name,
n_vertices(), _def);
51 EdgePropertyT<T> ResourceManager::request_edge_property(
const std::string& _name,
const T _def) {
53 return internal_request_property<std::vector<BaseProperty*>,EdgePropertyT<T>,EdgePropHandle,T>(edge_props_, _name,
n_edges(), _def);
57 HalfEdgePropertyT<T> ResourceManager::request_halfedge_property(
const std::string& _name,
const T _def) {
59 return internal_request_property<std::vector<BaseProperty*>,HalfEdgePropertyT<T>,HalfEdgePropHandle,T>(halfedge_props_, _name,
n_edges()*2u, _def);
63 FacePropertyT<T> ResourceManager::request_face_property(
const std::string& _name,
const T _def) {
65 return internal_request_property<std::vector<BaseProperty*>,FacePropertyT<T>,FacePropHandle,T>(face_props_, _name,
n_faces(), _def);
69 HalfFacePropertyT<T> ResourceManager::request_halfface_property(
const std::string& _name,
const T _def) {
71 return internal_request_property<std::vector<BaseProperty*>,HalfFacePropertyT<T>,HalfFacePropHandle,T>(halfface_props_, _name,
n_faces()*2u, _def);
75 CellPropertyT<T> ResourceManager::request_cell_property(
const std::string& _name,
const T _def) {
77 return internal_request_property<std::vector<BaseProperty*>,CellPropertyT<T>,CellPropHandle,T>(cell_props_, _name,
n_cells(), _def);
81 MeshPropertyT<T> ResourceManager::request_mesh_property(
const std::string& _name,
const T _def) {
83 return internal_request_property<std::vector<BaseProperty*>,MeshPropertyT<T>,MeshPropHandle,T>(mesh_props_, _name, 1, _def);
86 template<
class StdVecT,
class PropT,
class HandleT,
class T>
87 PropT ResourceManager::internal_request_property(StdVecT& _vec,
const std::string& _name,
size_t _size,
const T _def)
89 auto type_name = get_type_name<T>();
92 for(
typename StdVecT::iterator it = _vec.begin();
93 it != _vec.end(); ++it) {
94 if((*it)->name() == _name
95 && (*it)->internal_type_name() == type_name)
97 return *
static_cast<PropT*
>(*it);
102 auto handle = HandleT::from_unsigned(_vec.size());
104 PropT* prop =
new PropT(_name, type_name, *
this, handle, _def);
108 _vec.push_back(prop);
115 template<
class T,
typename EntityTag>
123 return resman->request_vertex_property<T>(_name, _def);
129 return resman->request_edge_property<T>(_name, _def);
135 return resman->request_halfedge_property<T>(_name, _def);
141 return resman->request_face_property<T>(_name, _def);
147 return resman->request_halfface_property<T>(_name, _def);
153 return resman->request_cell_property<T>(_name, _def);
157 template<
typename T,
typename EntityTag>
164 template<
typename T,
class EntityTag>
167 if(_flag == _prop->persistent())
return;
168 _prop->set_persistent(_flag);
171 template<
class StdVecT>
172 void ResourceManager::remove_property(StdVecT& _vec,
size_t _idx) {
174 auto prop_ptr = _vec[_idx];
175 prop_ptr->setResMan(
nullptr);
177 _vec.erase(_vec.begin() + _idx);
178 updatePropHandles(_vec);
181 template<
class StdVecT>
182 void ResourceManager::resize_props(StdVecT& _vec,
size_t _n) {
184 for(
typename StdVecT::iterator it = _vec.begin();
185 it != _vec.end(); ++it) {
190 template<
class StdVecT>
193 for(
typename StdVecT::iterator it = _vec.begin();
194 it != _vec.end(); ++it) {
195 (*it)->delete_element(_h.
uidx());
199 template<
class StdVecT>
200 void ResourceManager::clearVec(StdVecT& _vec) {
202 for (
auto prop: _vec) {
203 prop->setResMan(
nullptr);
209 template<
class StdVecT>
210 void ResourceManager::updatePropHandles(StdVecT &_vec)
212 size_t n = _vec.size();
213 for(
size_t i = 0; i < n; ++i) {
virtual size_t n_edges() const =0
Get number of edges in mesh.
virtual size_t n_cells() const =0
Get number of cells in mesh.
size_t uidx() const
return unsigned idx - handle must be valid
virtual size_t n_vertices() const =0
Get number of vertices in mesh.
virtual size_t n_faces() const =0
Get number of faces in mesh.