Commit 590f6066 authored by Martin Heistermann's avatar Martin Heistermann

Implement generic mesh::request_property templated on entity type.

parent 3e03bdfb
Pipeline #10296 passed with stage
in 3 minutes and 32 seconds
......@@ -55,9 +55,10 @@ class BaseProperty {
public:
friend class ResourceManager;
explicit BaseProperty(ResourceManager& _resMan) : resMan_(&_resMan) {}
explicit BaseProperty(ResourceManager* _resMan) : resMan_(_resMan) {}
BaseProperty(const BaseProperty& _cpy) : resMan_(_cpy.resMan_) {}
BaseProperty(BaseProperty&& _other) = default;
BaseProperty(const BaseProperty& _other) = default;
BaseProperty& operator=(const BaseProperty& _cpy) = delete;
......
......@@ -84,6 +84,10 @@ template <> const std::string entityTypeName<Entity::Mesh>();
template<typename T, typename Entity>
class PropertyTT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, Entity> {
public:
template<typename MeshT>
PropertyTT(MeshT *mesh, const std::string& _name, const T _def = T())
: PropertyTT(std::move(mesh->template request_property<T, Entity>(_name, _def)))
{}
using PropertyHandleT = OpenVolumeMesh::PropHandleT<Entity>;
PropertyTT(const std::string& _name, ResourceManager& _resMan, PropertyHandleT _handle, const T _def = T());
virtual ~PropertyTT() = default;
......
......@@ -69,6 +69,8 @@ public:
using EntityHandleT = HandleT<Entity>;
/// Constructor
PropertyPtr() : BaseProperty(nullptr) {}
/// Constructor
PropertyPtr(PropT* _ptr, ResourceManager& _resMan, PropHandleT<Entity> _handle);
......
......@@ -42,7 +42,7 @@ namespace OpenVolumeMesh {
template <class PropT, typename Entity>
PropertyPtr<PropT,Entity>::PropertyPtr(PropT* _ptr, ResourceManager& _resMan, PropHandleT<Entity> _handle) :
ptr::shared_ptr<PropT>(_ptr), BaseProperty(_resMan) {
ptr::shared_ptr<PropT>(_ptr), BaseProperty(&_resMan) {
ptr::shared_ptr<PropT>::get()->set_handle(_handle);
}
......
......@@ -132,6 +132,12 @@ public:
/// Get number of cells in mesh
virtual size_t n_cells() const = 0;
template<typename T,
typename EntityTag
>
PropertyTT<T, EntityTag> request_property(const std::string& _name = std::string(), const T _def = T());
template<class T> VertexPropertyT<T> request_vertex_property(const std::string& _name = std::string(), const T _def = T());
template<class T> EdgePropertyT<T> request_edge_property(const std::string& _name = std::string(), const T _def = T());
......@@ -146,6 +152,7 @@ public:
template<class T> MeshPropertyT<T> request_mesh_property(const std::string& _name = std::string(), const T _def = T());
private:
void release_property(VertexPropHandle _handle);
......@@ -178,19 +185,8 @@ public:
size_t n_mesh_props() const { return mesh_props_.size(); }
template<class T> void set_persistent(VertexPropertyT<T>& _prop, bool _flag = true);
template<class T> void set_persistent(EdgePropertyT<T>& _prop, bool _flag = true);
template<class T> void set_persistent(HalfEdgePropertyT<T>& _prop, bool _flag = true);
template<class T> void set_persistent(FacePropertyT<T>& _prop, bool _flag = true);
template<class T> void set_persistent(HalfFacePropertyT<T>& _prop, bool _flag = true);
template<class T> void set_persistent(CellPropertyT<T>& _prop, bool _flag = true);
template<class T> void set_persistent(MeshPropertyT<T>& _prop, bool _flag = true);
template<typename T, class EntityTag>
void set_persistent(PropertyTT<T, EntityTag>& _prop, bool _flag = true);
typedef std::vector<BaseProperty*> Properties;
......@@ -314,9 +310,6 @@ private:
template<class StdVecT, class PropT, class HandleT, class T>
PropT request_property(StdVecT& _vec, const std::string& _name, size_t _size, const T _def = T());
template<class PropT>
void set_persistentT(PropT& _prop, bool _flag);
template<class StdVecT>
void clearVec(StdVecT& _vec);
......
......@@ -117,53 +117,55 @@ PropT ResourceManager::request_property(StdVecT& _vec, const std::string& _name,
return *prop;
}
template<class T>
void ResourceManager::set_persistent(VertexPropertyT<T>& _prop, bool _flag) {
// request_property: work around C++ currently now allowing partial specialisation on functions by using structs:
set_persistentT(_prop, _flag);
}
template<class T, typename EntityTag>
struct request_property_impl {
static PropertyTT<T, EntityTag> _(ResourceManager* /*resman*/, const std::string& /*_name*/, const T /*_def*/);
};
template<class T>
void ResourceManager::set_persistent(EdgePropertyT<T>& _prop, bool _flag) {
set_persistentT(_prop, _flag);
}
template<class T>
void ResourceManager::set_persistent(HalfEdgePropertyT<T>& _prop, bool _flag) {
set_persistentT(_prop, _flag);
}
struct request_property_impl<T, Entity::Edge>{
static PropertyTT<T, Entity::Edge> _(ResourceManager *resman, const std::string &_name, const T _def) {
return resman->request_edge_property<T>(_name, _def);
}
};
template<class T>
void ResourceManager::set_persistent(FacePropertyT<T>& _prop, bool _flag) {
set_persistentT(_prop, _flag);
}
struct request_property_impl<T, Entity::HalfEdge>{
static PropertyTT<T, Entity::HalfEdge> _(ResourceManager *resman, const std::string &_name, const T _def) {
return resman->request_halfedge_property<T>(_name, _def);
}
};
template<class T>
void ResourceManager::set_persistent(HalfFacePropertyT<T>& _prop, bool _flag) {
set_persistentT(_prop, _flag);
}
struct request_property_impl<T, Entity::Face>{
static PropertyTT<T, Entity::Face> _(ResourceManager *resman, const std::string &_name, const T _def) {
return resman->request_face_property<T>(_name, _def);
}
};
template<class T>
void ResourceManager::set_persistent(CellPropertyT<T>& _prop, bool _flag) {
set_persistentT(_prop, _flag);
}
struct request_property_impl<T, Entity::HalfFace>{
static PropertyTT<T, Entity::HalfFace> _(ResourceManager *resman, const std::string &_name, const T _def) {
return resman->request_halfface_property<T>(_name, _def);
}
};
template<class T>
void ResourceManager::set_persistent(MeshPropertyT<T>& _prop, bool _flag) {
struct request_property_impl<T, Entity::Cell>{
static PropertyTT<T, Entity::Cell> _(ResourceManager *resman, const std::string &_name, const T _def) {
return resman->request_cell_property<T>(_name, _def);
}
};
set_persistentT(_prop, _flag);
template<typename T, typename EntityTag>
PropertyTT<T, EntityTag> ResourceManager::request_property(const std::string& _name, const T _def)
{
return request_property_impl<T, EntityTag>::_(this, _name, _def);
}
template<class PropT>
void ResourceManager::set_persistentT(PropT& _prop, bool _flag) {
template<typename T, class EntityTag>
void ResourceManager::set_persistent(PropertyTT<T, EntityTag>& _prop, bool _flag)
{
if(_flag == _prop->persistent()) return;
_prop->set_persistent(_flag);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment