Pointer.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (c) 2003-2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED,
00008 //  AS TO THE CORRECTNESS OF THIS CODE OR ANY DERIVATIVE
00009 //  WORKS WHICH INCORPORATE IT.
00010 //
00011 //  AUTODESK PROVIDES THE CODE ON AN "AS-IS" BASIS
00012 //  AND EXPLICITLY DISCLAIMS ANY LIABILITY, INCLUDING
00013 //  CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00014 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00015 //
00016 //  Use, duplication, or disclosure by the U.S. Government is subject to
00017 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00018 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00019 //  Data and Computer Software), as applicable.
00020 //
00021 
00022 
00023 #ifndef _DWFCORE_POINTER_H
00024 #define _DWFCORE_POINTER_H
00025 
00031 
00032 #include "dwfcore/Core.h"
00033 
00034 
00035 namespace DWFCore
00036 {
00037 
00048 template<class T>
00049 class DWFPointer : virtual public DWFCoreMemory
00050 {
00051 
00052 public:
00053 
00071     DWFPointer( T* pT, bool bArray )
00072         : _pT( pT )
00073         , _bArray( bArray )
00074     {;}
00075 
00081     virtual ~DWFPointer()
00082     {
00083         if (_pT)
00084         {
00085             if (_bArray)
00086             {
00087                 DWFCORE_FREE_MEMORY( _pT );
00088             }
00089             else
00090             {
00091                 DWFCORE_FREE_OBJECT( _pT );
00092             }
00093         }
00094     }
00095 
00102     DWFPointer&
00103     operator=( T* pT )
00104         throw()
00105     {
00106         _pT = pT;
00107         return *this;
00108     }
00109 
00116     operator T*() const
00117         throw()
00118     {
00119         return _pT;
00120     }
00121 
00128     operator const T*() const
00129         throw()
00130     {
00131         return (const T*)_pT;
00132     }
00133 
00140     operator void*() const
00141         throw()
00142     {
00143         return (void*)_pT;
00144     }
00145 
00152     operator const void*() const
00153         throw()
00154     {
00155         return (const void*)_pT;
00156     }
00157 
00164     operator T&() const
00165     {
00166         return *_pT;
00167     }
00168 
00175     operator const T&() const
00176     {
00177         return (const T&)*_pT;
00178     }
00179 
00188     bool isNull() const
00189         throw()
00190     {
00191         return (_pT == NULL);
00192     }
00193 
00200     T* operator->() const
00201     {
00202         return _pT;
00203     }
00204 
00205 private:
00206 
00207     T*      _pT;
00208     bool    _bArray;
00209 
00210 private:
00211 
00212     //
00213     // not implemented
00214     //
00215 
00216     DWFPointer( const DWFPointer& );
00217     const DWFPointer& operator=( const DWFPointer& );
00218 };
00219 
00220 }
00221 
00222 #endif

Generated on Tue Jan 6 22:39:29 2009 for Autodesk DWF Core Library by  doxygen 1.4.5