#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/Core/Base/SmartPtr.hh" // This file is part of RAVL, Recognition And Vision Library // Copyright (C) 2001, University of Surrey // This code may be redistributed under the terms of the GNU Lesser // General Public License (LGPL). See the lgpl.licence file for details or // see http://www.gnu.org/copyleft/lesser.html // file-header-ends-here #ifndef RAVL_SMARTPTR_HEADER #define RAVL_SMARTPTR_HEADER 1 //! rcsid="$Id: SmartPtr.hh,v 1.5 2002/08/08 16:03:10 craftit Exp $" //! lib=RavlCore //! author="Charles Galambos" //! docentry="Ravl.Core.Reference Counting" //! file="Ravl/Core/Base/SmartPtr.hh" #include "Ravl/RefCounter.hh" namespace RavlN { //! userlevel=Advanced //: Smart pointer. template class SmartPtrC : public RCHandleC { public: SmartPtrC() {} //: Default constructor. SmartPtrC(const RCHandleC &handle) : RCHandleC(handle) {} //: Construct from a normal handle. SmartPtrC(DataT &data) : RCHandleC(data) {} //: Construct from data. DataT *BodyPtr() { return body; } //: Access pointer to body. const DataT *BodyPtr() const { return body; } //: Access pointer to body. DataT *operator->() { return &RCHandleC::Body(); } //: Access body. const DataT *operator->() const { return &RCHandleC::Body(); } //: Access body. operator DataT *() { return body; } //: Access body. operator const DataT *() const { return body; } //: Access body. const SmartPtrC &operator=(const DataT *other) { DataT *oth = const_cast(other); if(oth != 0) oth->IncRefCounter(); if(body != 0) { if(body->DecRefCounter()) delete body; } body = oth; return *this; } //: Assign handle. }; } #endif