- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# Core/Utils/AutoPropertyHandleT.hh

    00001 /*===========================================================================*\
    00002  *                                                                           *
    00003  *                               OpenMesh                                    *
    00004  *      Copyright (C) 2001-2004 by Computer Graphics Group, RWTH Aachen      *
    00005  *                           www.openmesh.org                                *
    00006  *                                                                           *
    00007  *---------------------------------------------------------------------------*
    00008  *                                                                           *
    00009  *                                License                                    *
    00010  *                                                                           *
    00011  *  This library is free software; you can redistribute it and/or modify it  *
    00012  *  under the terms of the GNU Library General Public License as published   *
    00013  *  by the Free Software Foundation, version 2.                              *
    00014  *                                                                           *
    00015  *  This library is distributed in the hope that it will be useful, but      *
    00016  *  WITHOUT ANY WARRANTY; without even the implied warranty of               *
    00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        *
    00018  *  Library General Public License for more details.                         *
    00019  *                                                                           *
    00020  *  You should have received a copy of the GNU Library General Public        *
    00021  *  License along with this library; if not, write to the Free Software      *
    00022  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                *
    00023  *                                                                           *
    00024 \*===========================================================================*/
    00025
    00026 #ifndef OPENMESH_AutoPropertyHandleT_HH
    00027 #define OPENMESH_AutoPropertyHandleT_HH
    00028
    00029 //== INCLUDES =================================================================
    00030
    00031 //== NAMESPACES ===============================================================
    00032
    00033 namespace OpenMesh {
    00034
    00035 //== CLASS DEFINITION =========================================================
    00036
    00037 template <class Mesh_, class PropertyHandle_>
    00038 class AutoPropertyHandleT : public PropertyHandle_
    00039 {
    00040 public:
    00041
    00042   typedef Mesh_                             Mesh;
    00043   typedef PropertyHandle_                   PropertyHandle;
    00044   typedef PropertyHandle                    Base;
    00045   typedef typename PropertyHandle::Value    Value;
    00046   typedef AutoPropertyHandleT<Mesh, PropertyHandle>
    00047                                             Self;
    00048 protected:
    00049
    00050   Mesh&                                     m_;
    00051   bool                                      own_property_;//ref counting?
    00052
    00053 public:
    00054
    00055   explicit AutoPropertyHandleT(Mesh& _m, const std::string& _pp_name = std::string())
    00056   : m_(_m)
    00057   {
    00058     own_property_ = _pp_name.empty() || !m_.get_property_handle(*this, _pp_name);
    00059     if (own_property_)
    00060     {
    00061       m_.add_property(*this, _pp_name);
    00062     }
    00063   }
    00064
    00065   AutoPropertyHandleT(Mesh& _m, PropertyHandle _pph)
    00066   : Base(_pph.idx()), m_(_m), own_property_(false)
    00067   {}
    00068
    00069   AutoPropertyHandleT(const Self& _other)
    00070   : Base(_other.idx()), m_(_other.m_), own_property_(false)
    00071   {}
    00072
    00073   ~AutoPropertyHandleT()
    00074   {
    00075     if (own_property_)
    00076     {
    00077       m_.remove_property(*this);
    00078     }
    00079   }
    00080
    00081   template <class _Handle>
    00082   inline Value&                             operator [] (_Handle _hnd)
    00083   {
    00084     return m_.property(*this, _hnd);
    00085   }
    00086
    00087   template <class _Handle>
    00088   inline const Value&                       operator [] (_Handle _hnd) const
    00089   {
    00090     return m_.property(*this, _hnd);
    00091   }
    00092
    00093   inline bool                               own_property() const
    00094   {
    00095     return own_property_;
    00096   }
    00097
    00098   inline void                               free_property()
    00099   {
    00100     own_property_ = false;
    00101   }
    00102
    00103   inline void                               delete_property()
    00104   {
    00105     assert(own_property_);//only the owner can delete the property
    00106     m_.remove_property(*this);
    00107     own_property_ = false;
    00108     invalidate();
    00109   }
    00110 };
    00111
    00112 //=============================================================================
    00113 } // namespace OpenMesh
    00114 //=============================================================================
    00115 #endif // OPENMESH_AutoPropertyHandleT_HH defined
    00116 //=============================================================================