From: <ric...@us...> - 2011-09-20 23:25:47
|
Revision: 1112 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1112&view=rev Author: rich_sposato Date: 2011-09-20 23:25:41 +0000 (Tue, 20 Sep 2011) Log Message: ----------- -m Modified Paths: -------------- trunk/include/loki/StrongPtr.h trunk/src/StrongPtr.cpp Modified: trunk/include/loki/StrongPtr.h =================================================================== --- trunk/include/loki/StrongPtr.h 2011-09-20 23:19:14 UTC (rev 1111) +++ trunk/include/loki/StrongPtr.h 2011-09-20 23:25:41 UTC (rev 1112) @@ -85,7 +85,10 @@ /// If you write your own policy, you must implement these 3 functions: /// -# void static Delete( const P * p ) /// -# static P * Default( void ) -/// -# void Swap( YourResetPolicy & ) +/// -# Default constructor. +/// -# Copy constructor. +/// -# Templated copy constructor. +/// -# void Swap( YourDeletePolicy & ) /// /// \par ResetPolicy /// A reset policy tells the ReleaseAll and ResetAll functions whether they @@ -235,46 +238,7 @@ inline void Swap( DeleteSingle & ) {} }; -namespace Private -{ - //////////////////////////////////////////////////////////////////////////////// -/// \class DeleteArrayBase -/// -/// \ingroup StrongPointerDeleteGroup -/// Base class used only by the DeleteArray policy class. This stores the -/// number of elements in an array of shared objects. -//////////////////////////////////////////////////////////////////////////////// - -class DeleteArrayBase -{ -public: - - inline size_t GetArrayCount( void ) const { return m_itemCount; } - -protected: - - DeleteArrayBase( void ) : m_itemCount( 0 ) {} - - explicit DeleteArrayBase( size_t itemCount ) : m_itemCount( itemCount ) {} - - DeleteArrayBase( const DeleteArrayBase & that ) : m_itemCount( that.m_itemCount ) {} - - void Swap( DeleteArrayBase & rhs ); - - void OnInit( const void * p ) const; - - void OnCheckRange( size_t index ) const; - -private: - - size_t m_itemCount; - -}; - -} - -//////////////////////////////////////////////////////////////////////////////// /// \class DeleteArray /// /// \ingroup StrongPointerDeleteGroup @@ -2068,19 +2032,27 @@ return * GetPointer(); } + /** operator[] returns a reference to an modifiable object. If the index is greater than or + equal to the number of elements, the function will throw a std::out_of_range exception. + This only works with DeleteArray policy. Any other policy will cause a compiler error. + */ ReferenceType operator [] ( size_t index ) { - KP::OnDereference( GetPointer() ); - DP::OnCheckRange( index ); PointerType p = GetPointer(); + KP::OnDereference( p ); + DP::OnCheckRange( index ); return p[ index ]; } + /** operator[] returns a reference to a const object. If the index is greater than or + equal to the number of elements, the function will throw a std::out_of_range exception. + This only works with DeleteArray policy. Any other policy will cause a compiler error. + */ ConstReferenceType operator [] ( size_t index ) const { - KP::OnDereference( GetPointer() ); - DP::OnCheckRange( index ); ConstPointerType p = GetPointer(); + KP::OnDereference( p ); + DP::OnCheckRange( index ); return p[ index ]; } Modified: trunk/src/StrongPtr.cpp =================================================================== --- trunk/src/StrongPtr.cpp 2011-09-20 23:19:14 UTC (rev 1111) +++ trunk/src/StrongPtr.cpp 2011-09-20 23:25:41 UTC (rev 1112) @@ -15,9 +15,6 @@ #include <loki/StrongPtr.h> -#include <stdexcept> -#include <string> - #include <memory.h> #ifdef DO_EXTRA_LOKI_TESTS #include <cassert> @@ -41,45 +38,6 @@ // ---------------------------------------------------------------------------- -void DeleteArrayBase::Swap( DeleteArrayBase & rhs ) -{ - assert( NULL != this ); - - const size_t temp = m_itemCount; - m_itemCount = rhs.m_itemCount; - rhs.m_itemCount = temp; -} - -// ---------------------------------------------------------------------------- - -void DeleteArrayBase::OnInit( const void * p ) const -{ - assert( NULL != this ); - if ( NULL == p ) - { - assert( 0 == m_itemCount ); - } - else - { - assert( 0 < m_itemCount ); - } -} - -// ---------------------------------------------------------------------------- - -void DeleteArrayBase::OnCheckRange( size_t index ) const -{ - assert( NULL != this ); - - if ( index < m_itemCount ) - return; - - const ::std::string message( "index out of range in ::Loki::DeleteArrayBase::OnCheckRange" ); - throw ::std::out_of_range( message ); -} - -// ---------------------------------------------------------------------------- - OneOwnerRefCountInfo::OneOwnerRefCountInfo( SingleOwnerRefCount * ptr ) : m_pointer( NULL ) , m_strongPtr( ptr ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |