PCMPointer.h

Go to the documentation of this file.
00001 
00002 //
00003 // This source file is a part of ParCompMark
00004 // Parallel Compositing Benchmark Framework
00005 //
00006 // for latest info see http://parcompmark.sourceforge.net
00007 
00008 //
00009 // Copyright (C) 2006 IT2 ParCompMark Dev. Team
00010 // 
00011 // This program is free software; you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License
00013 // as published by the Free Software Foundation; either version 2
00014 // of the License, or (at your option) any later version.
00015 // 
00016 // This program is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 // GNU General Public License for more details.
00020 // 
00021 // You should have received a copy of the GNU General Public License
00022 // along with this program; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00024 
00027 
00028 #ifndef __PCM_POINTER_H__
00029 #  define __PCM_POINTER_H__
00030 
00031 //
00032 // Inner includes
00033 //
00034 
00035 #  include "PCMPremeditations.h"
00036 
00037 #  include "PCMException.h"
00038 
00039 #  include "PCMDummyLock.h"
00040 
00041 #  include "PCMMutex.h"
00042 
00043 namespace ParCompMark
00044 {
00045 
00055   template < typename T, class Lock > class Pointer
00056   {
00057 
00058         //
00059         // Unit test class
00060         //
00061 #  ifdef PARCOMPMARK_TEST
00062         friend class ParCompMarkTest::TestPointer;
00063 #  endif
00064 
00065         //
00066         // Typedefs
00067         //
00068 
00069    protected:
00070 
00072         typedef struct
00073 
00074         {                
00076          T *ptr;                                                                 
00078          bool dead;                                                                                                                              
00080          u32 usage;                                                                                                                                                                       
00082          bool ownMemory;                                                                                                                                                                                                                                                                                
00083          Lock lock;
00084         } Meta;
00085 
00086         //
00087         // Class constants
00088         //
00089 
00091 
00092 
00093    public:
00094 
00100         static const Pointer < T,
00101         Lock > *NULLPTR;
00102 
00104 
00105         //
00106         // Variables
00107         //
00108 
00110 
00111 
00112    protected:
00113 
00119         Meta * mMeta;
00120 
00122 
00123         //
00124         // Constructors & destructor
00125         //
00126 
00128 
00129 
00130    public:
00131 
00135         Pointer();
00136 
00142         explicit Pointer(const T * pointer, const bool & takeOwnership = true);
00143 
00148         Pointer(Pointer < T, Lock > &pointer);
00149 
00154         Pointer(const Pointer < T, Lock > &pointer);
00155 
00159         virtual ~ Pointer();
00160 
00162 
00163         //
00164         // Operators
00165         //
00166 
00168 
00169 
00170    public:
00171 
00177         virtual const Pointer < T, Lock > &operator =(const T * pointer);
00178 
00184         virtual const Pointer < T,
00185         Lock > &operator =(Pointer < T, Lock > &pointer);
00186 
00192         virtual const Pointer < T,
00193         Lock > &operator =(const Pointer < T, Lock > &pointer);
00194 
00199         virtual T *operator ->();
00200 
00206         virtual bool operator ==(const T * pointer);
00207 
00213         virtual bool operator ==(Pointer < T, Lock > &pointer);
00214 
00220         virtual bool operator !=(const T * pointer);
00221 
00227         virtual bool operator !=(Pointer < T, Lock > &pointer);
00228 
00230 
00231         //
00232         // Methods
00233         //
00234 
00236 
00237 
00238    public:
00239 
00244         virtual bool isNull() const;
00245 
00250         virtual bool isNotNull() const;
00251 
00256         virtual void assignWithLock(Pointer < T, Lock > &pointer);
00257 
00262         virtual void reference(const T * pointer);
00263 
00268         virtual T *getPtr();
00269 
00274         virtual void kill(const bool & force = false);
00275 
00287         virtual void setNull(const bool & force = false);
00288 
00292         virtual void lock();
00293 
00298         virtual bool trylock();
00299 
00303         virtual void unlock();
00304 
00309         virtual bool getLocked() const;
00310 
00311    protected:
00312 
00318         virtual void _deletePointer(const bool & force = false, const bool & keepLock = false);
00319 
00325         virtual void _assignCPointer(const T * pointer, const bool & takeOwnership = true);
00326 
00332         virtual void _assignPointer(Pointer < T, Lock > &pointer, const bool & keepLock = false);
00333 
00339         virtual void _switchPointer(Pointer < T, Lock > &pointer, const bool & keepLock = false);
00340 
00346         virtual bool _equalsCPointer(const T * pointer) const;
00347 
00353         virtual bool _equalsPointer(Pointer < T, Lock > &pointer) const;
00354 
00356 
00357   };
00358 
00359   //
00360   // Include header implementation
00361   //
00362 
00363 #  include "PCMPointer_impl.h"
00364 
00365 }
00366 
00367 #endif