Public Member Functions | Private Attributes

nitro::MemoryDescription Class Reference

#include <utilities/memory_handler.h>

Collaboration diagram for nitro::MemoryDescription:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 MemoryDescription (void *theMemoryBlock, const std::size_t theMemoryBlockSize, const std::string &theBlockDescription)
void OnAssigned (void)
void OnCopied (void)
bool AddressIn (void *Address)
void RegisterPointer (PointerInterface *Ptr)
void ReleaseNestedPointers (void)

Private Attributes

void * MemoryBlock
std::size_t MemoryBlockSize
std::string BlockDescription
std::size_t ReferenceCounter
std::vector< PointerInterface * > NestedPointers

Detailed Description

Objects of this class stores allocated memory block's description.

Author:
Dodonov A.A.

Definition at line 39 of file memory_handler.h.


Constructor & Destructor Documentation

nitro::MemoryDescription::MemoryDescription ( void *  theMemoryBlock,
const std::size_t  theMemoryBlockSize,
const std::string &  theBlockDescription 
)

Constructor.

Parameters:
theMemoryBlock - Pointer on the allocated memory block.
theMemoryBlockSize - Size of the allocated memory block.
theBlockDescription - String description of the allocated memory block.
Author:
Dodonov A.A.

Definition at line 8 of file memory_handler.cpp.

References BlockDescription, nitro::exception::code(), MemoryBlock, MemoryBlockSize, ReferenceCounter, and nitro::exception::what().

        {
                try
                {
                        MemoryBlock = theMemoryBlock;
                
                        MemoryBlockSize = theMemoryBlockSize;
                        
                        BlockDescription = theBlockDescription;
                        
                        ReferenceCounter = 1;
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "MemoryDescription::MemoryDescription( const void * theMemoryBlock , const std::size_t theMemoryBlockSize , const std::string & theBlockDescription )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "MemoryDescription::MemoryDescription( const void * theMemoryBlock , const std::size_t theMemoryBlockSize , const std::string & theBlockDescription )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:


Member Function Documentation

bool nitro::MemoryDescription::AddressIn ( void *  Address  ) 

Function validates does address Address belongs to the allocated memory block.

Parameters:
Address - Validating address.
Exceptions:
nitro::exception Can throw exception of this type. It contains a description of the error and error code.
Author:
Dodonov A.A.

Definition at line 62 of file memory_handler.cpp.

References nitro::exception::code(), MemoryBlock, MemoryBlockSize, and nitro::exception::what().

Referenced by RegisterPointer().

        {
                try
                {
                        return( MemoryBlock >= Address && Address <= ( ( char * )MemoryBlock ) + MemoryBlockSize );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "MemoryDescription::AddressIn( void * Address )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "MemoryDescription::AddressIn( void * Address )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

void nitro::MemoryDescription::OnAssigned ( void   ) 

Function is called at the moment when pointer is set with the new address.

Author:
Dodonov A.A.

Definition at line 30 of file memory_handler.cpp.

References nitro::exception::code(), ReferenceCounter, and nitro::exception::what().

        {
                try
                {
                        ReferenceCounter--;
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "MemoryDescription::OnAssigned( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "MemoryDescription::OnAssigned( void )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

void nitro::MemoryDescription::OnCopied ( void   ) 

Function is called at the moment when pointer is used to initialize another pointer.

Author:
Dodonov A.A.

Definition at line 46 of file memory_handler.cpp.

References nitro::exception::code(), ReferenceCounter, and nitro::exception::what().

        {
                try
                {
                        ReferenceCounter++;
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "MemoryDescription::OnCopied( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "MemoryDescription::OnCopied( void )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

void nitro::MemoryDescription::RegisterPointer ( PointerInterface Ptr  ) 

Function registers pointer for the described memory block.

Parameters:
Ptr - Pointer to register.
Exceptions:
nitro::exception - Can throw exception of this type. It contains a description of the error and error code.
Author:
Dodonov A.A.

Definition at line 78 of file memory_handler.cpp.

References AddressIn(), nitro::exception::code(), NestedPointers, and nitro::exception::what().

        {
                try
                {
                        if( AddressIn( ( void * ) Ptr ) )
                        {
                                NestedPointers.push_back( Ptr );
                        }
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "MemoryDescription::RegisterPointer( PointerInterface * Ptr )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "MemoryDescription::RegisterPointer( PointerInterface * Ptr )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

void nitro::MemoryDescription::ReleaseNestedPointers ( void   ) 

Function releases all allocated memory throgh all registred nested pointers.

Exceptions:
nitro::exception - Can throw exception of this type. It contains a description of the error and error code.
Author:
Dodonov A.A.

Definition at line 97 of file memory_handler.cpp.

References nitro::exception::code(), NestedPointers, and nitro::exception::what().

        {
                try
                {
                        for( std::size_t i( 0 ) ; i < NestedPointers.size() ; i++ )
                        {
                                NestedPointers[ i ]->Release();
                        }

                        NestedPointers.erase( NestedPointers.begin() , NestedPointers.end() );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "MemoryDescription::RegisterPointer( PointerInterface * Ptr )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "MemoryDescription::RegisterPointer( PointerInterface * Ptr )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:


Member Data Documentation

String description of the allocated memory block.

Author:
Dodonov A.A.

Definition at line 182 of file memory_handler.h.

Referenced by MemoryDescription().

Pointer on the allocated memory block.

Author:
Dodonov A.A.

Definition at line 158 of file memory_handler.h.

Referenced by AddressIn(), and MemoryDescription().

Size of the allocated memory block.

Author:
Dodonov A.A.

Definition at line 170 of file memory_handler.h.

Referenced by AddressIn(), and MemoryDescription().

Array contains all pointers from the described memory block.

Author:
Dodonov A.A.

Definition at line 206 of file memory_handler.h.

Referenced by RegisterPointer(), and ReleaseNestedPointers().

Reference counter.

Author:
Dodonov A.A.

Definition at line 194 of file memory_handler.h.

Referenced by MemoryDescription(), OnAssigned(), and OnCopied().


The documentation for this class was generated from the following files:

Generated by  doxygen 1.6.1