Commit 06d4281e authored by Martin Heistermann's avatar Martin Heistermann

Refactor: start simplification of PropertyTT/PropertyPtr

parent bd7687fa
Pipeline #9160 passed with stage
in 3 minutes and 53 seconds
......@@ -11,7 +11,7 @@ class OpenVolumeMeshPropertyT;
template <class E, typename >
class PropHandleT;
template <class PropT, class HandleT>
template <class PropT, typename Entity>
class PropertyPtr;
template<typename T, typename Entity>
......
......@@ -82,14 +82,12 @@ template <> const std::string entityTypeName<Entity::Cell>();
template <> const std::string entityTypeName<Entity::Mesh>();
template<typename T, typename Entity>
class PropertyTT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, PropHandleT<Entity>> {
class PropertyTT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, Entity> {
public:
using PropertyHandleT = OpenVolumeMesh::PropHandleT<Entity>;
PropertyTT(const std::string& _name, ResourceManager& _resMan, PropertyHandleT _handle, const T _def = T());
virtual ~PropertyTT() = default;
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 entityTypeName<Entity>(); }
virtual const std::string typeNameWrapper() const { return typeName<T>(); }
private:
......
......@@ -32,14 +32,6 @@
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Date$ *
* $LastChangedBy$ *
* *
\*===========================================================================*/
#define PROPERTYDEFINEST_CC
#include <istream>
......@@ -51,13 +43,13 @@ namespace OpenVolumeMesh {
template<typename T, typename Entity>
PropertyTT<T,Entity>::PropertyTT(const std::string& _name, ResourceManager& _resMan, PropertyHandleT _handle, const T _def) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, PropertyHandleT>(new OpenVolumeMeshPropertyT<T>(_name, _def), _resMan, _handle) {
PropertyPtr<OpenVolumeMeshPropertyT<T>, Entity>(new OpenVolumeMeshPropertyT<T>(_name, _def), _resMan, _handle) {
}
template<typename T, typename Entity>
PropertyTT<T,Entity>::PropertyTT(OpenVolumeMeshPropertyT<T> *_prop, ResourceManager &_resMan, PropertyHandleT _handle) :
PropertyPtr<OpenVolumeMeshPropertyT<T>, PropertyHandleT>(_prop, _resMan, _handle)
PropertyPtr<OpenVolumeMeshPropertyT<T>, Entity>(_prop, _resMan, _handle)
{
}
......@@ -68,16 +60,6 @@ BaseProperty *PropertyTT<T,Entity>::clone(ResourceManager &_resMan, OpenVolumeMe
return new PropertyTT<T, Entity>(prop_clone, _resMan, PropertyHandleT(_handle.idx()));
}
template<typename T, typename Entity>
void PropertyTT<T,Entity>::serialize(std::ostream& _ostr) const {
PropertyPtr<OpenVolumeMeshPropertyT<T>, PropertyHandleT>::get()->serialize(_ostr);
}
template<typename T, typename Entity>
void PropertyTT<T,Entity>::deserialize(std::istream& _istr) {
PropertyPtr<OpenVolumeMeshPropertyT<T>, PropertyHandleT>::get()->deserialize(_istr);
}
template<typename T>
const std::string typeName() {
throw std::runtime_error("Serialization is not supported for these data types!");
......
......@@ -37,6 +37,7 @@
#include <string>
#include "PropertyHandles.hh"
#include "BaseProperty.hh"
#include "OpenVolumeMeshHandle.hh"
#include "../System/MemoryInclude.hh"
......@@ -54,7 +55,7 @@ class ResourceManager;
* as soon as the object is not used anymore.
*/
template <class PropT, class HandleT>
template <class PropT, typename Entity>
class PropertyPtr : protected ptr::shared_ptr<PropT>, public BaseProperty {
public:
......@@ -66,10 +67,10 @@ public:
typedef typename PropT::reference reference;
typedef typename PropT::const_reference const_reference;
typedef OpenVolumeMesh::HandleT<typename HandleT::Entity> EntityHandleT;
using EntityHandleT = HandleT<Entity>;
/// Constructor
PropertyPtr(PropT* _ptr, ResourceManager& _resMan, HandleT _handle);
PropertyPtr(PropT* _ptr, ResourceManager& _resMan, PropHandleT<Entity> _handle);
/// Destructor
virtual ~PropertyPtr();
......@@ -100,6 +101,9 @@ public:
reference operator[](const EntityHandleT& _h) { return (*ptr::shared_ptr<PropT>::get())[_h.idx()]; }
const_reference operator[](const EntityHandleT& _h) const { return (*ptr::shared_ptr<PropT>::get())[_h.idx()]; }
virtual void serialize(std::ostream& _ostr) const { ptr::shared_ptr<PropT>::get()->serialize(_ostr); }
virtual void deserialize(std::istream& _istr) { ptr::shared_ptr<PropT>::get()->deserialize(_istr); }
virtual OpenVolumeMeshHandle handle() const;
virtual bool persistent() const { return ptr::shared_ptr<PropT>::get()->persistent(); }
......
......@@ -40,14 +40,14 @@
namespace OpenVolumeMesh {
template <class PropT, class HandleT>
PropertyPtr<PropT,HandleT>::PropertyPtr(PropT* _ptr, ResourceManager& _resMan, HandleT _handle) :
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>::get()->set_handle(_handle);
}
template <class PropT, class HandleT>
PropertyPtr<PropT,HandleT>::~PropertyPtr() {
template <class PropT, typename Entity>
PropertyPtr<PropT,Entity>::~PropertyPtr() {
/*
* If use count is 2 and prop is not set persistent,
......@@ -55,48 +55,48 @@ PropertyPtr<PropT,HandleT>::~PropertyPtr() {
* only one who stores the property.
*/
if(!locked() && !persistent() && ptr::shared_ptr<PropT>::use_count() == 2) {
resMan_.release_property(HandleT(handle().idx()));
resMan_.release_property(PropHandleT<Entity>(handle().idx()));
unlock();
}
}
template <class PropT, class HandleT>
void PropertyPtr<PropT,HandleT>::resize(size_t _size) {
template <class PropT, typename Entity>
void PropertyPtr<PropT,Entity>::resize(size_t _size) {
ptr::shared_ptr<PropT>::get()->resize(_size);
}
template <class PropT, class HandleT>
const std::string& PropertyPtr<PropT,HandleT>::name() const {
template <class PropT, typename Entity>
const std::string& PropertyPtr<PropT,Entity>::name() const {
return ptr::shared_ptr<PropT>::get()->name();
}
template <class PropT, class HandleT>
void PropertyPtr<PropT,HandleT>::delete_element(size_t _idx) {
template <class PropT, typename Entity>
void PropertyPtr<PropT,Entity>::delete_element(size_t _idx) {
ptr::shared_ptr<PropT>::get()->delete_element(_idx);
}
template <class PropT, class HandleT>
void PropertyPtr<PropT,HandleT>::swap_elements(size_t _idx0, size_t _idx1) {
template <class PropT, typename Entity>
void PropertyPtr<PropT,Entity>::swap_elements(size_t _idx0, size_t _idx1) {
ptr::shared_ptr<PropT>::get()->swap(_idx0, _idx1);
}
template <class PropT, class HandleT>
void PropertyPtr<PropT,HandleT>::copy(size_t _src_idx, size_t _dst_idx) {
template <class PropT, typename Entity>
void PropertyPtr<PropT,Entity>::copy(size_t _src_idx, size_t _dst_idx) {
ptr::shared_ptr<PropT>::get()->copy(_src_idx, _dst_idx);
}
template <class PropT, class HandleT>
void PropertyPtr<PropT,HandleT>::set_handle(const OpenVolumeMeshHandle& _handle) {
template <class PropT, typename Entity>
void PropertyPtr<PropT,Entity>::set_handle(const OpenVolumeMeshHandle& _handle) {
return ptr::shared_ptr<PropT>::get()->set_handle(_handle);
}
template <class PropT, class HandleT>
OpenVolumeMeshHandle PropertyPtr<PropT,HandleT>::handle() const {
template <class PropT, typename Entity>
OpenVolumeMeshHandle PropertyPtr<PropT,Entity>::handle() const {
return ptr::shared_ptr<PropT>::get()->handle();
}
template <class PropT, class HandleT>
void PropertyPtr<PropT,HandleT>::delete_multiple_entries(const std::vector<bool>& _tags) {
template <class PropT, typename Entity>
void PropertyPtr<PropT,Entity>::delete_multiple_entries(const std::vector<bool>& _tags) {
ptr::shared_ptr<PropT>::get()->delete_multiple_entries(_tags);
}
......
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