PropertyPtr.hh 5.51 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

52 53 54 55 56 57 58 59 60 61 62 63 64
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>
65
class PropertyPtr : public ptr::shared_ptr<PropT>, public BaseProperty {
66 67 68 69
public:

    friend class ResourceManager;

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

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

    /// Destructor
    virtual ~PropertyPtr();

    virtual const std::string& name() const;

    virtual void delete_element(size_t _idx);

86 87
    virtual void swap_elements(size_t _idx0, size_t _idx1);

88 89
    const_iterator begin() const { return ptr::shared_ptr<PropT>::get()->begin(); }
    iterator begin() { return ptr::shared_ptr<PropT>::get()->begin(); }
90

91 92
    const_iterator end() const { return ptr::shared_ptr<PropT>::get()->end(); }
    iterator end() { return ptr::shared_ptr<PropT>::get()->end(); }
93

94 95
    reference operator[](size_t _idx) { return (*ptr::shared_ptr<PropT>::get())[_idx]; }
    const_reference operator[](size_t _idx) const { return (*ptr::shared_ptr<PropT>::get())[_idx]; }
96

97 98 99
    reference operator[](const OpenVolumeMeshHandle& _h) { return (*ptr::shared_ptr<PropT>::get())[_h.idx()]; }
    const_reference operator[](const OpenVolumeMeshHandle& _h) const { return (*ptr::shared_ptr<PropT>::get())[_h.idx()]; }

100
    virtual OpenVolumeMeshHandle handle() const;
101

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

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

Mike Kremer's avatar
Mike Kremer committed
106
protected:
107

108 109
    virtual void delete_multiple_entries(const std::vector<bool>& _tags);

Max Lyon's avatar
Max Lyon committed
110
    virtual void resize(size_t _size);
111

112 113 114 115 116 117 118 119 120 121
    virtual void set_handle(const OpenVolumeMeshHandle& _handle);
};

} // Namespace OpenVolumeMesh

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

#endif /* PROPERTYPTR_HH_ */