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  PropertyPtr(const PropertyPtr<PropT, Entity>&) = default;
82  PropertyPtr<PropT, Entity>& operator=(const PropertyPtr<PropT, Entity>&) = default;
84 
85  using ptr::shared_ptr<PropT>::operator*;
86  using ptr::shared_ptr<PropT>::operator->;
87  using ptr::shared_ptr<PropT>::operator bool;
88 
89  const std::string& name() const override;
90 
91  void delete_element(size_t _idx) override;
92 
93  void swap_elements(size_t _idx0, size_t _idx1) override;
94 
95  void copy(size_t _src_idx, size_t _dst_idx) override;
96 
97  const_iterator begin() const { return ptr::shared_ptr<PropT>::get()->begin(); }
98  iterator begin() { return ptr::shared_ptr<PropT>::get()->begin(); }
99  size_t size() const override { return ptr::shared_ptr<PropT>::get()->size(); }
100 
101  const_iterator end() const { return ptr::shared_ptr<PropT>::get()->end(); }
102  iterator end() { return ptr::shared_ptr<PropT>::get()->end(); }
103 
104 #if OVM_ENABLE_DEPRECATED_APIS
105  OVM_DEPRECATED("use handles to index properties")
106  reference operator[](size_t _idx) { return (*ptr::shared_ptr<PropT>::get())[_idx]; }
107  OVM_DEPRECATED("use handles to index properties")
108  const_reference operator[](size_t _idx) const { return (*ptr::shared_ptr<PropT>::get())[_idx]; }
109 #endif
110 
111  reference operator[](const EntityHandleT& _h) { return (*ptr::shared_ptr<PropT>::get())[_h.uidx()]; }
112  const_reference operator[](const EntityHandleT& _h) const { return (*ptr::shared_ptr<PropT>::get())[_h.uidx()]; }
113 
114  void serialize(std::ostream& _ostr) const override { ptr::shared_ptr<PropT>::get()->serialize(_ostr); }
115  void deserialize(std::istream& _istr) override { ptr::shared_ptr<PropT>::get()->deserialize(_istr); }
116 
117  OpenVolumeMeshHandle handle() const override;
118 
119  bool persistent() const override { return ptr::shared_ptr<PropT>::get()->persistent(); }
120 
121  bool anonymous() const override { return ptr::shared_ptr<PropT>::get()->name().empty(); }
122 
123 protected:
124  const std::string &internal_type_name() const override { return ptr::shared_ptr<PropT>::get()->internal_type_name(); }
125 
126  void assign_values_from(const BaseProperty *other) override;
127  void move_values_from(BaseProperty *other) override;
128 
129  void delete_multiple_entries(const std::vector<bool>& _tags) override;
130 
131  void resize(size_t _size) override;
132 
133  void set_handle(const OpenVolumeMeshHandle& _handle) override;
134 };
135 
136 } // Namespace OpenVolumeMesh
137 
138 #if defined(INCLUDE_TEMPLATES) && !defined(PROPERTYPTRT_CC)
139 #include "PropertyPtrT_impl.hh"
140 #endif
141 
PropertyPtr()
Constructor.
Definition: PropertyPtr.hh:73
~PropertyPtr() override
Destructor.
size_t uidx() const
return unsigned idx - handle must be valid
void assign_values_from(const BaseProperty *other) override
void move_values_from(BaseProperty *other) override