Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages

pointer.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                 pointer.h  -  Reference counting and smart pointers
00003                              -------------------
00004     begin                : Tue Oct 30 2001
00005     copyright            : (C) 2001 by Reality Rift Studios
00006     email                : mattias@realityrift.com
00007  ***************************************************************************
00008 
00009  The contents of this file are subject to the Mozilla Public License Version
00010  1.1 (the "License"); you may not use this file except in compliance with
00011  the License. You may obtain a copy of the License at 
00012  http://www.mozilla.org/MPL/
00013 
00014  Software distributed under the License is distributed on an "AS IS" basis,
00015  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00016  for the specific language governing rights and limitations under the
00017  License.
00018 
00019  The Original Code is the NeoEngine, pointer.h
00020 
00021  The Initial Developer of the Original Code is Mattias Jansson.
00022  Portions created by Mattias Jansson are Copyright (C) 2001
00023  Reality Rift Studios. All Rights Reserved.
00024 
00025  ***************************************************************************/
00026 
00027 #ifndef __NEPOINTER_H
00028 #define __NEPOINTER_H
00029 
00030 
00037 #include "base.h"
00038 
00039 #include <assert.h>
00040 
00041 #ifdef WIN32
00042 #  include <vector>
00043 #endif
00044 
00045 
00046 namespace NeoEngine
00047 {
00048 
00049 
00059 class NEOENGINE_API RefCounter
00060 {
00061     private:
00062 
00064         int                                           m_iRefCount;
00065 
00066 
00067     public:
00068 
00072         inline                                        RefCounter();
00073 
00077         inline virtual                               ~RefCounter();
00078 
00082         inline void                                   IncRef();
00083 
00087         inline void                                   DecRef();
00088 
00092         inline int                                    GetRefCount() const;
00093 };
00094 
00095 
00106 template < class T > class Pointer
00107 {
00108     private:
00109 
00111         T                                            *m_pkObject;
00112 
00113     public:
00114 
00119         inline                                        Pointer( T *pkObject = 0 );
00120 
00125         inline                                        Pointer( const Pointer< T > &rkPointer );
00126 
00130         inline                                       ~Pointer();
00131 
00135         inline                                        operator const bool () const;
00136 
00140         inline                                        operator T* ();
00141 
00145         inline                                        operator const T* () const;
00146 
00150         inline T                                     &operator * ();
00151 
00155         inline const T                               &operator * () const;
00156 
00160         inline T                                     *operator -> ();
00161 
00165         inline const T                               *operator -> () const;
00166 
00170         inline bool                                   operator !() const;
00171 
00177         inline Pointer< T >                          &operator = ( const Pointer< T > &rkPointer );
00178 
00184         inline Pointer< T >                          &operator = ( T *pkObject );
00185 
00190         inline bool                                   operator == ( const Pointer< T > &rkPointer ) const;
00191 
00196         inline bool                                   operator == ( const T *pkObject ) const;
00197 
00202         inline bool                                   operator != ( const Pointer< T > &rkPointer ) const;
00203 
00208         inline bool                                   operator != ( const T *pkObject ) const;
00209 
00214         inline bool                                   operator < ( const Pointer< T > &rkPointer ) const;
00215 
00220         inline bool                                   operator < ( const T *pkObject ) const;
00221 };
00222 
00223 
00224 #include "pointer_inl.h"
00225 
00226 
00227 //Macros for easy typing
00228 
00229 #ifdef WIN32
00230 #  ifdef _MSC_VER
00231 #    pragma warning( disable : 4786 )
00232 #  endif
00233 #  if ( _MSC_VER >= 1300 )
00234 #    define SmartPointer( classname ) \
00235        class classname; \
00236        typedef Pointer< classname > classname##Ptr; \
00237        EXPIMP_TEMPLATE template class NEOENGINE_API Pointer< classname >; \
00238        EXPIMP_TEMPLATE template class NEOENGINE_API std::allocator< Pointer< classname > >; \
00239        EXPIMP_TEMPLATE template class NEOENGINE_API std::vector< Pointer< classname > >
00240 #  elif defined( _MSC_VER )
00241 #    define SmartPointer( classname ) \
00242        class classname; \
00243        typedef Pointer< classname > classname##Ptr; \
00244        EXPIMP_TEMPLATE template class NEOENGINE_API Pointer< classname >; \
00245        EXPIMP_TEMPLATE template class NEOENGINE_API std::vector< Pointer< classname > >
00246 #  else
00247 #    define SmartPointer(classname) typedef Pointer< classname > classname##Ptr
00248 #  endif
00249 #else
00250 #  define SmartPointer(classname) typedef Pointer< classname > classname##Ptr
00251 #endif
00252 
00253 
00254 };
00255 
00256 
00257 #endif

Generated on Wed Jan 21 14:21:07 2004 for NeoEngine by doxygen 1.3.5