PCMPointer.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00027
00028 #ifndef __PCM_POINTER_H__
00029 # define __PCM_POINTER_H__
00030
00031
00032
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
00060
00061 # ifdef PARCOMPMARK_TEST
00062 friend class ParCompMarkTest::TestPointer;
00063 # endif
00064
00065
00066
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
00088
00089
00091
00092
00093 public:
00094
00100 static const Pointer < T,
00101 Lock > *NULLPTR;
00102
00104
00105
00106
00107
00108
00110
00111
00112 protected:
00113
00119 Meta * mMeta;
00120
00122
00123
00124
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
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
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
00361
00362
00363 # include "PCMPointer_impl.h"
00364
00365 }
00366
00367 #endif