Commit 26e2fe64 authored by Martin Heistermann's avatar Martin Heistermann

Implement proper copy constructor for ResourceManager to allow mesh copying.

Fixes #5.
parent 3ae26e6a
Pipeline #6176 passed with stage
in 3 minutes and 47 seconds
......@@ -65,6 +65,8 @@ public:
virtual const std::string& name() const = 0;
virtual BaseProperty* clone(ResourceManager &_resMan, OpenVolumeMeshHandle _handle) const = 0;
virtual void delete_element(size_t _idx) = 0;
virtual void swap_elements(size_t _idx0, size_t _idx1) = 0;
......
......@@ -79,7 +79,9 @@ template<class T>
class VertexPropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, VertexPropHandle> {
public:
VertexPropertyT(const std::string& _name, ResourceManager& _resMan, VertexPropHandle _handle, const T _def = T());
VertexPropertyT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager& _resMan, VertexPropHandle _handle);
virtual ~VertexPropertyT() {}
virtual BaseProperty* clone(ResourceManager &_resMan, OpenVolumeMeshHandle _handle) const;
virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr);
virtual const std::string entityType() const { return "VProp"; }
......@@ -89,7 +91,9 @@ template<class T>
class EdgePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, EdgePropHandle> {
public:
EdgePropertyT(const std::string& _name, ResourceManager& _resMan, EdgePropHandle _handle, const T _def = T());
EdgePropertyT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager& _resMan, EdgePropHandle _handle);
virtual ~EdgePropertyT() {}
virtual BaseProperty* clone(ResourceManager &_resMan, const OpenVolumeMeshHandle _handle) const;
virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr);
virtual const std::string entityType() const { return "EProp"; }
......@@ -99,7 +103,9 @@ template<class T>
class HalfEdgePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfEdgePropHandle> {
public:
HalfEdgePropertyT(const std::string& _name, ResourceManager& _resMan, HalfEdgePropHandle _handle, const T _def = T());
HalfEdgePropertyT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager& _resMan, HalfEdgePropHandle _handle);
virtual ~HalfEdgePropertyT() {}
virtual BaseProperty* clone(ResourceManager &_resMan, const OpenVolumeMeshHandle _handle) const;
virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr);
virtual const std::string entityType() const { return "HEProp"; }
......@@ -109,7 +115,9 @@ template<class T>
class FacePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, FacePropHandle> {
public:
FacePropertyT(const std::string& _name, ResourceManager& _resMan, FacePropHandle _handle, const T _def = T());
FacePropertyT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager& _resMan, FacePropHandle _handle);
virtual ~FacePropertyT() {}
virtual BaseProperty* clone(ResourceManager &_resMan, const OpenVolumeMeshHandle _handle) const;
virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr);
virtual const std::string entityType() const { return "FProp"; }
......@@ -119,7 +127,9 @@ template<class T>
class HalfFacePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfFacePropHandle> {
public:
HalfFacePropertyT(const std::string& _name, ResourceManager& _resMan, HalfFacePropHandle _handle, const T _def = T());
HalfFacePropertyT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager& _resMan, HalfFacePropHandle _handle);
virtual ~HalfFacePropertyT() {}
virtual BaseProperty* clone(ResourceManager &_resMan, const OpenVolumeMeshHandle _handle) const;
virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr);
virtual const std::string entityType() const { return "HFProp"; }
......@@ -129,7 +139,9 @@ template<class T>
class CellPropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, CellPropHandle> {
public:
CellPropertyT(const std::string& _name, ResourceManager& _resMan, CellPropHandle _handle, const T _def = T());
CellPropertyT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager& _resMan, CellPropHandle _handle);
virtual ~CellPropertyT() {}
virtual BaseProperty* clone(ResourceManager &_resMan, const OpenVolumeMeshHandle _handle) const;
virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr);
virtual const std::string entityType() const { return "CProp"; }
......@@ -139,7 +151,9 @@ template<class T>
class MeshPropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, MeshPropHandle> {
public:
MeshPropertyT(const std::string& _name, ResourceManager& _resMan, MeshPropHandle _handle, const T _def = T());
MeshPropertyT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager& _resMan, MeshPropHandle _handle);
virtual ~MeshPropertyT() {}
virtual BaseProperty* clone(ResourceManager &_resMan, const OpenVolumeMeshHandle _handle) const;
virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr);
virtual const std::string entityType() const { return "MProp"; }
......
......@@ -56,6 +56,19 @@ VertexPropertyT<T>::VertexPropertyT(const std::string& _name, ResourceManager& _
}
template<class T>
VertexPropertyT<T>::VertexPropertyT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager &_resMan, VertexPropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, VertexPropHandle>(_prop, _resMan, _handle)
{
}
template<class T>
BaseProperty *VertexPropertyT<T>::clone(ResourceManager &_resMan, OpenVolumeMeshHandle _handle) const
{
auto prop_clone = ptr::shared_ptr<OpenVolumeMeshPropertyT<T>>::get()->clone();
return new VertexPropertyT<T>(prop_clone, _resMan, VertexPropHandle(_handle));
}
template<class T>
void VertexPropertyT<T>::serialize(std::ostream& _ostr) const {
PropertyPtr<OpenVolumeMeshPropertyT<T>, VertexPropHandle>::get()->serialize(_ostr);
......@@ -71,6 +84,18 @@ EdgePropertyT<T>::EdgePropertyT(const std::string& _name, ResourceManager& _resM
PropertyPtr<OpenVolumeMeshPropertyT<T>, EdgePropHandle>(new OpenVolumeMeshPropertyT<T>(_name, _def), _resMan, _handle) {
}
template<class T>
EdgePropertyT<T>::EdgePropertyT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager &_resMan, EdgePropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, EdgePropHandle>(_prop, _resMan, _handle)
{
}
template<class T>
BaseProperty *EdgePropertyT<T>::clone(ResourceManager &_resMan, const OpenVolumeMeshHandle _handle) const
{
auto prop_clone = ptr::shared_ptr<OpenVolumeMeshPropertyT<T>>::get()->clone();
return new EdgePropertyT<T>(prop_clone, _resMan, EdgePropHandle(_handle));
}
template<class T>
void EdgePropertyT<T>::serialize(std::ostream& _ostr) const {
......@@ -87,6 +112,18 @@ HalfEdgePropertyT<T>::HalfEdgePropertyT(const std::string& _name, ResourceManage
PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfEdgePropHandle>(new OpenVolumeMeshPropertyT<T>(_name, _def), _resMan, _handle) {
}
template<class T>
HalfEdgePropertyT<T>::HalfEdgePropertyT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager &_resMan, HalfEdgePropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfEdgePropHandle>(_prop, _resMan, _handle)
{
}
template<class T>
BaseProperty *HalfEdgePropertyT<T>::clone(ResourceManager &_resMan, const OpenVolumeMeshHandle _handle) const
{
auto prop_clone = ptr::shared_ptr<OpenVolumeMeshPropertyT<T>>::get()->clone();
return new HalfEdgePropertyT<T>(prop_clone, _resMan, HalfEdgePropHandle(_handle));
}
template<class T>
void HalfEdgePropertyT<T>::serialize(std::ostream& _ostr) const {
......@@ -103,6 +140,18 @@ FacePropertyT<T>::FacePropertyT(const std::string& _name, ResourceManager& _resM
PropertyPtr<OpenVolumeMeshPropertyT<T>, FacePropHandle>(new OpenVolumeMeshPropertyT<T>(_name, _def), _resMan, _handle) {
}
template<class T>
FacePropertyT<T>::FacePropertyT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager &_resMan, FacePropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, FacePropHandle>(_prop, _resMan, _handle)
{
}
template<class T>
BaseProperty *FacePropertyT<T>::clone(ResourceManager &_resMan, const OpenVolumeMeshHandle _handle) const
{
auto prop_clone = ptr::shared_ptr<OpenVolumeMeshPropertyT<T>>::get()->clone();
return new FacePropertyT<T>(prop_clone, _resMan, FacePropHandle(_handle));
}
template<class T>
void FacePropertyT<T>::serialize(std::ostream& _ostr) const {
......@@ -119,6 +168,18 @@ HalfFacePropertyT<T>::HalfFacePropertyT(const std::string& _name, ResourceManage
PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfFacePropHandle>(new OpenVolumeMeshPropertyT<T>(_name, _def), _resMan, _handle) {
}
template<class T>
HalfFacePropertyT<T>::HalfFacePropertyT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager &_resMan, HalfFacePropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfFacePropHandle>(_prop, _resMan, _handle)
{
}
template<class T>
BaseProperty *HalfFacePropertyT<T>::clone(ResourceManager &_resMan, const OpenVolumeMeshHandle _handle) const
{
auto prop_clone = ptr::shared_ptr<OpenVolumeMeshPropertyT<T>>::get()->clone();
return new HalfFacePropertyT<T>(prop_clone, _resMan, HalfFacePropHandle(_handle));
}
template<class T>
void HalfFacePropertyT<T>::serialize(std::ostream& _ostr) const {
......@@ -135,6 +196,18 @@ CellPropertyT<T>::CellPropertyT(const std::string& _name, ResourceManager& _resM
PropertyPtr<OpenVolumeMeshPropertyT<T>, CellPropHandle>(new OpenVolumeMeshPropertyT<T>(_name, _def), _resMan, _handle) {
}
template<class T>
CellPropertyT<T>::CellPropertyT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager &_resMan, CellPropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, CellPropHandle>(_prop, _resMan, _handle)
{
}
template<class T>
BaseProperty *CellPropertyT<T>::clone(ResourceManager &_resMan, const OpenVolumeMeshHandle _handle) const
{
auto prop_clone = ptr::shared_ptr<OpenVolumeMeshPropertyT<T>>::get()->clone();
return new CellPropertyT<T>(prop_clone, _resMan, CellPropHandle(_handle));
}
template<class T>
void CellPropertyT<T>::serialize(std::ostream& _ostr) const {
......@@ -151,6 +224,18 @@ MeshPropertyT<T>::MeshPropertyT(const std::string& _name, ResourceManager& _resM
PropertyPtr<OpenVolumeMeshPropertyT<T>, MeshPropHandle>(new OpenVolumeMeshPropertyT<T>(_name, _def), _resMan, _handle) {
}
template<class T>
MeshPropertyT<T>::MeshPropertyT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager &_resMan, MeshPropHandle _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, MeshPropHandle>(_prop, _resMan, _handle)
{
}
template<class T>
BaseProperty *MeshPropertyT<T>::clone(ResourceManager &_resMan, const OpenVolumeMeshHandle _handle) const
{
auto prop_clone = ptr::shared_ptr<OpenVolumeMeshPropertyT<T>>::get()->clone();
return new MeshPropertyT<T>(prop_clone, _resMan, MeshPropHandle(_handle));
}
template<class T>
void MeshPropertyT<T>::serialize(std::ostream& _ostr) const {
......
......@@ -47,6 +47,22 @@ namespace OpenVolumeMesh {
ResourceManager::ResourceManager() {
}
ResourceManager::ResourceManager(const ResourceManager &other) {
auto cloneProps = [this](const Properties &src, Properties &dest) {
dest.reserve(src.size());
for (BaseProperty *bp: src) {
dest.push_back(bp->clone(*this, bp->handle()));
}
};
cloneProps(other.vertex_props_, vertex_props_);
cloneProps(other.edge_props_, edge_props_);
cloneProps(other.halfedge_props_, halfedge_props_);
cloneProps(other.face_props_, face_props_);
cloneProps(other.halfface_props_, halfface_props_);
cloneProps(other.cell_props_, cell_props_);
cloneProps(other.mesh_props_, mesh_props_);
}
ResourceManager::~ResourceManager() {
// Delete persistent props
......
......@@ -76,6 +76,7 @@ class PropertyPtr;
class ResourceManager {
public:
ResourceManager();
ResourceManager(const ResourceManager &other);
virtual ~ResourceManager();
template <class PropT, class HandleT> friend class PropertyPtr;
......
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