00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef OPENMESH_AutoPropertyHandleT_HH
00027 #define OPENMESH_AutoPropertyHandleT_HH
00028
00029
00030
00031
00032
00033 namespace OpenMesh {
00034
00035
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_;
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_);
00106 m_.remove_property(*this);
00107 own_property_ = false;
00108 invalidate();
00109 }
00110 };
00111
00112
00113 }
00114
00115 #endif // OPENMESH_AutoPropertyHandleT_HH defined
00116