From: <ric...@us...> - 2008-11-10 05:55:14
|
Revision: 903 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=903&view=rev Author: rich_sposato Date: 2008-11-10 05:55:12 +0000 (Mon, 10 Nov 2008) Log Message: ----------- Fixed bug 2082935 using overloaded version of AtomicDecrement. Modified Paths: -------------- trunk/include/loki/SmartPtr.h Modified: trunk/include/loki/SmartPtr.h =================================================================== --- trunk/include/loki/SmartPtr.h 2008-11-10 05:47:06 UTC (rev 902) +++ trunk/include/loki/SmartPtr.h 2008-11-10 05:55:12 UTC (rev 903) @@ -2,14 +2,14 @@ // The Loki Library // Copyright (c) 2001 by Andrei Alexandrescu // This code accompanies the book: -// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design +// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design // Patterns Applied". Copyright (c) 2001. Addison-Wesley. -// Permission to use, copy, modify, distribute and sell this software for any -// purpose is hereby granted without fee, provided that the above copyright -// notice appear in all copies and that both that copyright notice and this +// Permission to use, copy, modify, distribute and sell this software for any +// purpose is hereby granted without fee, provided that the above copyright +// notice appear in all copies and that both that copyright notice and this // permission notice appear in supporting documentation. -// The author or Addison-Wesley Longman make no representations about the -// suitability of this software for any purpose. It is provided "as is" +// The author or Addison-Wesley Longman make no representations about the +// suitability of this software for any purpose. It is provided "as is" // without express or implied warranty. //////////////////////////////////////////////////////////////////////////////// #ifndef LOKI_SMARTPTR_INC_ @@ -61,7 +61,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \class HeapStorage /// -/// \ingroup SmartPointerStorageGroup +/// \ingroup SmartPointerStorageGroup /// Implementation of the StoragePolicy used by SmartPtr. Uses explicit call /// to T's destructor followed by call to free. //////////////////////////////////////////////////////////////////////////////// @@ -76,10 +76,10 @@ typedef T* PointerType; /// type returned by operator-> typedef T& ReferenceType; /// type returned by operator* - HeapStorage() : pointee_(Default()) + HeapStorage() : pointee_(Default()) {} - // The storage policy doesn't initialize the stored pointer + // The storage policy doesn't initialize the stored pointer // which will be initialized by the OwnershipPolicy's Clone fn HeapStorage(const HeapStorage&) : pointee_(0) {} @@ -87,16 +87,16 @@ template <class U> HeapStorage(const HeapStorage<U>&) : pointee_(0) {} - + HeapStorage(const StoredType& p) : pointee_(p) {} - + PointerType operator->() const { return pointee_; } - + ReferenceType operator*() const { return *pointee_; } - + void Swap(HeapStorage& rhs) { std::swap(pointee_, rhs.pointee_); } - + // Accessors template <class F> friend typename HeapStorage<F>::PointerType GetImpl(const HeapStorage<F>& sp); @@ -122,7 +122,7 @@ // Default value to initialize the pointer static StoredType Default() { return 0; } - + private: // Data StoredType pointee_; @@ -144,7 +144,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \class DefaultSPStorage /// -/// \ingroup SmartPointerStorageGroup +/// \ingroup SmartPointerStorageGroup /// Implementation of the StoragePolicy used by SmartPtr //////////////////////////////////////////////////////////////////////////////// @@ -158,10 +158,10 @@ typedef T* PointerType; // type returned by operator-> typedef T& ReferenceType; // type returned by operator* - DefaultSPStorage() : pointee_(Default()) + DefaultSPStorage() : pointee_(Default()) {} - // The storage policy doesn't initialize the stored pointer + // The storage policy doesn't initialize the stored pointer // which will be initialized by the OwnershipPolicy's Clone fn DefaultSPStorage(const DefaultSPStorage&) : pointee_(0) {} @@ -169,16 +169,16 @@ template <class U> DefaultSPStorage(const DefaultSPStorage<U>&) : pointee_(0) {} - + DefaultSPStorage(const StoredType& p) : pointee_(p) {} - + PointerType operator->() const { return pointee_; } - + ReferenceType operator*() const { return *pointee_; } - + void Swap(DefaultSPStorage& rhs) { std::swap(pointee_, rhs.pointee_); } - + // Accessors template <class F> friend typename DefaultSPStorage<F>::PointerType GetImpl(const DefaultSPStorage<F>& sp); @@ -203,7 +203,7 @@ // Default value to initialize the pointer static StoredType Default() { return 0; } - + private: // Data StoredType pointee_; @@ -225,7 +225,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \class LockedStorage /// -/// \ingroup SmartPointerStorageGroup +/// \ingroup SmartPointerStorageGroup /// Implementation of the StoragePolicy used by SmartPtr. /// /// Each call to operator-> locks the object for the duration of a call to a @@ -351,7 +351,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \class ArrayStorage /// -/// \ingroup SmartPointerStorageGroup +/// \ingroup SmartPointerStorageGroup /// Implementation of the ArrayStorage used by SmartPtr //////////////////////////////////////////////////////////////////////////////// @@ -365,10 +365,10 @@ typedef T* PointerType; // type returned by operator-> typedef T& ReferenceType; // type returned by operator* - ArrayStorage() : pointee_(Default()) + ArrayStorage() : pointee_(Default()) {} - // The storage policy doesn't initialize the stored pointer + // The storage policy doesn't initialize the stored pointer // which will be initialized by the OwnershipPolicy's Clone fn ArrayStorage(const ArrayStorage&) : pointee_(0) {} @@ -376,16 +376,16 @@ template <class U> ArrayStorage(const ArrayStorage<U>&) : pointee_(0) {} - + ArrayStorage(const StoredType& p) : pointee_(p) {} - + PointerType operator->() const { return pointee_; } - + ReferenceType operator*() const { return *pointee_; } - + void Swap(ArrayStorage& rhs) { std::swap(pointee_, rhs.pointee_); } - + // Accessors template <class F> friend typename ArrayStorage<F>::PointerType GetImpl(const ArrayStorage<F>& sp); @@ -401,11 +401,11 @@ // (Destruction might be taken over by the OwnershipPolicy) void Destroy() { delete [] pointee_; } - + // Default value to initialize the pointer static StoredType Default() { return 0; } - + private: // Data StoredType pointee_; @@ -427,7 +427,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \class RefCounted /// -/// \ingroup SmartPointerOwnershipGroup +/// \ingroup SmartPointerOwnershipGroup /// Implementation of the OwnershipPolicy used by SmartPtr /// Provides a classic external reference counting implementation //////////////////////////////////////////////////////////////////////////////// @@ -436,30 +436,30 @@ class RefCounted { public: - RefCounted() + RefCounted() : pCount_(static_cast<uintptr_t*>( SmallObject<>::operator new(sizeof(uintptr_t)))) { assert(pCount_!=0); *pCount_ = 1; } - - RefCounted(const RefCounted& rhs) + + RefCounted(const RefCounted& rhs) : pCount_(rhs.pCount_) {} - + // MWCW lacks template friends, hence the following kludge template <typename P1> - RefCounted(const RefCounted<P1>& rhs) + RefCounted(const RefCounted<P1>& rhs) : pCount_(reinterpret_cast<const RefCounted&>(rhs).pCount_) {} - + P Clone(const P& val) { ++*pCount_; return val; } - + bool Release(const P&) { if (!--*pCount_) @@ -470,21 +470,21 @@ } return false; } - + void Swap(RefCounted& rhs) { std::swap(pCount_, rhs.pCount_); } - + enum { destructiveCopy = false }; private: // Data uintptr_t* pCount_; }; - + //////////////////////////////////////////////////////////////////////////////// /// \struct RefCountedMT /// -/// \ingroup SmartPointerOwnershipGroup +/// \ingroup SmartPointerOwnershipGroup /// Implementation of the OwnershipPolicy used by SmartPtr /// Implements external reference counting for multithreaded programs /// Policy Usage: RefCountedMTAdj<ThreadingModel>::RefCountedMT @@ -499,7 +499,7 @@ /// implies a design flaw at a higher level. That race condition must be /// fixed at a higher design level, and no change to this class could fix it. //////////////////////////////////////////////////////////////////////////////// - + template <template <class, class> class ThreadingModel, class MX = LOKI_DEFAULT_MUTEX > struct RefCountedMTAdj @@ -512,7 +512,7 @@ typedef volatile CountType *CountPtrType; public: - RefCountedMT() + RefCountedMT() { pCount_ = static_cast<CountPtrType>( SmallObject<LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL>::operator new( @@ -522,13 +522,13 @@ ThreadingModel<RefCountedMT, MX>::AtomicAssign(*pCount_, 1); } - RefCountedMT(const RefCountedMT& rhs) + RefCountedMT(const RefCountedMT& rhs) : pCount_(rhs.pCount_) {} //MWCW lacks template friends, hence the following kludge template <typename P1> - RefCountedMT(const RefCountedMT<P1>& rhs) + RefCountedMT(const RefCountedMT<P1>& rhs) : pCount_(reinterpret_cast<const RefCountedMT<P>&>(rhs).pCount_) {} @@ -540,10 +540,12 @@ bool Release(const P&) { - if (!ThreadingModel<RefCountedMT, MX>::AtomicDecrement(*pCount_)) + bool isZero = false; + ThreadingModel< RefCountedMT, MX >::AtomicDecrement( *pCount_, 0, isZero ); + if ( isZero ) { SmallObject<LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL>::operator delete( - const_cast<CountType *>(pCount_), + const_cast<CountType *>(pCount_), sizeof(*pCount_)); return true; } @@ -564,7 +566,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \class COMRefCounted /// -/// \ingroup SmartPointerOwnershipGroup +/// \ingroup SmartPointerOwnershipGroup /// Implementation of the OwnershipPolicy used by SmartPtr /// Adapts COM intrusive reference counting to OwnershipPolicy-specific syntax //////////////////////////////////////////////////////////////////////////////// @@ -575,27 +577,27 @@ public: COMRefCounted() {} - + template <class U> COMRefCounted(const COMRefCounted<U>&) {} - + static P Clone(const P& val) { if(val!=0) val->AddRef(); return val; } - + static bool Release(const P& val) - { - if(val!=0) - val->Release(); - return false; + { + if(val!=0) + val->Release(); + return false; } - + enum { destructiveCopy = false }; - + static void Swap(COMRefCounted&) {} }; @@ -603,9 +605,9 @@ //////////////////////////////////////////////////////////////////////////////// /// \struct DeepCopy /// -/// \ingroup SmartPointerOwnershipGroup +/// \ingroup SmartPointerOwnershipGroup /// Implementation of the OwnershipPolicy used by SmartPtr -/// Implements deep copy semantics, assumes existence of a Clone() member +/// Implements deep copy semantics, assumes existence of a Clone() member /// function of the pointee type //////////////////////////////////////////////////////////////////////////////// @@ -614,27 +616,27 @@ { DeepCopy() {} - + template <class P1> DeepCopy(const DeepCopy<P1>&) {} - + static P Clone(const P& val) { return val->Clone(); } - + static bool Release(const P&) { return true; } - + static void Swap(DeepCopy&) {} - + enum { destructiveCopy = false }; }; - + //////////////////////////////////////////////////////////////////////////////// /// \class RefLinked /// -/// \ingroup SmartPointerOwnershipGroup +/// \ingroup SmartPointerOwnershipGroup /// Implementation of the OwnershipPolicy used by SmartPtr /// Implements reference linking //////////////////////////////////////////////////////////////////////////////// @@ -644,7 +646,7 @@ class LOKI_EXPORT RefLinkedBase { public: - RefLinkedBase() + RefLinkedBase() { prev_ = next_ = this; } RefLinkedBase(const RefLinkedBase& rhs); @@ -667,16 +669,16 @@ mutable const RefLinkedBase* next_; }; } - + template <class P> class RefLinked : public Private::RefLinkedBase { public: RefLinked() {} - + template <class P1> - RefLinked(const RefLinked<P1>& rhs) + RefLinked(const RefLinked<P1>& rhs) : Private::RefLinkedBase(rhs) {} @@ -692,11 +694,11 @@ return Private::RefLinkedBase::Merge( rhs ); } }; - + //////////////////////////////////////////////////////////////////////////////// /// \class DestructiveCopy /// -/// \ingroup SmartPointerOwnershipGroup +/// \ingroup SmartPointerOwnershipGroup /// Implementation of the OwnershipPolicy used by SmartPtr /// Implements destructive copy semantics (a la std::auto_ptr) //////////////////////////////////////////////////////////////////////////////// @@ -707,11 +709,11 @@ public: DestructiveCopy() {} - + template <class P1> DestructiveCopy(const DestructiveCopy<P1>&) {} - + template <class P1> static P Clone(P1& val) { @@ -719,20 +721,20 @@ val = P1(); return result; } - + static bool Release(const P&) { return true; } - + static void Swap(DestructiveCopy&) {} - + enum { destructiveCopy = true }; }; - + //////////////////////////////////////////////////////////////////////////////// /// \class NoCopy /// -/// \ingroup SmartPointerOwnershipGroup +/// \ingroup SmartPointerOwnershipGroup /// Implementation of the OwnershipPolicy used by SmartPtr /// Implements a policy that doesn't allow copying objects //////////////////////////////////////////////////////////////////////////////// @@ -743,11 +745,11 @@ public: NoCopy() {} - + template <class P1> NoCopy(const NoCopy<P1>&) {} - + static P Clone(const P&) { // Make it depended on template parameter @@ -755,20 +757,20 @@ LOKI_STATIC_CHECK(DependedFalse, This_Policy_Disallows_Value_Copying); } - + static bool Release(const P&) { return true; } - + static void Swap(NoCopy&) {} - + enum { destructiveCopy = false }; }; - + //////////////////////////////////////////////////////////////////////////////// /// \struct AllowConversion -/// -/// \ingroup SmartPointerConversionGroup +/// +/// \ingroup SmartPointerConversionGroup /// Implementation of the ConversionPolicy used by SmartPtr /// Allows implicit conversion from SmartPtr to the pointee type //////////////////////////////////////////////////////////////////////////////// @@ -784,7 +786,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \struct DisallowConversion /// -/// \ingroup SmartPointerConversionGroup +/// \ingroup SmartPointerConversionGroup /// Implementation of the ConversionPolicy used by SmartPtr /// Does not allow implicit conversion from SmartPtr to the pointee type /// You can initialize a DisallowConversion with an AllowConversion @@ -794,10 +796,10 @@ { DisallowConversion() {} - + DisallowConversion(const AllowConversion&) {} - + enum { allow = false }; void Swap(DisallowConversion&) @@ -807,7 +809,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \struct NoCheck /// -/// \ingroup SmartPointerCheckingGroup +/// \ingroup SmartPointerCheckingGroup /// Implementation of the CheckingPolicy used by SmartPtr /// Well, it's clear what it does :o) //////////////////////////////////////////////////////////////////////////////// @@ -817,11 +819,11 @@ { NoCheck() {} - + template <class P1> NoCheck(const NoCheck<P1>&) {} - + static void OnDefault(const P&) {} @@ -839,7 +841,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \struct AssertCheck /// -/// \ingroup SmartPointerCheckingGroup +/// \ingroup SmartPointerCheckingGroup /// Implementation of the CheckingPolicy used by SmartPtr /// Checks the pointer before dereference //////////////////////////////////////////////////////////////////////////////// @@ -849,15 +851,15 @@ { AssertCheck() {} - + template <class P1> AssertCheck(const AssertCheck<P1>&) {} - + template <class P1> AssertCheck(const NoCheck<P1>&) {} - + static void OnDefault(const P&) {} @@ -874,10 +876,10 @@ //////////////////////////////////////////////////////////////////////////////// /// \struct AssertCheckStrict /// -/// \ingroup SmartPointerCheckingGroup +/// \ingroup SmartPointerCheckingGroup /// Implementation of the CheckingPolicy used by SmartPtr /// Checks the pointer against zero upon initialization and before dereference -/// You can initialize an AssertCheckStrict with an AssertCheck +/// You can initialize an AssertCheckStrict with an AssertCheck //////////////////////////////////////////////////////////////////////////////// template <class P> @@ -885,28 +887,28 @@ { AssertCheckStrict() {} - + template <class U> AssertCheckStrict(const AssertCheckStrict<U>&) {} - + template <class U> AssertCheckStrict(const AssertCheck<U>&) {} - + template <class P1> AssertCheckStrict(const NoCheck<P1>&) {} - + static void OnDefault(P val) { assert(val); } - + static void OnInit(P val) { assert(val); } - + static void OnDereference(P val) { assert(val); } - + static void Swap(AssertCheckStrict&) {} }; @@ -914,7 +916,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \struct NullPointerException /// -/// \ingroup SmartPointerGroup +/// \ingroup SmartPointerGroup /// Used by some implementations of the CheckingPolicy used by SmartPtr //////////////////////////////////////////////////////////////////////////////// @@ -925,11 +927,11 @@ const char* what() const throw() { return "Null Pointer Exception"; } }; - + //////////////////////////////////////////////////////////////////////////////// /// \struct RejectNullStatic /// -/// \ingroup SmartPointerCheckingGroup +/// \ingroup SmartPointerCheckingGroup /// Implementation of the CheckingPolicy used by SmartPtr /// Checks the pointer upon initialization and before dereference //////////////////////////////////////////////////////////////////////////////// @@ -939,23 +941,23 @@ { RejectNullStatic() {} - + template <class P1> RejectNullStatic(const RejectNullStatic<P1>&) {} - + template <class P1> RejectNullStatic(const NoCheck<P1>&) {} - + template <class P1> RejectNullStatic(const AssertCheck<P1>&) {} - + template <class P1> RejectNullStatic(const AssertCheckStrict<P1>&) {} - + static void OnDefault(const P&) { // Make it depended on template parameter @@ -963,13 +965,13 @@ LOKI_STATIC_CHECK(DependedFalse, ERROR_This_Policy_Does_Not_Allow_Default_Initialization); } - + static void OnInit(const P& val) { if (!val) throw NullPointerException(); } - + static void OnDereference(const P& val) { if (!val) throw NullPointerException(); } - + static void Swap(RejectNullStatic&) {} }; @@ -977,7 +979,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \struct RejectNull /// -/// \ingroup SmartPointerCheckingGroup +/// \ingroup SmartPointerCheckingGroup /// Implementation of the CheckingPolicy used by SmartPtr /// Checks the pointer before dereference //////////////////////////////////////////////////////////////////////////////// @@ -987,31 +989,31 @@ { RejectNull() {} - + template <class P1> RejectNull(const RejectNull<P1>&) {} - + static void OnInit(P) {} static void OnDefault(P) {} - + void OnDereference(P val) { if (!val) throw NullPointerException(); } - + void OnDereference(P val) const { if (!val) throw NullPointerException(); } void Swap(RejectNull&) - {} + {} }; //////////////////////////////////////////////////////////////////////////////// /// \struct RejectNullStrict /// -/// \ingroup SmartPointerCheckingGroup +/// \ingroup SmartPointerCheckingGroup /// Implementation of the CheckingPolicy used by SmartPtr /// Checks the pointer upon initialization and before dereference //////////////////////////////////////////////////////////////////////////////// @@ -1021,15 +1023,15 @@ { RejectNullStrict() {} - + template <class P1> RejectNullStrict(const RejectNullStrict<P1>&) {} - + template <class P1> RejectNullStrict(const RejectNull<P1>&) {} - + static void OnInit(P val) { if (!val) throw NullPointerException(); } @@ -1040,7 +1042,7 @@ { OnInit(val); } void Swap(RejectNullStrict&) - {} + {} }; @@ -1056,13 +1058,13 @@ class ConversionPolicy = DisallowConversion, template <class> class CheckingPolicy = AssertCheck, template <class> class StoragePolicy = DefaultSPStorage, - template<class> class ConstnessPolicy = LOKI_DEFAULT_CONSTNESS + template<class> class ConstnessPolicy = LOKI_DEFAULT_CONSTNESS > class SmartPtr; //////////////////////////////////////////////////////////////////////////////// // class template SmartPtrDef (definition) -// this class added to unify the usage of SmartPtr +// this class added to unify the usage of SmartPtr // instead of writing SmartPtr<T,OP,CP,KP,SP> write SmartPtrDef<T,OP,CP,KP,SP>::type //////////////////////////////////////////////////////////////////////////////// @@ -1073,7 +1075,7 @@ class ConversionPolicy = DisallowConversion, template <class> class CheckingPolicy = AssertCheck, template <class> class StoragePolicy = DefaultSPStorage, - template<class> class ConstnessPolicy = LOKI_DEFAULT_CONSTNESS + template<class> class ConstnessPolicy = LOKI_DEFAULT_CONSTNESS > struct SmartPtrDef { @@ -1092,7 +1094,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \class SmartPtr /// -/// \ingroup SmartPointerGroup +/// \ingroup SmartPointerGroup /// /// \param OwnershipPolicy default = RefCounted, /// \param ConversionPolicy default = DisallowConversion, @@ -1127,7 +1129,7 @@ typedef OwnershipPolicy<typename StoragePolicy<T>::InitPointerType> OP; typedef CheckingPolicy<typename StoragePolicy<T>::StoredType> KP; typedef ConversionPolicy CP; - + public: typedef typename ConstnessPolicy<T>::Type* ConstPointerType; typedef typename ConstnessPolicy<T>::Type& ConstReferenceType; @@ -1135,13 +1137,13 @@ typedef typename SP::PointerType PointerType; typedef typename SP::StoredType StoredType; typedef typename SP::ReferenceType ReferenceType; - + typedef typename Select<OP::destructiveCopy,SmartPtr, const SmartPtr>::Result CopyArg; - + private: struct NeverMatched {}; - + #ifdef LOKI_SMARTPTR_CONVERSION_CONSTRUCTOR_POLICY typedef typename Select< CP::allow, const StoredType&, NeverMatched>::Result ImplicitArg; typedef typename Select<!CP::allow, const StoredType&, NeverMatched>::Result ExplicitArg; @@ -1156,7 +1158,7 @@ { KP::OnDefault(GetImpl(*this)); } - + explicit SmartPtr(ExplicitArg p) : SP(p) { @@ -1204,7 +1206,7 @@ SmartPtr(RefToValue<SmartPtr> rhs) : SP(rhs), OP(rhs), KP(rhs), CP(rhs) {} - + operator RefToValue<SmartPtr>() { return RefToValue<SmartPtr>(*this); } @@ -1230,7 +1232,7 @@ temp.Swap(*this); return *this; } - + template < typename T1, @@ -1246,7 +1248,7 @@ temp.Swap(*this); return *this; } - + void Swap(SmartPtr& rhs) { OP::Swap(rhs); @@ -1254,7 +1256,7 @@ KP::Swap(rhs); SP::Swap(rhs); } - + ~SmartPtr() { if (OP::Release(GetImpl(*static_cast<SP*>(this)))) @@ -1271,7 +1273,7 @@ p = GetImplRef(sp); GetImplRef(sp) = SP::Default(); } - + friend inline void Reset(SmartPtr& sp, typename SP::StoredType p) { SmartPtr(p).Swap(sp); } @@ -1338,13 +1340,13 @@ KP::OnDereference(GetImplRef(*this)); return SP::operator*(); } - + ConstReferenceType operator*() const { KP::OnDereference(GetImplRef(*this)); return SP::operator*(); } - + bool operator!() const // Enables "if (!sp) ..." { return GetImpl(*this) == 0; } @@ -1442,7 +1444,7 @@ Tester(int) {} void dummy() {} }; - + typedef void (Tester::*unspecified_boolean_type_)(); typedef typename Select<CP::allow, Tester, unspecified_boolean_type_>::Result @@ -1461,11 +1463,11 @@ { Insipid(PointerType) {} }; - + typedef typename Select<CP::allow, PointerType, Insipid>::Result AutomaticConversionResult; - - public: + + public: operator AutomaticConversionResult() const { return GetImpl(*this); } }; @@ -1568,7 +1570,7 @@ inline bool operator!=(const SmartPtr<T, OP, CP, KP, SP, CNP >& lhs, U* rhs) { return !(lhs == rhs); } - + //////////////////////////////////////////////////////////////////////////////// /// operator!= for lhs = raw pointer, rhs = SmartPtr /// \ingroup SmartPointerGroup @@ -1648,7 +1650,7 @@ inline bool operator>(const SmartPtr<T, OP, CP, KP, SP, CNP >& lhs, U* rhs) { return rhs < lhs; } - + //////////////////////////////////////////////////////////////////////////////// /// operator> for lhs = raw pointer, rhs = SmartPtr /// \ingroup SmartPointerGroup @@ -1667,7 +1669,7 @@ inline bool operator>(U* lhs, const SmartPtr<T, OP, CP, KP, SP, CNP >& rhs) { return rhs < lhs; } - + //////////////////////////////////////////////////////////////////////////////// /// operator<= for lhs = SmartPtr, rhs = raw pointer /// \ingroup SmartPointerGroup @@ -1686,7 +1688,7 @@ inline bool operator<=(const SmartPtr<T, OP, CP, KP, SP, CNP >& lhs, U* rhs) { return !(rhs < lhs); } - + //////////////////////////////////////////////////////////////////////////////// /// operator<= for lhs = raw pointer, rhs = SmartPtr /// \ingroup SmartPointerGroup @@ -1724,7 +1726,7 @@ inline bool operator>=(const SmartPtr<T, OP, CP, KP, SP, CNP >& lhs, U* rhs) { return !(lhs < rhs); } - + //////////////////////////////////////////////////////////////////////////////// /// operator>= for lhs = raw pointer, rhs = SmartPtr /// \ingroup SmartPointerGroup This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2009-04-11 06:01:14
|
Revision: 1013 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1013&view=rev Author: rich_sposato Date: 2009-04-11 06:01:06 +0000 (Sat, 11 Apr 2009) Log Message: ----------- Fixed bug 2747377 by changing order of operands. Modified Paths: -------------- trunk/include/loki/SmartPtr.h Modified: trunk/include/loki/SmartPtr.h =================================================================== --- trunk/include/loki/SmartPtr.h 2009-03-31 21:56:08 UTC (rev 1012) +++ trunk/include/loki/SmartPtr.h 2009-04-11 06:01:06 UTC (rev 1013) @@ -1531,7 +1531,7 @@ > inline bool operator==(const SmartPtr<T, OP, CP, KP, SP, CNP1 >& lhs, U* rhs) - { return GetImpl(lhs) == rhs; } + { return ( GetImpl( lhs ) == rhs ); } //////////////////////////////////////////////////////////////////////////////// /// operator== for lhs = raw pointer, rhs = SmartPtr @@ -1550,7 +1550,7 @@ > inline bool operator==(U* lhs, const SmartPtr<T, OP, CP, KP, SP, CNP1 >& rhs) - { return rhs == lhs; } + { return ( GetImpl( rhs ) == lhs ); } //////////////////////////////////////////////////////////////////////////////// /// operator!= for lhs = SmartPtr, rhs = raw pointer @@ -1569,7 +1569,7 @@ > inline bool operator!=(const SmartPtr<T, OP, CP, KP, SP, CNP >& lhs, U* rhs) - { return !(lhs == rhs); } + { return ( GetImpl( lhs ) != rhs ); } //////////////////////////////////////////////////////////////////////////////// /// operator!= for lhs = raw pointer, rhs = SmartPtr @@ -1588,7 +1588,7 @@ > inline bool operator!=(U* lhs, const SmartPtr<T, OP, CP, KP, SP, CNP >& rhs) - { return rhs != lhs; } + { return ( GetImpl( rhs ) != lhs ); } //////////////////////////////////////////////////////////////////////////////// /// operator< for lhs = SmartPtr, rhs = raw pointer @@ -1629,7 +1629,7 @@ inline bool operator<(U* lhs, const SmartPtr<T, OP, CP, KP, SP, CNP >& rhs) { - return ( GetImpl( rhs ) < lhs ); + return ( lhs < GetImpl( rhs ) ); } //////////////////////////////////////////////////////////////////////////////// @@ -1649,7 +1649,7 @@ > inline bool operator>(const SmartPtr<T, OP, CP, KP, SP, CNP >& lhs, U* rhs) - { return rhs < lhs; } + { return rhs < GetImpl( lhs ); } //////////////////////////////////////////////////////////////////////////////// /// operator> for lhs = raw pointer, rhs = SmartPtr This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2009-09-26 20:27:41
|
Revision: 1019 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1019&view=rev Author: rich_sposato Date: 2009-09-26 20:27:34 +0000 (Sat, 26 Sep 2009) Log Message: ----------- Fixed bug 2831440 by making constructors explicit. Modified Paths: -------------- trunk/include/loki/SmartPtr.h Modified: trunk/include/loki/SmartPtr.h =================================================================== --- trunk/include/loki/SmartPtr.h 2009-09-26 19:42:09 UTC (rev 1018) +++ trunk/include/loki/SmartPtr.h 2009-09-26 20:27:34 UTC (rev 1019) @@ -88,7 +88,7 @@ HeapStorage(const HeapStorage<U>&) : pointee_(0) {} - HeapStorage(const StoredType& p) : pointee_(p) {} + explicit HeapStorage(const StoredType& p) : pointee_(p) {} PointerType operator->() const { return pointee_; } @@ -170,7 +170,7 @@ DefaultSPStorage(const DefaultSPStorage<U>&) : pointee_(0) {} - DefaultSPStorage(const StoredType& p) : pointee_(p) {} + explicit DefaultSPStorage(const StoredType& p) : pointee_(p) {} PointerType operator->() const { return pointee_; } @@ -249,7 +249,7 @@ class Locker { public: - Locker( const T * p ) : pointee_( const_cast< T * >( p ) ) + explicit Locker( const T * p ) : pointee_( const_cast< T * >( p ) ) { if ( pointee_ != 0 ) pointee_->Lock(); @@ -293,7 +293,7 @@ LockedStorage( const LockedStorage&) : pointee_( 0 ) {} - LockedStorage( const StoredType & p ) : pointee_( p ) {} + explicit LockedStorage( const StoredType & p ) : pointee_( p ) {} PointerType operator->() { @@ -377,7 +377,7 @@ ArrayStorage(const ArrayStorage<U>&) : pointee_(0) {} - ArrayStorage(const StoredType& p) : pointee_(p) {} + explicit ArrayStorage(const StoredType& p) : pointee_(p) {} PointerType operator->() const { return pointee_; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2009-09-26 20:43:19
|
Revision: 1021 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1021&view=rev Author: rich_sposato Date: 2009-09-26 20:43:11 +0000 (Sat, 26 Sep 2009) Log Message: ----------- Fixed bug 2803535 by adding const qualifier. Modified Paths: -------------- trunk/include/loki/SmartPtr.h Modified: trunk/include/loki/SmartPtr.h =================================================================== --- trunk/include/loki/SmartPtr.h 2009-09-26 20:28:24 UTC (rev 1020) +++ trunk/include/loki/SmartPtr.h 2009-09-26 20:43:11 UTC (rev 1021) @@ -295,7 +295,7 @@ explicit LockedStorage( const StoredType & p ) : pointee_( p ) {} - PointerType operator->() + PointerType operator->() const { return Locker< T >( pointee_ ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2009-10-07 00:28:38
|
Revision: 1028 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1028&view=rev Author: rich_sposato Date: 2009-10-07 00:28:23 +0000 (Wed, 07 Oct 2009) Log Message: ----------- Changed functions in ownership policies from public to protected. Modified Paths: -------------- trunk/include/loki/SmartPtr.h Modified: trunk/include/loki/SmartPtr.h =================================================================== --- trunk/include/loki/SmartPtr.h 2009-10-01 17:54:38 UTC (rev 1027) +++ trunk/include/loki/SmartPtr.h 2009-10-07 00:28:23 UTC (rev 1028) @@ -70,7 +70,7 @@ template <class T> class HeapStorage { - public: + protected: typedef T* StoredType; /// the type of the pointee_ object typedef T* InitPointerType; /// type used to declare OwnershipPolicy type. typedef T* PointerType; /// type returned by operator-> @@ -152,7 +152,7 @@ template <class T> class DefaultSPStorage { - public: + protected: typedef T* StoredType; // the type of the pointee_ object typedef T* InitPointerType; /// type used to declare OwnershipPolicy type. typedef T* PointerType; // type returned by operator-> @@ -359,7 +359,7 @@ template <class T> class ArrayStorage { - public: + protected: typedef T* StoredType; // the type of the pointee_ object typedef T* InitPointerType; /// type used to declare OwnershipPolicy type. typedef T* PointerType; // type returned by operator-> @@ -435,7 +435,7 @@ template <class P> class RefCounted { - public: + protected: RefCounted() : pCount_(static_cast<uintptr_t*>( SmallObject<>::operator new(sizeof(uintptr_t)))) @@ -511,7 +511,7 @@ typedef typename base_type::IntType CountType; typedef volatile CountType *CountPtrType; - public: + protected: RefCountedMT() { pCount_ = static_cast<CountPtrType>( @@ -574,7 +574,7 @@ template <class P> class COMRefCounted { - public: + protected: COMRefCounted() {} @@ -614,6 +614,7 @@ template <class P> struct DeepCopy { + protected: DeepCopy() {} @@ -673,7 +674,7 @@ template <class P> class RefLinked : public Private::RefLinkedBase { - public: + protected: RefLinked() {} @@ -706,7 +707,7 @@ template <class P> class DestructiveCopy { - public: + protected: DestructiveCopy() {} @@ -742,7 +743,7 @@ template <class P> class NoCopy { - public: + protected: NoCopy() {} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2009-10-07 00:41:14
|
Revision: 1029 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1029&view=rev Author: rich_sposato Date: 2009-10-07 00:41:02 +0000 (Wed, 07 Oct 2009) Log Message: ----------- Changed functions in all policies from public to protected. Modified Paths: -------------- trunk/include/loki/SmartPtr.h Modified: trunk/include/loki/SmartPtr.h =================================================================== --- trunk/include/loki/SmartPtr.h 2009-10-07 00:28:23 UTC (rev 1028) +++ trunk/include/loki/SmartPtr.h 2009-10-07 00:41:02 UTC (rev 1029) @@ -70,12 +70,14 @@ template <class T> class HeapStorage { - protected: + public: typedef T* StoredType; /// the type of the pointee_ object typedef T* InitPointerType; /// type used to declare OwnershipPolicy type. typedef T* PointerType; /// type returned by operator-> typedef T& ReferenceType; /// type returned by operator* + protected: + HeapStorage() : pointee_(Default()) {} @@ -107,7 +109,6 @@ template <class F> friend typename HeapStorage<F>::StoredType& GetImplRef(HeapStorage<F>& sp); - protected: // Destroys the data stored // (Destruction might be taken over by the OwnershipPolicy) void Destroy() @@ -152,12 +153,14 @@ template <class T> class DefaultSPStorage { - protected: + public: typedef T* StoredType; // the type of the pointee_ object typedef T* InitPointerType; /// type used to declare OwnershipPolicy type. typedef T* PointerType; // type returned by operator-> typedef T& ReferenceType; // type returned by operator* + protected: + DefaultSPStorage() : pointee_(Default()) {} @@ -189,7 +192,6 @@ template <class F> friend typename DefaultSPStorage<F>::StoredType& GetImplRef(DefaultSPStorage<F>& sp); - protected: // Destroys the data stored // (Destruction might be taken over by the OwnershipPolicy) // @@ -287,6 +289,8 @@ typedef Locker< T > PointerType; /// type returned by operator-> typedef T& ReferenceType; /// type returned by operator* + protected: + LockedStorage() : pointee_( Default() ) {} ~LockedStorage( void ) {} @@ -315,7 +319,6 @@ template <class F> friend typename LockedStorage<F>::StoredType& GetImplRef(LockedStorage<F>& sp); - protected: // Destroys the data stored // (Destruction might be taken over by the OwnershipPolicy) void Destroy() @@ -359,12 +362,15 @@ template <class T> class ArrayStorage { - protected: + public: + typedef T* StoredType; // the type of the pointee_ object typedef T* InitPointerType; /// type used to declare OwnershipPolicy type. typedef T* PointerType; // type returned by operator-> typedef T& ReferenceType; // type returned by operator* + protected: + ArrayStorage() : pointee_(Default()) {} @@ -396,7 +402,6 @@ template <class F> friend typename ArrayStorage<F>::StoredType& GetImplRef(ArrayStorage<F>& sp); - protected: // Destroys the data stored // (Destruction might be taken over by the OwnershipPolicy) void Destroy() @@ -507,6 +512,8 @@ template <class P> class RefCountedMT : public ThreadingModel< RefCountedMT<P>, MX > { + public: + typedef ThreadingModel< RefCountedMT<P>, MX > base_type; typedef typename base_type::IntType CountType; typedef volatile CountType *CountPtrType; @@ -646,7 +653,7 @@ { class LOKI_EXPORT RefLinkedBase { - public: + protected: RefLinkedBase() { prev_ = next_ = this; } @@ -818,6 +825,8 @@ template <class P> struct NoCheck { + protected: + NoCheck() {} @@ -850,6 +859,8 @@ template <class P> struct AssertCheck { + protected: + AssertCheck() {} @@ -886,6 +897,8 @@ template <class P> struct AssertCheckStrict { + protected: + AssertCheckStrict() {} @@ -940,6 +953,8 @@ template <class P> struct RejectNullStatic { + protected: + RejectNullStatic() {} @@ -988,6 +1003,8 @@ template <class P> struct RejectNull { + protected: + RejectNull() {} @@ -1022,6 +1039,8 @@ template <class P> struct RejectNullStrict { + protected: + RejectNullStrict() {} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2010-09-16 17:32:30
|
Revision: 1078 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1078&view=rev Author: rich_sposato Date: 2010-09-16 17:32:24 +0000 (Thu, 16 Sep 2010) Log Message: ----------- Used initialization instead of assignment within constructor. Modified Paths: -------------- trunk/include/loki/SmartPtr.h Modified: trunk/include/loki/SmartPtr.h =================================================================== --- trunk/include/loki/SmartPtr.h 2010-09-16 17:28:52 UTC (rev 1077) +++ trunk/include/loki/SmartPtr.h 2010-09-16 17:32:24 UTC (rev 1078) @@ -54,7 +54,12 @@ #define LOKI_ENABLE_FRIEND_TEMPLATE_TEMPLATE_PARAMETER_WORKAROUND #endif +#if defined( _MSC_VER ) + #pragma warning( push ) + #pragma warning( disable: 4355 ) +#endif + namespace Loki { @@ -654,8 +659,9 @@ class LOKI_EXPORT RefLinkedBase { protected: - RefLinkedBase() - { prev_ = next_ = this; } + RefLinkedBase( void ) : + prev_( this ), next_( this ) + {} RefLinkedBase(const RefLinkedBase& rhs); @@ -1869,5 +1875,10 @@ }; } +// ---------------------------------------------------------------------------- + +#if defined( _MSC_VER ) + #pragma warning( pop ) +#endif + #endif // end file guardian - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-07 22:46:43
|
Revision: 1094 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1094&view=rev Author: rich_sposato Date: 2011-09-07 22:46:37 +0000 (Wed, 07 Sep 2011) Log Message: ----------- Fixed bug 3224518 by adding calls to OnDereference. Modified Paths: -------------- trunk/include/loki/SmartPtr.h Modified: trunk/include/loki/SmartPtr.h =================================================================== --- trunk/include/loki/SmartPtr.h 2011-09-07 20:04:38 UTC (rev 1093) +++ trunk/include/loki/SmartPtr.h 2011-09-07 22:46:37 UTC (rev 1094) @@ -983,7 +983,7 @@ static void OnDefault(const P&) { // Make it depended on template parameter - static const bool DependedFalse = sizeof(P*) == 0; + static const bool DependedFalse = ( sizeof(P*) == 0 ); LOKI_STATIC_CHECK(DependedFalse, ERROR_This_Policy_Does_Not_Allow_Default_Initialization); } @@ -1196,6 +1196,7 @@ (void)helper; // do void cast to remove compiler warning. // Dynamic casting from T1 to T and saving result in `this''s pointer PointerType p = dynamic_cast< PointerType >( GetImplRef( rhs ) ); + KP::OnDereference( p ); GetImplRef( *this ) = OP::Clone( p ); } @@ -1214,6 +1215,7 @@ (void)helper; // do void cast to remove compiler warning. // Dynamic casting from T1 to T and saving result in `this''s pointer PointerType p = dynamic_cast< PointerType >( GetImplRef( rhs ) ); + KP::OnDereference( p ); GetImplRef( *this ) = OP::Clone( p ); } @@ -1237,6 +1239,7 @@ SmartPtr(CopyArg& rhs) : SP(rhs), OP(rhs), KP(rhs), CP(rhs) { + KP::OnDereference( GetImpl( rhs ) ); GetImplRef(*this) = OP::Clone(GetImplRef(rhs)); } @@ -1252,6 +1255,7 @@ SmartPtr(const SmartPtr<T1, OP1, CP1, KP1, SP1, CNP1 >& rhs) : SP(rhs), OP(rhs), KP(rhs), CP(rhs) { + KP::OnDereference( GetImpl( rhs ) ); GetImplRef(*this) = OP::Clone(GetImplRef(rhs)); } @@ -1267,6 +1271,7 @@ SmartPtr(SmartPtr<T1, OP1, CP1, KP1, SP1, CNP1 >& rhs) : SP(rhs), OP(rhs), KP(rhs), CP(rhs) { + KP::OnDereference( GetImpl( rhs ) ); GetImplRef(*this) = OP::Clone(GetImplRef(rhs)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-13 00:50:11
|
Revision: 1100 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1100&view=rev Author: rich_sposato Date: 2011-09-13 00:50:05 +0000 (Tue, 13 Sep 2011) Log Message: ----------- Added call to OnDereference to constructor. Modified Paths: -------------- trunk/include/loki/SmartPtr.h Modified: trunk/include/loki/SmartPtr.h =================================================================== --- trunk/include/loki/SmartPtr.h 2011-09-09 00:30:44 UTC (rev 1099) +++ trunk/include/loki/SmartPtr.h 2011-09-13 00:50:05 UTC (rev 1100) @@ -1252,7 +1252,7 @@ template <class> class SP1, template <class> class CNP1 > - SmartPtr(const SmartPtr<T1, OP1, CP1, KP1, SP1, CNP1 >& rhs) + SmartPtr( const SmartPtr< T1, OP1, CP1, KP1, SP1, CNP1 >& rhs ) : SP(rhs), OP(rhs), KP(rhs), CP(rhs) { KP::OnDereference( GetImpl( rhs ) ); @@ -1268,7 +1268,7 @@ template <class> class SP1, template <class> class CNP1 > - SmartPtr(SmartPtr<T1, OP1, CP1, KP1, SP1, CNP1 >& rhs) + SmartPtr( SmartPtr< T1, OP1, CP1, KP1, SP1, CNP1 >& rhs ) : SP(rhs), OP(rhs), KP(rhs), CP(rhs) { KP::OnDereference( GetImpl( rhs ) ); @@ -1277,7 +1277,11 @@ SmartPtr(RefToValue<SmartPtr> rhs) : SP(rhs), OP(rhs), KP(rhs), CP(rhs) - {} + { + SmartPtr & ref = rhs; + KP::OnDereference( GetImpl( ref ) ); + GetImplRef( *this ) = OP::Clone( GetImplRef( ref ) ); + } operator RefToValue<SmartPtr>() { return RefToValue<SmartPtr>(*this); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-17 02:19:07
|
Revision: 1101 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1101&view=rev Author: rich_sposato Date: 2011-09-17 02:19:01 +0000 (Sat, 17 Sep 2011) Log Message: ----------- Fixed bug 2080889 by adding overload of const Clone function. Modified Paths: -------------- trunk/include/loki/SmartPtr.h Modified: trunk/include/loki/SmartPtr.h =================================================================== --- trunk/include/loki/SmartPtr.h 2011-09-13 00:50:05 UTC (rev 1100) +++ trunk/include/loki/SmartPtr.h 2011-09-17 02:19:01 UTC (rev 1101) @@ -729,6 +729,14 @@ {} template <class P1> + static P Clone( const P1 & val ) + { + P result(val); + const_cast< P1 & >( val ) = P1(); + return result; + } + + template <class P1> static P Clone(P1& val) { P result(val); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-21 23:25:00
|
Revision: 1114 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1114&view=rev Author: rich_sposato Date: 2011-09-21 23:24:54 +0000 (Wed, 21 Sep 2011) Log Message: ----------- Added comment about policy incompatibility. Modified Paths: -------------- trunk/include/loki/SmartPtr.h Modified: trunk/include/loki/SmartPtr.h =================================================================== --- trunk/include/loki/SmartPtr.h 2011-09-20 23:32:29 UTC (rev 1113) +++ trunk/include/loki/SmartPtr.h 2011-09-21 23:24:54 UTC (rev 1114) @@ -400,6 +400,13 @@ /// /// \ingroup SmartPointerStorageGroup /// Implementation of the ArrayStorage used by SmartPtr +/// This assumes the pointer points to the zeroth element in an array, and uses +/// the array-delete operator to deconstruct and deallocate the array. DeepCopy +/// is not compatible with ArrayStorage DeepCopy::Clone will only copy the first +/// element in the array and won't know the size of the array. Even if it did +/// know the size, it would need to use array new to safely work the array +/// delete operator in ArrayStorage, but array new will not copy the elements +/// in the source array since it calls the default constructor for each element. //////////////////////////////////////////////////////////////////////////////// @@ -663,7 +670,12 @@ /// \ingroup SmartPointerOwnershipGroup /// Implementation of the OwnershipPolicy used by SmartPtr /// Implements deep copy semantics, assumes existence of a Clone() member -/// function of the pointee type +/// function of the pointee type. DeepCopy is not compatible with ArrayStorage +/// DeepCopy::Clone will only copy the first element in the array and won't +/// know the size of the array. Even if it did know the size, it would need to +/// use array new to safely work the array delete operator in ArrayStorage, but +/// array new will not copy the elements in the source array since it calls the +/// default constructor for each array element. //////////////////////////////////////////////////////////////////////////////// template <class P> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |