Developer Documentation

PropertyPtr.hh
1 /*===========================================================================*\
2 * *
3 * OpenVolumeMesh *
4 * Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen *
5 * www.openvolumemesh.org *
6 * *
7 *---------------------------------------------------------------------------*
8 * This file is part of OpenVolumeMesh. *
9 * *
10 * OpenVolumeMesh is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenVolumeMesh is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenVolumeMesh. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34
35
36 #pragma once
37
38 #include <string>
39
40 #include "PropertyHandles.hh"
41 #include "BaseProperty.hh"
42 #include "OpenVolumeMeshHandle.hh"
43 #include "../System/MemoryInclude.hh"
44 #include "../System/Deprecation.hh"
45
46 namespace OpenVolumeMesh {
47
48 class ResourceManager;
49
58 template <class PropT, typename Entity>
59 class PropertyPtr : protected ptr::shared_ptr<PropT>, public BaseProperty {
60 public:
61
62 friend class ResourceManager;
63
64 typedef typename PropT::value_type value_type;
65 typedef typename PropT::vector_type::const_iterator const_iterator;
66 typedef typename PropT::vector_type::iterator iterator;
67 typedef typename PropT::reference reference;
68 typedef typename PropT::const_reference const_reference;
69
70 using EntityHandleT = HandleT<Entity>;
71
73 PropertyPtr() : BaseProperty(nullptr) {}
75 PropertyPtr(PropT* _ptr, ResourceManager& _resMan, PropHandleT<Entity> _handle);
76
78 ~PropertyPtr() override;
79
80 using ptr::shared_ptr<PropT>::operator*;
81 using ptr::shared_ptr<PropT>::operator->;
82 using ptr::shared_ptr<PropT>::operator bool;
83
84 const std::string& name() const override;
85
86 void delete_element(size_t _idx) override;
87
88 void swap_elements(size_t _idx0, size_t _idx1) override;
89
90 void copy(size_t _src_idx, size_t _dst_idx) override;
91
92 const_iterator begin() const { return ptr::shared_ptr<PropT>::get()->begin(); }
93 iterator begin() { return ptr::shared_ptr<PropT>::get()->begin(); }
94 size_t size() const override { return ptr::shared_ptr<PropT>::get()->size(); }
95
96 const_iterator end() const { return ptr::shared_ptr<PropT>::get()->end(); }
97 iterator end() { return ptr::shared_ptr<PropT>::get()->end(); }
98
99 #if OVM_ENABLE_DEPRECATED_APIS
100 OVM_DEPRECATED("use handles to index properties")
101 reference operator[](size_t _idx) { return (*ptr::shared_ptr<PropT>::get())[_idx]; }
102 OVM_DEPRECATED("use handles to index properties")
103 const_reference operator[](size_t _idx) const { return (*ptr::shared_ptr<PropT>::get())[_idx]; }
104 #endif
105
106 reference operator[](const EntityHandleT& _h) { return (*ptr::shared_ptr<PropT>::get())[_h.idx()]; }
107 const_reference operator[](const EntityHandleT& _h) const { return (*ptr::shared_ptr<PropT>::get())[_h.uidx()]; }
108
109 void serialize(std::ostream& _ostr) const override { ptr::shared_ptr<PropT>::get()->serialize(_ostr); }
110 void deserialize(std::istream& _istr) override { ptr::shared_ptr<PropT>::get()->deserialize(_istr); }
111
112 OpenVolumeMeshHandle handle() const override;
113
114 bool persistent() const override { return ptr::shared_ptr<PropT>::get()->persistent(); }
115
116 bool anonymous() const override { return ptr::shared_ptr<PropT>::get()->name().empty(); }
117
118 protected:
119 const std::string &internal_type_name() const override { return ptr::shared_ptr<PropT>::get()->internal_type_name(); }
120
121 void assign_values_from(const BaseProperty *other) override;
122 void move_values_from(BaseProperty *other) override;
123
124 void delete_multiple_entries(const std::vector<bool>& _tags) override;
125
126 void resize(size_t _size) override;
127
128 void set_handle(const OpenVolumeMeshHandle& _handle) override;
129 };
130
131 } // Namespace OpenVolumeMesh
132
133 #if defined(INCLUDE_TEMPLATES) && !defined(PROPERTYPTRT_CC)
134 #include "PropertyPtrT_impl.hh"
135 #endif
136
OpenVolumeMesh::PropertyPtr::PropertyPtr
PropertyPtr()
Constructor.
Definition: PropertyPtr.hh:73
OpenVolumeMesh
Definition: ColorAttrib.hh:53
OpenVolumeMesh::PropertyPtr::~PropertyPtr
~PropertyPtr() override
Destructor.
Definition: PropertyPtrT_impl.hh:50
OpenVolumeMesh::HandleT
Definition: OpenVolumeMeshHandle.hh:108
OpenVolumeMesh::BaseProperty
Definition: BaseProperty.hh:46
OpenVolumeMesh::ResourceManager
Definition: ResourceManager.hh:54
OpenVolumeMesh::OpenVolumeMeshHandle::uidx
size_t uidx() const
return unsigned idx - handle must be valid
Definition: OpenVolumeMeshHandle.hh:80
OpenVolumeMesh::OpenVolumeMeshHandle
Definition: OpenVolumeMeshHandle.hh:50
OpenVolumeMesh::PropertyPtr::assign_values_from
void assign_values_from(const BaseProperty *other) override
Definition: PropertyPtrT_impl.hh:63
OpenVolumeMesh::PropertyPtr::move_values_from
void move_values_from(BaseProperty *other) override
Definition: PropertyPtrT_impl.hh:70