OpenVolumeMesh
 All Classes Functions Variables Typedefs Pages
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  * *
37  * $Revision: 198 $ *
38  * $Date: 2012-05-16 12:52:10 +0200 (Wed, 16 May 2012) $ *
39  * $LastChangedBy: kremer $ *
40  * *
41 \*===========================================================================*/
42 
43 #ifndef PROPERTYPTR_HH_
44 #define PROPERTYPTR_HH_
45 
46 #include <iostream>
47 #include <string>
48 #include <cassert>
49 
50 #include "BaseProperty.hh"
51 #include "PropertyHandles.hh"
52 
53 #include "../System/MemoryInclude.hh"
54 
55 namespace OpenVolumeMesh {
56 
57 class ResourceManager;
58 
67 template <class PropT, class HandleT>
68 class PropertyPtr : public ptr::shared_ptr<PropT>, public BaseProperty {
69 public:
70 
71  friend class ResourceManager;
72 
73  typedef typename PropT::value_type value_type;
74  typedef typename PropT::vector_type::const_iterator const_iterator;
75  typedef typename PropT::vector_type::iterator iterator;
76  typedef typename PropT::reference reference;
77  typedef typename PropT::const_reference const_reference;
78 
80  PropertyPtr(PropT* _ptr, ResourceManager& _resMan, HandleT _handle);
81 
83  virtual ~PropertyPtr();
84 
85  virtual const std::string& name() const;
86 
87  virtual void delete_element(size_t _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  reference operator[](size_t _idx) { return (*ptr::shared_ptr<PropT>::get())[_idx]; }
96  const_reference operator[](size_t _idx) const { return (*ptr::shared_ptr<PropT>::get())[_idx]; }
97 
98  reference operator[](const OpenVolumeMeshHandle& _h) { return (*ptr::shared_ptr<PropT>::get())[_h.idx()]; }
99  const_reference operator[](const OpenVolumeMeshHandle& _h) const { return (*ptr::shared_ptr<PropT>::get())[_h.idx()]; }
100 
101  virtual OpenVolumeMeshHandle handle() const;
102 
103  virtual bool persistent() const { return ptr::shared_ptr<PropT>::get()->persistent(); }
104 
105  virtual bool anonymous() const { return ptr::shared_ptr<PropT>::get()->name().empty(); }
106 
107 protected:
108 
109  virtual void delete_multiple_entries(const std::vector<bool>& _tags);
110 
111  virtual void resize(unsigned int _size);
112 
113  virtual void set_handle(const OpenVolumeMeshHandle& _handle);
114 };
115 
116 } // Namespace OpenVolumeMesh
117 
118 #if defined(INCLUDE_TEMPLATES) && !defined(PROPERTYPTRT_CC)
119 #include "PropertyPtrT.cc"
120 #endif
121 
122 #endif /* PROPERTYPTR_HH_ */