PropertyPtr.hh 5.91 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*===========================================================================*\
 *                                                                           *
 *                            OpenVolumeMesh                                 *
 *        Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen         *
 *                        www.openvolumemesh.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenVolumeMesh.                                     *
 *                                                                           *
 *  OpenVolumeMesh is free software: you can redistribute it and/or modify   *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenVolumeMesh is distributed in the hope that it will be useful,        *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenVolumeMesh.  If not,                              *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                         *
 *   $Date$                    *
 *   $LastChangedBy$                                                *
 *                                                                           *
\*===========================================================================*/

#ifndef PROPERTYPTR_HH_
#define PROPERTYPTR_HH_

#include <string>

#include "BaseProperty.hh"
49
#include "OpenVolumeMeshHandle.hh"
50
#include "../System/MemoryInclude.hh"
51
#include "../System/Deprecation.hh"
52

53
54
55
56
57
58
59
60
61
62
63
64
65
namespace OpenVolumeMesh {

class ResourceManager;

/**
 * \class PropertyPtr
 *
 * A smart-pointer-like class that counts the encapsulated
 * object's references and automatically deletes the memory
 * as soon as the object is not used anymore.
 */

template <class PropT, class HandleT>
66
class PropertyPtr : protected ptr::shared_ptr<PropT>, public BaseProperty {
67
68
69
70
public:

    friend class ResourceManager;

71
    typedef typename PropT::value_type                  value_type;
72
73
    typedef typename PropT::vector_type::const_iterator const_iterator;
    typedef typename PropT::vector_type::iterator       iterator;
74
75
    typedef typename PropT::reference                   reference;
    typedef typename PropT::const_reference             const_reference;
76

77
78
    typedef typename HandleT::EntityHandleT             EntityHandleT;

79
    /// Constructor
80
    PropertyPtr(PropT* _ptr, ResourceManager& _resMan, HandleT _handle);
81
82
83
84

    /// Destructor
    virtual ~PropertyPtr();

85
86
87
88
    using ptr::shared_ptr<PropT>::operator*;
    using ptr::shared_ptr<PropT>::operator->;
    using ptr::shared_ptr<PropT>::operator bool;

89
90
91
92
    virtual const std::string& name() const;

    virtual void delete_element(size_t _idx);

93
94
    virtual void swap_elements(size_t _idx0, size_t _idx1);

95
96
    virtual void copy(size_t _src_idx, size_t _dst_idx);

97
98
    const_iterator begin() const { return ptr::shared_ptr<PropT>::get()->begin(); }
    iterator begin() { return ptr::shared_ptr<PropT>::get()->begin(); }
99

100
101
    const_iterator end() const { return ptr::shared_ptr<PropT>::get()->end(); }
    iterator end() { return ptr::shared_ptr<PropT>::get()->end(); }
102

103
    OVM_DEPRECATED("use handles to index properties")
104
    reference operator[](size_t _idx) { return (*ptr::shared_ptr<PropT>::get())[_idx]; }
105
    OVM_DEPRECATED("use handles to index properties")
106
    const_reference operator[](size_t _idx) const { return (*ptr::shared_ptr<PropT>::get())[_idx]; }
107

108
109
    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()]; }
110

111
    virtual OpenVolumeMeshHandle handle() const;
112

113
    virtual bool persistent() const { return ptr::shared_ptr<PropT>::get()->persistent(); }
114

115
116
    virtual bool anonymous() const { return ptr::shared_ptr<PropT>::get()->name().empty(); }

Mike Kremer's avatar
Mike Kremer committed
117
protected:
118

119
120
    virtual void delete_multiple_entries(const std::vector<bool>& _tags);

Max Lyon's avatar
Max Lyon committed
121
    virtual void resize(size_t _size);
122

123
124
125
126
127
128
129
130
131
132
    virtual void set_handle(const OpenVolumeMeshHandle& _handle);
};

} // Namespace OpenVolumeMesh

#if defined(INCLUDE_TEMPLATES) && !defined(PROPERTYPTRT_CC)
#include "PropertyPtrT.cc"
#endif

#endif /* PROPERTYPTR_HH_ */