Go to the documentation of this file.00001 #ifndef __NITRO_MEMORY_HANDLER_CPP__
00002 #define __NITRO_MEMORY_HANDLER_CPP__
00003
00004 #include <utilities/memory_handler.h>
00005
00006 namespace nitro{
00007
00008 MemoryDescription::MemoryDescription( void * theMemoryBlock , const std::size_t theMemoryBlockSize , const std::string & theBlockDescription )
00009 {
00010 try
00011 {
00012 MemoryBlock = theMemoryBlock;
00013
00014 MemoryBlockSize = theMemoryBlockSize;
00015
00016 BlockDescription = theBlockDescription;
00017
00018 ReferenceCounter = 1;
00019 }
00020 catch( nitro::exception e )
00021 {
00022 throw( nitro::exception( std::string( "MemoryDescription::MemoryDescription( const void * theMemoryBlock , const std::size_t theMemoryBlockSize , const std::string & theBlockDescription )::" ) + e.what() , e.code() ) );
00023 }
00024 catch( ... )
00025 {
00026 throw( nitro::exception( std::string( "MemoryDescription::MemoryDescription( const void * theMemoryBlock , const std::size_t theMemoryBlockSize , const std::string & theBlockDescription )::An error occured" ) , 0 ) );
00027 }
00028 }
00029
00030 void MemoryDescription::OnAssigned( void )
00031 {
00032 try
00033 {
00034 ReferenceCounter--;
00035 }
00036 catch( nitro::exception e )
00037 {
00038 throw( nitro::exception( std::string( "MemoryDescription::OnAssigned( void )::" ) + e.what() , e.code() ) );
00039 }
00040 catch( ... )
00041 {
00042 throw( nitro::exception( std::string( "MemoryDescription::OnAssigned( void )::An error occured" ) , 0 ) );
00043 }
00044 }
00045
00046 void MemoryDescription::OnCopied( void )
00047 {
00048 try
00049 {
00050 ReferenceCounter++;
00051 }
00052 catch( nitro::exception e )
00053 {
00054 throw( nitro::exception( std::string( "MemoryDescription::OnCopied( void )::" ) + e.what() , e.code() ) );
00055 }
00056 catch( ... )
00057 {
00058 throw( nitro::exception( std::string( "MemoryDescription::OnCopied( void )::An error occured" ) , 0 ) );
00059 }
00060 }
00061
00062 bool MemoryDescription::AddressIn( void * Address )
00063 {
00064 try
00065 {
00066 return( MemoryBlock >= Address && Address <= ( ( char * )MemoryBlock ) + MemoryBlockSize );
00067 }
00068 catch( nitro::exception e )
00069 {
00070 throw( nitro::exception( std::string( "MemoryDescription::AddressIn( void * Address )::" ) + e.what() , e.code() ) );
00071 }
00072 catch( ... )
00073 {
00074 throw( nitro::exception( std::string( "MemoryDescription::AddressIn( void * Address )::An error occured" ) , 0 ) );
00075 }
00076 }
00077
00078 void MemoryDescription::RegisterPointer( PointerInterface * Ptr )
00079 {
00080 try
00081 {
00082 if( AddressIn( ( void * ) Ptr ) )
00083 {
00084 NestedPointers.push_back( Ptr );
00085 }
00086 }
00087 catch( nitro::exception e )
00088 {
00089 throw( nitro::exception( std::string( "MemoryDescription::RegisterPointer( PointerInterface * Ptr )::" ) + e.what() , e.code() ) );
00090 }
00091 catch( ... )
00092 {
00093 throw( nitro::exception( std::string( "MemoryDescription::RegisterPointer( PointerInterface * Ptr )::An error occured" ) , 0 ) );
00094 }
00095 }
00096
00097 void MemoryDescription::ReleaseNestedPointers( void )
00098 {
00099 try
00100 {
00101 for( std::size_t i( 0 ) ; i < NestedPointers.size() ; i++ )
00102 {
00103 NestedPointers[ i ]->Release();
00104 }
00105
00106 NestedPointers.erase( NestedPointers.begin() , NestedPointers.end() );
00107 }
00108 catch( nitro::exception e )
00109 {
00110 throw( nitro::exception( std::string( "MemoryDescription::RegisterPointer( PointerInterface * Ptr )::" ) + e.what() , e.code() ) );
00111 }
00112 catch( ... )
00113 {
00114 throw( nitro::exception( std::string( "MemoryDescription::RegisterPointer( PointerInterface * Ptr )::An error occured" ) , 0 ) );
00115 }
00116 }
00117
00118 DLL_ENTITY MemoryHandler StdMemoryHandler;
00119
00120 }
00121
00122 #endif