36 #include <Pt/Atomicity.h>
37 #include <Pt/SerializationInfo.h>
106 template <
typename T>
107 class InternalRefCounted
111 bool unlink(T*
object)
119 void link(
const InternalRefCounted& ptr, T*
object)
134 template <
typename T>
140 {
return _count ? *_count : 0; }
151 if ( _count && --*_count <= 0)
167 if(ptr._count == 0) {
168 _count =
new unsigned(1);
185 template <
typename T>
186 class ExternalAtomicRefCounted
190 {
return rc ? atomicGet(*rc) : 0; }
193 ExternalAtomicRefCounted()
197 bool unlink(T*
object)
199 if (
object && atomicDecrement(*rc) <= 0)
210 void link(
const ExternalAtomicRefCounted& ptr, T*
object)
215 rc =
new atomic_t(1);
219 atomicIncrement(*rc);
227 volatile atomic_t* rc;
239 template <
typename T>
243 static void destroy(T* ptr)
248 template <
typename T>
249 class FreeDestroyPolicy
257 template <
typename ObjectType>
258 class ArrayDestroyPolicy
261 static void destroy(ObjectType* ptr)
271 explicit AutoPtrRef(T* rhs)
289 typename Destroy = DeletePolicy<T> >
293 typedef T element_type;
315 { this->destroy(ap); }
319 operator AutoPtrRef<Y>()
321 return AutoPtrRef<Y>(
release() );
353 operator bool ()
const
383 template <
typename T>
384 AutoPtr<T> move(AutoPtr<T>& p)
386 return AutoPtr<T>( AutoPtrRef<T>(p) );
393 template <
typename T,
typename D,
typename T2,
typename D2>
395 {
return a.
get() == b.
get(); }
401 template <
typename T,
typename D,
typename T2>
403 {
return a.
get() == b; }
410 template <
typename T,
typename D,
typename T2,
typename D2>
412 {
return a.
get() != b.
get(); }
418 template <
typename T,
typename D,
typename T2>
420 {
return a.
get() != b; }
427 template <
typename T,
typename D,
typename T2,
typename D2>
429 {
return a.v() < b.
get(); }
435 template <
typename T,
typename D,
typename T2>
436 bool operator<(const AutoPtr<T, D>& a,
const T2* b)
437 {
return a.get() < b; }
457 template <
typename T,
480 { this->link(*
this, ptr); }
486 { this->link(ptr, ptr.object); }
492 if (this->unlink(
object))
493 this->destroy(
object);
500 if(
object == ptr.object)
503 if( this->unlink(
object) )
504 this->destroy(
object);
508 this->link(ptr,
object);
513 void reset(T* ptr = 0)
518 if( this->unlink(
object) )
519 this->destroy(
object);
523 this->link(*
this,
object);
539 {
return object == 0; }
543 operator bool ()
const
544 {
return object != 0; }
562 template <
typename T,
class O,
typename D,
typename T2,
typename O2,
typename D2>
564 {
return a.
get() == b.
get(); }
570 template <
typename T,
typename O,
typename D,
typename T2>
572 {
return a.
get() == b; }
579 template <
typename T,
typename O,
typename D,
typename T2,
typename O2,
typename D2>
581 {
return a.
get() != b.
get(); }
587 template <
typename T,
typename O,
typename D,
typename T2>
589 {
return a.
get() != b; }
596 template <
typename T,
typename O,
typename D,
typename T2,
typename O2,
typename D2>
598 {
return a.
get() < b.get(); }
604 template <
typename T,
typename O,
typename D,
typename T2>
605 bool operator<(const SmartPtr<T, O, D>& a,
const T2* b)
606 {
return a.get() < b; }
613 template <
typename T,
typename M,
typename D >
631 template <
typename T,
typename M,
typename D >
648 template <
typename T,
typename M>
659 template <
typename T,
typename M,
typename D >
662 if( ! sp.
get() || ! si.
save( *sp ) )
672 template <
typename T,
typename M,
typename D >
673 void operator <<=(Pt::SerializationInfo& si, const SmartPtr<T, M, D>& sp)
675 if( sp.getPointer() )
681 si <<= sp.getPointer();
687 #endif // PT_SMARTPTR_H
ExternalRefCounted()
Default constructor.
Definition: SmartPtr.h:144
Policy based smart pointer.
Definition: SmartPtr.h:460
bool operator!=(const SmartPtr< T, O, D > &a, const T2 *b)
Equality comparison operator.
Definition: SmartPtr.h:588
T * get() const
Access value.
Definition: SmartPtr.h:325
SerializationInfo & out() const
Returns the SerializationInfo to save to.
Definition: SerializationInfo.h:848
Loads referencable types.
Definition: SerializationInfo.h:911
SmartPtr(T *ptr)
Constructs from a pointer to manage.
Definition: SmartPtr.h:478
T * operator->() const
Access value.
Definition: SmartPtr.h:335
T * getTarget() const
Returns a pointer to the refernced type.
Definition: FixupInfo.h:81
Non-intrusive reference counting for SmartPtr.
Definition: SmartPtr.h:135
Fixup of references during serialization.
Definition: FixupInfo.h:42
bool isReference() const
Returns true if reference.
Definition: SerializationInfo.h:168
RefLinked()
Default constructor.
Definition: SmartPtr.h:58
bool operator==(const AutoPtr< T, D > &a, const AutoPtr< T2, D2 > &b)
Equality comparison operator.
Definition: SmartPtr.h:394
bool operator!() const
Returns true if the raw pointer is null.
Definition: SmartPtr.h:538
const SerializationInfo & in() const
Returns the SerializationInfo to load from.
Definition: SerializationInfo.h:921
bool operator!=(const AutoPtr< T, D > &a, const T2 *b)
Equality comparison operator.
Definition: SmartPtr.h:419
void save(Pt::SaveInfo &si, const SmartPtr< T, M, D > &sp)
Custom saving for serialization.
Definition: SmartPtr.h:660
void reset(T *ptr=0)
Reset value.
Definition: SmartPtr.h:365
T * get()
Get non-owning pointer.
Definition: SmartPtr.h:548
SmartPtr(const SmartPtr &ptr)
Copy constructor.
Definition: SmartPtr.h:484
T & operator*() const
Access value.
Definition: SmartPtr.h:330
SmartPtr & operator=(const SmartPtr &ptr)
Assign from another SmartPtr.
Definition: SmartPtr.h:498
AutoPtr(T *ptr=0)
Default constructor.
Definition: SmartPtr.h:297
bool operator==(const SmartPtr< T, O, D > &a, const T2 *b)
Equality comparison operator.
Definition: SmartPtr.h:571
~SmartPtr()
Destructor.
Definition: SmartPtr.h:490
T * operator->() const
Access value.
Definition: SmartPtr.h:528
T * release()
Release ownership.
Definition: SmartPtr.h:357
bool operator!=(const SmartPtr< T, O, D > &a, const SmartPtr< T2, O2, D2 > &b)
Equality comparison operator.
Definition: SmartPtr.h:580
bool save(const T &type)
Returns true if type was saved, false if type was already saved.
Definition: SerializationInfo.h:854
bool unlink(T *object)
unlink a smart pointer from a managed object
Definition: SmartPtr.h:149
Saves referencable types.
Definition: SerializationInfo.h:838
void fixup(const Pt::FixupInfo &fixup, SmartPtr< T, M, D > &fixme)
Custom fixup for deserialization.
Definition: SmartPtr.h:614
void load(const LoadInfo &li, SmartPtr< T, M, D > &sp)
Custom loading for deserialization.
Definition: SmartPtr.h:632
bool operator==(const SmartPtr< T, O, D > &a, const SmartPtr< T2, O2, D2 > &b)
Equality comparison operator.
Definition: SmartPtr.h:563
void link(const ExternalRefCounted &ptr, T *object)
link a smart pointer to a managed object
Definition: SmartPtr.h:163
~AutoPtr()
Destructor.
Definition: SmartPtr.h:314
AutoPtr & operator=(AutoPtrRef< T > rhs)
Assignment operator.
Definition: SmartPtr.h:307
bool isNull() const
Returns true if null.
Definition: FixupInfo.h:76
void load(T &type) const
Loads the type.
Definition: SerializationInfo.h:927
bool unlink(T *object)
Unlink a smart pointer from a managed object.
Definition: SmartPtr.h:64
SmartPtr()
Default Constructor.
Definition: SmartPtr.h:472
bool operator!() const
Returns true if nullptr.
Definition: SmartPtr.h:341
Represents arbitrary types during serialization.
Definition: SerializationInfo.h:58
void loadReference(T &fixme, unsigned mid=0) const
Load a reference during deserialization.
Definition: SerializationInfo.h:575
bool operator!=(const AutoPtr< T, D > &a, const AutoPtr< T2, D2 > &b)
Equality comparison operator.
Definition: SmartPtr.h:411
int refs() const
Returns the refcount.
Definition: SmartPtr.h:139
bool operator==(const AutoPtr< T, D > &a, const T2 *b)
Equality comparison operator.
Definition: SmartPtr.h:402
Reference linking policy for SmartPtr.
Definition: SmartPtr.h:50
Policy based Auto pointer.
Definition: SmartPtr.h:290
Deleter policy for SmartPtr.
Definition: SmartPtr.h:240
AutoPtr(AutoPtrRef< T > rhs)
Copy constructor.
Definition: SmartPtr.h:302
void link(const RefLinked &ptr, T *object)
Link a smart pointer to a managed object.
Definition: SmartPtr.h:84
T & operator*() const
Access value.
Definition: SmartPtr.h:533