43 #define RESOURCEMANAGERT_CC
45 #include "ResourceManager.hh"
46 #include "PropertyDefines.hh"
51 VertexPropertyT<T> ResourceManager::request_vertex_property(
const std::string& _name,
const T _def) {
53 return request_property<std::vector<BaseProperty*>,VertexPropertyT<T>,VertexPropHandle,T>(vertex_props_, _name,
n_vertices(), _def);
57 EdgePropertyT<T> ResourceManager::request_edge_property(
const std::string& _name,
const T _def) {
59 return request_property<std::vector<BaseProperty*>,EdgePropertyT<T>,EdgePropHandle,T>(edge_props_, _name,
n_edges(), _def);
63 HalfEdgePropertyT<T> ResourceManager::request_halfedge_property(
const std::string& _name,
const T _def) {
65 return request_property<std::vector<BaseProperty*>,HalfEdgePropertyT<T>,HalfEdgePropHandle,T>(halfedge_props_, _name,
n_edges()*2u, _def);
69 FacePropertyT<T> ResourceManager::request_face_property(
const std::string& _name,
const T _def) {
71 return request_property<std::vector<BaseProperty*>,FacePropertyT<T>,FacePropHandle,T>(face_props_, _name,
n_faces(), _def);
75 HalfFacePropertyT<T> ResourceManager::request_halfface_property(
const std::string& _name,
const T _def) {
77 return request_property<std::vector<BaseProperty*>,HalfFacePropertyT<T>,HalfFacePropHandle,T>(halfface_props_, _name,
n_faces()*2u, _def);
81 CellPropertyT<T> ResourceManager::request_cell_property(
const std::string& _name,
const T _def) {
83 return request_property<std::vector<BaseProperty*>,CellPropertyT<T>,CellPropHandle,T>(cell_props_, _name,
n_cells(), _def);
87 MeshPropertyT<T> ResourceManager::request_mesh_property(
const std::string& _name,
const T _def) {
89 return request_property<std::vector<BaseProperty*>,MeshPropertyT<T>,MeshPropHandle,T>(mesh_props_, _name, 1, _def);
92 template<
class StdVecT,
class PropT,
class HandleT,
class T>
93 PropT ResourceManager::request_property(StdVecT& _vec,
const std::string& _name,
size_t _size,
const T _def) {
96 for(
typename StdVecT::iterator it = _vec.begin();
97 it != _vec.end(); ++it) {
98 if((*it)->name() == _name) {
99 #if OVM_FORCE_STATIC_CAST
100 return *
static_cast<PropT*
>(*it);
102 PropT* prop =
dynamic_cast<PropT*
>(*it);
103 if(prop != NULL)
return *prop;
109 HandleT handle(_vec.size());
111 PropT* prop =
new PropT(_name, *
this, handle, _def);
115 _vec.push_back(prop);
121 void ResourceManager::set_persistent(VertexPropertyT<T>& _prop,
bool _flag) {
123 set_persistentT(_prop, _flag);
127 void ResourceManager::set_persistent(EdgePropertyT<T>& _prop,
bool _flag) {
129 set_persistentT(_prop, _flag);
133 void ResourceManager::set_persistent(HalfEdgePropertyT<T>& _prop,
bool _flag) {
135 set_persistentT(_prop, _flag);
139 void ResourceManager::set_persistent(FacePropertyT<T>& _prop,
bool _flag) {
141 set_persistentT(_prop, _flag);
145 void ResourceManager::set_persistent(HalfFacePropertyT<T>& _prop,
bool _flag) {
147 set_persistentT(_prop, _flag);
151 void ResourceManager::set_persistent(CellPropertyT<T>& _prop,
bool _flag) {
153 set_persistentT(_prop, _flag);
157 void ResourceManager::set_persistent(MeshPropertyT<T>& _prop,
bool _flag) {
159 set_persistentT(_prop, _flag);
162 template<
class PropT>
163 void ResourceManager::set_persistentT(PropT& _prop,
bool _flag) {
165 if(_flag == _prop->persistent())
return;
167 _prop->set_persistent(_flag);
170 template<
class StdVecT>
171 void ResourceManager::remove_property(StdVecT& _vec,
size_t _idx) {
173 (*(_vec.begin() + _idx))->lock();
174 delete *(_vec.begin() + _idx);
175 _vec.erase(_vec.begin() + _idx);
176 size_t n = _vec.size();
177 for(
size_t i = 0; i < n; ++i) {
178 _vec[i]->set_handle(OpenVolumeMeshHandle(i));
182 template<
class StdVecT>
183 void ResourceManager::resize_props(StdVecT& _vec,
size_t _n) {
185 for(
typename StdVecT::iterator it = _vec.begin();
186 it != _vec.end(); ++it) {
191 template<
class StdVecT>
192 void ResourceManager::entity_deleted(StdVecT& _vec,
const OpenVolumeMeshHandle& _h) {
194 for(
typename StdVecT::iterator it = _vec.begin();
195 it != _vec.end(); ++it) {
196 (*it)->delete_element(_h.idx());
200 template<
class StdVecT>
201 void ResourceManager::clearVec(StdVecT& _vec) {
204 for(
typename StdVecT::iterator it = _vec.begin();
205 it != _vec.end(); ++it) {
206 if(!(*it)->persistent()) {
208 std::cerr <<
"Keeping property \"" << (*it)->name()
209 <<
"\" since it is still in use!" << std::endl;
212 newVec.push_back(*it);
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.
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.