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 "BaseProperty.hh"
41 #include "OpenVolumeMeshHandle.hh"
42 #include "../System/MemoryInclude.hh"
43 #include "../System/Deprecation.hh"
44 
45 namespace OpenVolumeMesh {
46 
47 class ResourceManager;
48 
57 template <class PropT, class HandleT>
58 class PropertyPtr : protected ptr::shared_ptr<PropT>, public BaseProperty {
59 public:
60 
61  friend class ResourceManager;
62 
63  typedef typename PropT::value_type value_type;
64  typedef typename PropT::vector_type::const_iterator const_iterator;
65  typedef typename PropT::vector_type::iterator iterator;
66  typedef typename PropT::reference reference;
67  typedef typename PropT::const_reference const_reference;
68 
70 
72  PropertyPtr(PropT* _ptr, ResourceManager& _resMan, HandleT _handle);
73 
75  virtual ~PropertyPtr();
76 
77  using ptr::shared_ptr<PropT>::operator*;
78  using ptr::shared_ptr<PropT>::operator->;
79  using ptr::shared_ptr<PropT>::operator bool;
80 
81  virtual const std::string& name() const;
82 
83  virtual void delete_element(size_t _idx);
84 
85  virtual void swap_elements(size_t _idx0, size_t _idx1);
86 
87  virtual void copy(size_t _src_idx, size_t _dst_idx);
88 
89  const_iterator begin() const { return ptr::shared_ptr<PropT>::get()->begin(); }
90  iterator begin() { return ptr::shared_ptr<PropT>::get()->begin(); }
91 
92  const_iterator end() const { return ptr::shared_ptr<PropT>::get()->end(); }
93  iterator end() { return ptr::shared_ptr<PropT>::get()->end(); }
94 
95  OVM_DEPRECATED("use handles to index properties")
96  reference operator[](size_t _idx) { return (*ptr::shared_ptr<PropT>::get())[_idx]; }
97  OVM_DEPRECATED("use handles to index properties")
98  const_reference operator[](size_t _idx) const { return (*ptr::shared_ptr<PropT>::get())[_idx]; }
99 
100  reference operator[](const EntityHandleT& _h) { return (*ptr::shared_ptr<PropT>::get())[_h.idx()]; }
101  const_reference operator[](const EntityHandleT& _h) const { return (*ptr::shared_ptr<PropT>::get())[_h.idx()]; }
102 
103  virtual OpenVolumeMeshHandle handle() const;
104 
105  virtual bool persistent() const { return ptr::shared_ptr<PropT>::get()->persistent(); }
106 
107  virtual bool anonymous() const { return ptr::shared_ptr<PropT>::get()->name().empty(); }
108 
109 protected:
110 
111  virtual void delete_multiple_entries(const std::vector<bool>& _tags);
112 
113  virtual void resize(size_t _size);
114 
115  virtual void set_handle(const OpenVolumeMeshHandle& _handle);
116 };
117 
118 } // Namespace OpenVolumeMesh
119 
120 #if defined(INCLUDE_TEMPLATES) && !defined(PROPERTYPTRT_CC)
121 #include "PropertyPtrT_impl.hh"
122 #endif
123 
PropertyPtr(PropT *_ptr, ResourceManager &_resMan, HandleT _handle)
Constructor.
virtual ~PropertyPtr()
Destructor.