diff --git a/include/loki/SmartPtr.h b/include/loki/SmartPtr.h index dd37f2e..f6b1c4a 100644 --- a/include/loki/SmartPtr.h +++ b/include/loki/SmartPtr.h @@ -56,6 +56,7 @@ namespace Loki /// to T's destructor followed by call to free. //////////////////////////////////////////////////////////////////////////////// + template class HeapStorage { @@ -86,14 +87,14 @@ namespace Loki { std::swap(pointee_, rhs.pointee_); } // Accessors - friend inline PointerType GetImpl(const HeapStorage& sp) - { return sp.pointee_; } - - friend inline const StoredType& GetImplRef(const HeapStorage& sp) - { return sp.pointee_; } + template + friend typename HeapStorage::PointerType GetImpl(const HeapStorage& sp); - friend inline StoredType& GetImplRef(HeapStorage& sp) - { return sp.pointee_; } + template + friend const typename HeapStorage::StoredType& GetImplRef(const HeapStorage& sp); + + template + friend typename HeapStorage::StoredType& GetImplRef(HeapStorage& sp); protected: // Destroys the data stored @@ -116,6 +117,19 @@ namespace Loki StoredType 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 typename HeapStorage::StoredType& GetImplRef(HeapStorage& sp) + { return sp.pointee_; } + + //////////////////////////////////////////////////////////////////////////////// /// \class DefaultSPStorage /// @@ -123,6 +137,7 @@ namespace Loki /// Implementation of the StoragePolicy used by SmartPtr //////////////////////////////////////////////////////////////////////////////// + template class DefaultSPStorage { @@ -153,14 +168,14 @@ namespace Loki { std::swap(pointee_, rhs.pointee_); } // Accessors - friend inline PointerType GetImpl(const DefaultSPStorage& sp) - { return sp.pointee_; } - - friend inline const StoredType& GetImplRef(const DefaultSPStorage& sp) - { return sp.pointee_; } + template + friend typename DefaultSPStorage::PointerType GetImpl(const DefaultSPStorage& sp); - friend inline StoredType& GetImplRef(DefaultSPStorage& sp) - { return sp.pointee_; } + template + friend const typename DefaultSPStorage::StoredType& GetImplRef(const DefaultSPStorage& sp); + + template + friend typename DefaultSPStorage::StoredType& GetImplRef(DefaultSPStorage& sp); protected: // Destroys the data stored @@ -179,6 +194,18 @@ namespace Loki StoredType 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 typename DefaultSPStorage::StoredType& GetImplRef(DefaultSPStorage& sp) + { return sp.pointee_; } + //////////////////////////////////////////////////////////////////////////////// /// \class ArrayStorage @@ -187,6 +214,7 @@ namespace Loki /// Implementation of the ArrayStorage used by SmartPtr //////////////////////////////////////////////////////////////////////////////// + template class ArrayStorage { @@ -217,14 +245,14 @@ namespace Loki { std::swap(pointee_, rhs.pointee_); } // Accessors - friend inline PointerType GetImpl(const ArrayStorage& sp) - { return sp.pointee_; } - - friend inline const StoredType& GetImplRef(const ArrayStorage& sp) - { return sp.pointee_; } + template + friend typename ArrayStorage::PointerType GetImpl(const ArrayStorage& sp); - friend inline StoredType& GetImplRef(ArrayStorage& sp) - { return sp.pointee_; } + template + friend const typename ArrayStorage::StoredType& GetImplRef(const ArrayStorage& sp); + + template + friend typename ArrayStorage::StoredType& GetImplRef(ArrayStorage& sp); protected: // Destroys the data stored @@ -241,6 +269,18 @@ namespace Loki StoredType 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 typename ArrayStorage::StoredType& GetImplRef(ArrayStorage& sp) + { return sp.pointee_; } + //////////////////////////////////////////////////////////////////////////////// /// \class RefCounted @@ -1065,15 +1105,32 @@ namespace Loki SP::Destroy(); } } - - friend inline void Release(SmartPtr& sp, typename SP::StoredType& p) - { - p = GetImplRef(sp); - GetImplRef(sp) = SP::Default(); - } - - friend inline void Reset(SmartPtr& sp, typename SP::StoredType p) - { SmartPtr(p).Swap(sp); } + + template + < + typename T1, + template class OP1, + class CP1, + template class KP1, + template class SP1, + template class CNP1 + > + friend void Release(SmartPtr& sp, + typename SP1::StoredType& p); + + template + < + typename T1, + template class OP1, + class CP1, + template class KP1, + template class SP1, + template class CNP1 + > + friend void Reset(SmartPtr& sp, + typename SP1::StoredType p); + + template < @@ -1090,7 +1147,7 @@ namespace Loki { return false; } - return OP::Merge( rhs ); + return OP::template Merge( rhs ); } PointerType operator->() @@ -1242,6 +1299,37 @@ namespace Loki { return GetImpl(*this); } }; + template + < + typename T, + template class OP, + class CP, + template class KP, + template class SP, + template class CNP1, + typename U + > + inline void Release(SmartPtr& sp, + typename SP::StoredType& p) + { + p = GetImplRef(sp); + GetImplRef(sp) = SP::Default(); + } + + template + < + typename T, + template class OP, + class CP, + template class KP, + template class SP, + template class CNP1, + typename U + > + inline void Reset(SmartPtr& sp, + typename SP::StoredType p) + { SmartPtr(p).Swap(sp); } + //////////////////////////////////////////////////////////////////////////////// // free comparison operators for class template SmartPtr //////////////////////////////////////////////////////////////////////////////// @@ -1526,6 +1614,9 @@ namespace std // $Log$ +// Revision 1.34 2006/10/11 10:44:21 syntheticpp +// fix gcc>4.1 handling of injected friends +// // Revision 1.33 2006/07/07 09:50:30 syntheticpp // also compile when std::string is not implicit included/typedefed by other headers; the SUN compiler needs the explicit include of //