23 #define mImpPtrManPointerAccess( qual, type ) \ 24 inline qual type* ptr() qual { return this->ptr_; } \ 25 inline operator qual type*() qual { return this->ptr_; }\ 26 inline qual type* operator ->() qual { return this->ptr_; } \ 27 inline qual type& operator *() qual { return *this->ptr_; } 33 {
if ( isowner )
delete ptr; ptr = 0; }
38 {
if ( isowner )
delete [] ptr; ptr = 0; }
50 inline bool operator !()
const {
return !ptr_; }
52 inline T*
set(T* p,
bool doerase=
true);
54 inline T*
release() {
return set(0,
false); }
56 inline void erase() {
set( 0, true ); }
58 inline bool setIfNull(T* p);
60 typedef T* (*PointerCreator)();
61 inline T* createIfNull(PointerCreator=createSingleObject<T>);
66 typedef void (*PtrFunc)(T*);
67 inline PtrManBase(PtrFunc setfunc,PtrFunc deletor,T*);
94 static
void deleteFunc( T* p ) {
delete p; }
113 static
void deleteFunc( T* p ) {
delete p; }
133 const T& operator[](
int)
const;
135 const T& operator[](
od_int64)
const;
162 static
void deleteFunc( T* p ) {
delete p; }
175 { this->
set( p, true );
return *
this; }
182 static
void ref(T* p) { p->ref(); }
183 static void unRef(T* p) {
if ( p ) p->unRef(); }
201 static
void ref(T* p) { p->ref(); }
202 static void unRef(T* p) {
if ( p ) p->unRef(); }
206 #undef mImpPtrManPointerAccess 210 template <
class T>
inline 212 : deletefunc_( deletor )
213 , setfunc_( setfunc )
219 template <
class T>
inline 225 T* oldptr =
ptr_.exchange(p);
236 template <
class T>
inline 239 if (
ptr_.setIfEqual( 0, p ) )
250 template <
class T>
inline 256 T* newptr = creator();
270 template <
class T>
inline 274 pErrMsg(
"Should not be called");
278 template <
class T>
inline 282 pErrMsg(
"Should not be called");
287 template <
class T>
inline 293 template <
class T>
inline 301 template <
class T>
inline 305 pErrMsg(
"Should not be called");
309 template <
class T>
inline 313 pErrMsg(
"Should not be called");
318 template <
class T>
inline 324 template <
class T>
inline 327 this->
set(
const_cast<T*
>( p ) );
332 template <
class T>
inline 336 pErrMsg(
"Should not be called");
340 template <
class T>
inline 344 pErrMsg(
"Should not be called");
349 template <
class T>
inline 356 template <
class T>
inline 365 template <
class T>
inline 372 return this->
ptr_[(size_t) idx];
376 template <
class T>
inline 383 return this->
ptr_[(size_t) idx];
387 template <
class T>
inline 394 return this->
ptr_[(size_t) idx];
398 template <
class T>
inline 405 return this->
ptr_[(size_t) idx];
412 template <
class T>
inline 416 pErrMsg(
"Shold not be called");
420 template <
class T>
inline 426 template <
class T>
inline 429 this->
set(
const_cast<T*
>(p) );
434 template <
class T>
inline 440 template <
class T>
inline 446 template <
class T>
inline 449 this->
set(
const_cast<T*
>(p.
ptr()) );
454 template <
class T>
inline 460 template <
class T>
inline 466 template <
class T>
inline 469 this->
set(
const_cast<T*
>(p.
ptr()) );
474 template <
class T>
inline 477 this->
set(
const_cast<T*
>( p ) );
PtrMan(const PtrMan< T > &)
Don't use.
Definition: ptrman.h:271
static void ref(T *p)
Definition: ptrman.h:182
static void deleteFunc(T *p)
Definition: ptrman.h:142
RefMan(const RefMan< T > &)
Definition: ptrman.h:435
#define od_int64
Definition: plftypes.h:36
#define private
Definition: winstreambuf.h:13
PtrManBase(PtrFunc setfunc, PtrFunc deletor, T *)
Definition: ptrman.h:211
ConstPtrMan(const ConstPtrMan< T > &)
Definition: ptrman.h:302
ConstArrPtrMan< T > & operator=(const T *p)
Definition: ptrman.h:427
ArrPtrMan< T > & operator=(T *p)
Definition: ptrman.h:357
int64_t size_
Definition: ptrman.h:144
static void unRef(T *p)
Definition: ptrman.h:183
ConstPtrMan< T > & operator=(const T *p)
Definition: ptrman.h:325
virtual ~PtrManBase()
Definition: ptrman.h:68
T *(* PointerCreator)()
Definition: ptrman.h:60
void deleteAndZeroArrPtr(T *&ptr, bool isowner=true)
Definition: ptrman.h:37
static void deleteFunc(T *p)
Definition: ptrman.h:94
PtrFunc deletefunc_
Definition: ptrman.h:73
static void unRef(T *p)
Definition: ptrman.h:202
ArrPtrMan(const ArrPtrMan< T > &)
Don't use.
Definition: ptrman.h:333
const T * ptr() const
Definition: ptrman.h:159
T * createIfNull(PointerCreator=createSingleObject< T >)
Definition: ptrman.h:251
ConstRefMan< T > & operator=(const T *p)
Definition: ptrman.h:475
Atomic instantiated with a pointer. The class really only handles the casting from a void* to a T*...
Definition: atomic.h:144
void setSize(int64_t size)
Definition: ptrman.h:138
#define mImpPtrManPointerAccess(qual, type)
Definition: ptrman.h:23
T * createSingleObject()
Definition: ptrman.h:40
void erase()
Definition: ptrman.h:56
void forceCrash(bool withdump)
static void deleteFunc(T *p)
Definition: ptrman.h:113
void deleteAndZeroPtr(T *&ptr, bool isowner=true)
Definition: ptrman.h:32
RefMan< T > & operator=(T *p)
Definition: ptrman.h:174
T * release()
Returns pointer. I won't take care of it any longer.
Definition: ptrman.h:54
ConstArrPtrMan(const ConstArrPtrMan< T > &)
Definition: ptrman.h:413
const T * ptr() const
Definition: ptrman.h:198
T * set(T *p, bool doerase=true)
Returns old pointer if not erased.
Definition: ptrman.h:220
ConstRefMan(const ConstRefMan< T > &)
Definition: ptrman.h:455
#define mClass(module)
Definition: commondefs.h:164
#define pErrMsg(msg)
Definition: errmsg.h:60
T * createObjectArray(int64_t sz)
Definition: ptrman.h:41
Threads::AtomicPointer< T > ptr_
Definition: ptrman.h:70
const T * ptr() const
Definition: ptrman.h:177
PtrFunc setfunc_
Definition: ptrman.h:72
static void deleteFunc(T *p)
Definition: ptrman.h:162
bool setIfNull(T *p)
Definition: ptrman.h:237
static void ref(T *p)
Definition: ptrman.h:201
PtrMan< T > & operator=(T *p)
Definition: ptrman.h:294