From c0cdb2ad99a1e2a6ade5ce76c91177a79258e669 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:10:11 +0200 Subject: 3.14 --- shared/loki/SmartPtr.h | 2276 ++++++++++++++++++++++++------------------------ 1 file changed, 1138 insertions(+), 1138 deletions(-) (limited to 'shared/loki/SmartPtr.h') diff --git a/shared/loki/SmartPtr.h b/shared/loki/SmartPtr.h index df548553..fb14258e 100644 --- a/shared/loki/SmartPtr.h +++ b/shared/loki/SmartPtr.h @@ -67,78 +67,78 @@ namespace Loki //////////////////////////////////////////////////////////////////////////////// - template - class HeapStorage - { - 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* +template +class HeapStorage +{ +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* - HeapStorage() : pointee_(Default()) - {} + HeapStorage() : pointee_(Default()) + {} - // The storage policy doesn't initialize the stored pointer - // which will be initialized by the OwnershipPolicy's Clone fn - HeapStorage(const HeapStorage&) : pointee_(0) - {} + // The storage policy doesn't initialize the stored pointer + // which will be initialized by the OwnershipPolicy's Clone fn + HeapStorage(const HeapStorage&) : pointee_(0) + {} - template - HeapStorage(const HeapStorage&) : pointee_(0) - {} + template + HeapStorage(const HeapStorage&) : pointee_(0) + {} - HeapStorage(const StoredType& p) : pointee_(p) {} + HeapStorage(const StoredType& p) : pointee_(p) {} - PointerType operator->() const { return pointee_; } + PointerType operator->() const { return pointee_; } - ReferenceType operator*() const { return *pointee_; } + ReferenceType operator*() const { return *pointee_; } - void Swap(HeapStorage& rhs) - { std::swap(pointee_, rhs.pointee_); } + void Swap(HeapStorage& rhs) + { std::swap(pointee_, rhs.pointee_); } - // Accessors - template - friend typename HeapStorage::PointerType GetImpl(const HeapStorage& sp); + // Accessors + template + friend typename HeapStorage::PointerType GetImpl(const HeapStorage& sp); - template - friend const typename HeapStorage::StoredType& GetImplRef(const HeapStorage& sp); + template + friend const typename HeapStorage::StoredType& GetImplRef(const HeapStorage& sp); - template - friend typename HeapStorage::StoredType& GetImplRef(HeapStorage& sp); + template + friend typename HeapStorage::StoredType& GetImplRef(HeapStorage& sp); - protected: - // Destroys the data stored - // (Destruction might be taken over by the OwnershipPolicy) - void Destroy() +protected: + // Destroys the data stored + // (Destruction might be taken over by the OwnershipPolicy) + void Destroy() + { + if ( 0 != pointee_ ) { - if ( 0 != pointee_ ) - { - pointee_->~T(); - ::free( pointee_ ); - } + pointee_->~T(); + ::free( pointee_ ); } + } - // Default value to initialize the pointer - static StoredType Default() - { return 0; } + // Default value to initialize the pointer + static StoredType Default() + { return 0; } - private: - // Data - StoredType pointee_; - }; +private: + // Data + StoredType pointee_; +}; - template - inline typename HeapStorage::PointerType GetImpl(const HeapStorage& sp) - { return sp.pointee_; } +template +inline typename HeapStorage::PointerType GetImpl(const HeapStorage& sp) +{ return sp.pointee_; } - template - inline const typename HeapStorage::StoredType& GetImplRef(const HeapStorage& sp) - { return sp.pointee_; } +template +inline const typename HeapStorage::StoredType& GetImplRef(const HeapStorage& sp) +{ return sp.pointee_; } - template - inline typename HeapStorage::StoredType& GetImplRef(HeapStorage& sp) - { return sp.pointee_; } +template +inline typename HeapStorage::StoredType& GetImplRef(HeapStorage& sp) +{ return sp.pointee_; } //////////////////////////////////////////////////////////////////////////////// @@ -149,77 +149,77 @@ namespace Loki //////////////////////////////////////////////////////////////////////////////// - template - class DefaultSPStorage - { - 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* +template +class DefaultSPStorage +{ +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* - DefaultSPStorage() : pointee_(Default()) - {} + DefaultSPStorage() : pointee_(Default()) + {} - // The storage policy doesn't initialize the stored pointer - // which will be initialized by the OwnershipPolicy's Clone fn - DefaultSPStorage(const DefaultSPStorage&) : pointee_(0) - {} + // The storage policy doesn't initialize the stored pointer + // which will be initialized by the OwnershipPolicy's Clone fn + DefaultSPStorage(const DefaultSPStorage&) : pointee_(0) + {} - template - DefaultSPStorage(const DefaultSPStorage&) : pointee_(0) - {} + template + DefaultSPStorage(const DefaultSPStorage&) : pointee_(0) + {} - DefaultSPStorage(const StoredType& p) : pointee_(p) {} + DefaultSPStorage(const StoredType& p) : pointee_(p) {} - PointerType operator->() const { return pointee_; } + PointerType operator->() const { return pointee_; } - ReferenceType operator*() const { return *pointee_; } + ReferenceType operator*() const { return *pointee_; } - void Swap(DefaultSPStorage& rhs) - { std::swap(pointee_, rhs.pointee_); } + void Swap(DefaultSPStorage& rhs) + { std::swap(pointee_, rhs.pointee_); } - // Accessors - template - friend typename DefaultSPStorage::PointerType GetImpl(const DefaultSPStorage& sp); + // Accessors + template + friend typename DefaultSPStorage::PointerType GetImpl(const DefaultSPStorage& sp); - template - friend const typename DefaultSPStorage::StoredType& GetImplRef(const DefaultSPStorage& sp); + template + friend const typename DefaultSPStorage::StoredType& GetImplRef(const DefaultSPStorage& sp); - template - friend typename DefaultSPStorage::StoredType& GetImplRef(DefaultSPStorage& sp); + template + friend typename DefaultSPStorage::StoredType& GetImplRef(DefaultSPStorage& sp); - protected: - // Destroys the data stored - // (Destruction might be taken over by the OwnershipPolicy) - // - // If your compiler gives you a warning in this area while - // compiling the tests, it is on purpose, please ignore it. - void Destroy() - { - delete pointee_; - } +protected: + // Destroys the data stored + // (Destruction might be taken over by the OwnershipPolicy) + // + // If your compiler gives you a warning in this area while + // compiling the tests, it is on purpose, please ignore it. + void Destroy() + { + delete pointee_; + } - // Default value to initialize the pointer - static StoredType Default() - { return 0; } + // Default value to initialize the pointer + static StoredType Default() + { return 0; } - private: - // Data - StoredType pointee_; - }; +private: + // Data + StoredType pointee_; +}; - template - inline typename DefaultSPStorage::PointerType GetImpl(const DefaultSPStorage& sp) - { return sp.pointee_; } +template +inline typename DefaultSPStorage::PointerType GetImpl(const DefaultSPStorage& sp) +{ return sp.pointee_; } - template - inline const typename DefaultSPStorage::StoredType& GetImplRef(const DefaultSPStorage& sp) - { return sp.pointee_; } +template +inline const typename DefaultSPStorage::StoredType& GetImplRef(const DefaultSPStorage& sp) +{ return sp.pointee_; } - template - inline typename DefaultSPStorage::StoredType& GetImplRef(DefaultSPStorage& sp) - { return sp.pointee_; } +template +inline typename DefaultSPStorage::StoredType& GetImplRef(DefaultSPStorage& sp) +{ return sp.pointee_; } //////////////////////////////////////////////////////////////////////////////// @@ -245,107 +245,107 @@ namespace Loki /// LockedStorage which calls other functions to lock the object. //////////////////////////////////////////////////////////////////////////////// - template - class Locker +template +class Locker +{ +public: + Locker( const T* p ) : pointee_( const_cast< T* >( p ) ) { - public: - Locker( const T * p ) : pointee_( const_cast< T * >( p ) ) - { - if ( pointee_ != 0 ) - pointee_->Lock(); - } + if ( pointee_ != 0 ) + pointee_->Lock(); + } - ~Locker( void ) - { - if ( pointee_ != 0 ) - pointee_->Unlock(); - } + ~Locker( void ) + { + if ( pointee_ != 0 ) + pointee_->Unlock(); + } - operator T * () - { - return pointee_; - } + operator T* () + { + return pointee_; + } - T * operator->() - { - return pointee_; - } + T* operator->() + { + return pointee_; + } - private: - Locker( void ); - Locker & operator = ( const Locker & ); - T * pointee_; - }; +private: + Locker( void ); + Locker& operator = ( const Locker& ); + T* pointee_; +}; - template - class LockedStorage - { - public: +template +class LockedStorage +{ +public: - typedef T* StoredType; /// the type of the pointee_ object - typedef T* InitPointerType; /// type used to declare OwnershipPolicy type. - typedef Locker< T > PointerType; /// type returned by operator-> - typedef T& ReferenceType; /// type returned by operator* + typedef T* StoredType; /// the type of the pointee_ object + typedef T* InitPointerType; /// type used to declare OwnershipPolicy type. + typedef Locker< T > PointerType; /// type returned by operator-> + typedef T& ReferenceType; /// type returned by operator* - LockedStorage() : pointee_( Default() ) {} + LockedStorage() : pointee_( Default() ) {} - ~LockedStorage( void ) {} + ~LockedStorage( void ) {} - LockedStorage( const LockedStorage&) : pointee_( 0 ) {} + LockedStorage( const LockedStorage&) : pointee_( 0 ) {} - LockedStorage( const StoredType & p ) : pointee_( p ) {} + LockedStorage( const StoredType& p ) : pointee_( p ) {} - PointerType operator->() - { - return Locker< T >( pointee_ ); - } + PointerType operator->() + { + return Locker< T >( pointee_ ); + } - void Swap(LockedStorage& rhs) - { - std::swap( pointee_, rhs.pointee_ ); - } + void Swap(LockedStorage& rhs) + { + std::swap( pointee_, rhs.pointee_ ); + } - // Accessors - template - friend typename LockedStorage::InitPointerType GetImpl(const LockedStorage& sp); + // Accessors + template + friend typename LockedStorage::InitPointerType GetImpl(const LockedStorage& sp); - template - friend const typename LockedStorage::StoredType& GetImplRef(const LockedStorage& sp); + template + friend const typename LockedStorage::StoredType& GetImplRef(const LockedStorage& sp); - template - friend typename LockedStorage::StoredType& GetImplRef(LockedStorage& sp); + template + friend typename LockedStorage::StoredType& GetImplRef(LockedStorage& sp); - protected: - // Destroys the data stored - // (Destruction might be taken over by the OwnershipPolicy) - void Destroy() - { - delete pointee_; - } +protected: + // Destroys the data stored + // (Destruction might be taken over by the OwnershipPolicy) + void Destroy() + { + delete pointee_; + } - // Default value to initialize the pointer - static StoredType Default() - { return 0; } + // Default value to initialize the pointer + static StoredType Default() + { return 0; } - private: - /// Dereference operator is not implemented. - ReferenceType operator*(); +private: + /// Dereference operator is not implemented. + ReferenceType operator*(); - // Data - StoredType pointee_; - }; + // Data + StoredType pointee_; +}; - template - inline typename LockedStorage::InitPointerType GetImpl(const LockedStorage& sp) - { return sp.pointee_; } +template +inline typename LockedStorage::InitPointerType GetImpl(const LockedStorage& sp) +{ return sp.pointee_; } - template - inline const typename LockedStorage::StoredType& GetImplRef(const LockedStorage& sp) - { return sp.pointee_; } +template +inline const typename LockedStorage::StoredType& GetImplRef(const LockedStorage& sp) +{ return sp.pointee_; } - template - inline typename LockedStorage::StoredType& GetImplRef(LockedStorage& sp) - { return sp.pointee_; } +template +inline typename LockedStorage::StoredType& GetImplRef(LockedStorage& sp) +{ return sp.pointee_; } //////////////////////////////////////////////////////////////////////////////// @@ -356,72 +356,72 @@ namespace Loki //////////////////////////////////////////////////////////////////////////////// - template - class ArrayStorage - { - 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* +template +class ArrayStorage +{ +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* - ArrayStorage() : pointee_(Default()) - {} + ArrayStorage() : pointee_(Default()) + {} - // The storage policy doesn't initialize the stored pointer - // which will be initialized by the OwnershipPolicy's Clone fn - ArrayStorage(const ArrayStorage&) : pointee_(0) - {} + // The storage policy doesn't initialize the stored pointer + // which will be initialized by the OwnershipPolicy's Clone fn + ArrayStorage(const ArrayStorage&) : pointee_(0) + {} - template - ArrayStorage(const ArrayStorage&) : pointee_(0) - {} + template + ArrayStorage(const ArrayStorage&) : pointee_(0) + {} - ArrayStorage(const StoredType& p) : pointee_(p) {} + ArrayStorage(const StoredType& p) : pointee_(p) {} - PointerType operator->() const { return pointee_; } + PointerType operator->() const { return pointee_; } - ReferenceType operator*() const { return *pointee_; } + ReferenceType operator*() const { return *pointee_; } - void Swap(ArrayStorage& rhs) - { std::swap(pointee_, rhs.pointee_); } + void Swap(ArrayStorage& rhs) + { std::swap(pointee_, rhs.pointee_); } - // Accessors - template - friend typename ArrayStorage::PointerType GetImpl(const ArrayStorage& sp); + // Accessors + template + friend typename ArrayStorage::PointerType GetImpl(const ArrayStorage& sp); - template - friend const typename ArrayStorage::StoredType& GetImplRef(const ArrayStorage& sp); + template + friend const typename ArrayStorage::StoredType& GetImplRef(const ArrayStorage& sp); - template - friend typename ArrayStorage::StoredType& GetImplRef(ArrayStorage& sp); + template + friend typename ArrayStorage::StoredType& GetImplRef(ArrayStorage& sp); - protected: - // Destroys the data stored - // (Destruction might be taken over by the OwnershipPolicy) - void Destroy() - { delete [] pointee_; } +protected: + // Destroys the data stored + // (Destruction might be taken over by the OwnershipPolicy) + void Destroy() + { delete [] pointee_; } - // Default value to initialize the pointer - static StoredType Default() - { return 0; } + // Default value to initialize the pointer + static StoredType Default() + { return 0; } - private: - // Data - StoredType pointee_; - }; +private: + // Data + StoredType pointee_; +}; - template - inline typename ArrayStorage::PointerType GetImpl(const ArrayStorage& sp) - { return sp.pointee_; } +template +inline typename ArrayStorage::PointerType GetImpl(const ArrayStorage& sp) +{ return sp.pointee_; } - template - inline const typename ArrayStorage::StoredType& GetImplRef(const ArrayStorage& sp) - { return sp.pointee_; } +template +inline const typename ArrayStorage::StoredType& GetImplRef(const ArrayStorage& sp) +{ return sp.pointee_; } - template - inline typename ArrayStorage::StoredType& GetImplRef(ArrayStorage& sp) - { return sp.pointee_; } +template +inline typename ArrayStorage::StoredType& GetImplRef(ArrayStorage& sp) +{ return sp.pointee_; } //////////////////////////////////////////////////////////////////////////////// @@ -432,54 +432,54 @@ namespace Loki /// Provides a classic external reference counting implementation //////////////////////////////////////////////////////////////////////////////// - template - class RefCounted +template +class RefCounted +{ +public: + RefCounted() + : pCount_(static_cast( + SmallObject<>::operator new(sizeof(uintptr_t)))) { - public: - RefCounted() - : pCount_(static_cast( - SmallObject<>::operator new(sizeof(uintptr_t)))) - { - assert(pCount_!=0); - *pCount_ = 1; - } + 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 - RefCounted(const RefCounted& rhs) + // MWCW lacks template friends, hence the following kludge + template + RefCounted(const RefCounted& rhs) : pCount_(reinterpret_cast(rhs).pCount_) - {} + {} - P Clone(const P& val) - { - ++*pCount_; - return val; - } + P Clone(const P& val) + { + ++*pCount_; + return val; + } - bool Release(const P&) + bool Release(const P&) + { + if (!--*pCount_) { - if (!--*pCount_) - { - SmallObject<>::operator delete(pCount_, sizeof(uintptr_t)); - pCount_ = NULL; - return true; - } - return false; + SmallObject<>::operator delete(pCount_, sizeof(uintptr_t)); + pCount_ = NULL; + return true; } + return false; + } - void Swap(RefCounted& rhs) - { std::swap(pCount_, rhs.pCount_); } + void Swap(RefCounted& rhs) + { std::swap(pCount_, rhs.pCount_); } - enum { destructiveCopy = false }; + enum { destructiveCopy = false }; - private: - // Data - uintptr_t* pCount_; - }; +private: + // Data + uintptr_t* pCount_; +}; //////////////////////////////////////////////////////////////////////////////// /// \struct RefCountedMT @@ -500,68 +500,68 @@ namespace Loki /// fixed at a higher design level, and no change to this class could fix it. //////////////////////////////////////////////////////////////////////////////// - template