Class allowes to store binary data. More...
#include <utilities/binary_data.h>
Public Member Functions | |
BinaryData (void) | |
BinaryData (const char &Ch) | |
BinaryData (const char *Buffer) | |
BinaryData (const char *Buffer, const std::size_t &Length) | |
BinaryData (const BinaryData &Data) | |
operator const char * () const | |
BinaryData | operator= (const BinaryData &Data) |
void | AppendData (const char &Ch) |
void | AppendData (const char *Buffer) |
void | AppendData (const std::string &Buffer) |
void | AppendData (const char *Buffer, const std::size_t &Length) |
std::size_t | GetBufferLength (void) const |
const char * | GetBuffer (void) const |
void | SetByte (std::size_t BytePos, char ByteValue) |
void | Release (void) |
void | Reserve (const std::size_t &theLength) |
virtual | ~BinaryData () |
Static Public Member Functions | |
static int | GetFirstOccurance (const char *OriginalBuffer, const std::size_t OriginalBufferLength, const char *Buffer, const std::size_t BufferLength, const std::size_t StartFrom=0) |
static int | GetFirstOccurance (const BinaryData &c, const char *Buffer, const std::size_t BufferLength, const std::size_t StartFrom=0) |
static int | GetOccuranceCount (const char *OriginalBuffer, const std::size_t OriginalBufferLength, const char *Buffer, const std::size_t BufferLength) |
static int | GetOccuranceCount (const BinaryData &c, const char *Buffer, const std::size_t BufferLength) |
static void | ReplaceBuffer (BinaryData &c, const std::size_t StartPos, const std::size_t ReplaceLength, const char *Buffer, const std::size_t BufferLength) |
static void | ReplaceBuffer (BinaryData &c, const char *NeedleBuffer, const std::size_t NeedleBufferLength, const char *Buffer, const std::size_t BufferLength) |
Private Attributes | |
std::vector< char > | Data |
Class allowes to store binary data.
Definition at line 56 of file binary_data.h.
nitro::BinaryData::BinaryData | ( | void | ) |
Default constructor.
nitro::exception | Throws exception with the description of error. |
Definition at line 11 of file binary_data.cpp.
: Data() { }
nitro::BinaryData::BinaryData | ( | const char & | Ch | ) |
Constructor loads data.
Ch | - Additing data. |
nitro::exception | Throws exception with the description of error. |
Definition at line 15 of file binary_data.cpp.
References nitro::exception::code(), Data, and nitro::exception::what().
{ try { Data.push_back( Ch ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::BinaryData( const char & Ch )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::BinaryData( const char & Ch )::An error occured" ) , 0 ) ); } }
nitro::BinaryData::BinaryData | ( | const char * | Buffer | ) |
Constructor loads binary data from NULL-terminated string.
Buffer | - Additing data. |
nitro::exception | Throws exception with the description of error. |
Definition at line 31 of file binary_data.cpp.
References AppendData(), nitro::exception::code(), and nitro::exception::what().
{ try { // копируем без нуль символа!!! AppendData( Buffer , strlen( Buffer ) + 1 ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::BinaryData( const char * Buffer )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::BinaryData( const char * Buffer )::An error occured" ) , 0 ) ); } }
nitro::BinaryData::BinaryData | ( | const char * | Buffer, | |
const std::size_t & | Length | |||
) |
Constructor accepts custom binary data
Buffer | - Добавляемые данные. | |
Length | - Длина добавляемого буффера. |
nitro::exception | Кидает исключение с описанием ошибки. |
Definition at line 48 of file binary_data.cpp.
References AppendData(), nitro::exception::code(), and nitro::exception::what().
{ try { AppendData( Buffer , Length ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::BinaryData( const char * Buffer , const std::size_t & Length )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::BinaryData( const char * Buffer , const std::size_t & Length )::An error occured" ) , 0 ) ); } }
nitro::BinaryData::BinaryData | ( | const BinaryData & | Data | ) |
Copy-constructor.
Data | - Initializing data. |
nitro::exception | Throws exception with the description of error. |
Definition at line 64 of file binary_data.cpp.
References AppendData(), nitro::exception::code(), GetBuffer(), GetBufferLength(), Release(), and nitro::exception::what().
{ try { Release(); AppendData( Data.GetBuffer() , Data.GetBufferLength() ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::BinaryData( const BinaryData & Data )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::BinaryData( const BinaryData & Data )::An error occured" ) , 0 ) ); } }
nitro::BinaryData::~BinaryData | ( | ) | [virtual] |
Destructor (virtual).
Dodonov A.A.
Definition at line 269 of file binary_data.cpp.
References Release().
{ try { Release(); } catch( ... ) { } }
void nitro::BinaryData::AppendData | ( | const char & | Ch | ) |
Function appends data in the existing buffer.
Ch | - Appending NULL-terminated data. |
nitro::exception | Throws exception with the description of error. |
Definition at line 118 of file binary_data.cpp.
References nitro::exception::code(), Data, and nitro::exception::what().
Referenced by AppendData(), nitro::CSVFile::AppendRecord(), BinaryData(), nitro::File::LoadBinDataFromFile(), nitro::INIFile::LoadINIFile(), operator=(), nitro::CSVFile::ReadRecord(), and nitro::INIFile::SaveINIFile().
{ try { Data.push_back( Ch ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::AppendData( const char & Ch )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::AppendData( const char & Ch )::An error occured" ) , 0 ) ); } }
void nitro::BinaryData::AppendData | ( | const char * | Buffer | ) |
Function appends NULL-terminated data in the existing buffer.
Buffer | - Appending NULL-terminated data. |
nitro::exception | Throws exception with the description of error. |
Definition at line 134 of file binary_data.cpp.
References AppendData(), nitro::exception::code(), and nitro::exception::what().
{ try { AppendData( Buffer , strlen( Buffer ) ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::AppendData( const char * Buffer )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::AppendData( const char * Buffer )::An error occured" ) , 0 ) ); } }
void nitro::BinaryData::AppendData | ( | const std::string & | Buffer | ) |
Function appends data in the existing buffer.
Buffer | - Appending NULL-terminated data. |
nitro::exception | Throws exception with the description of error. |
Definition at line 150 of file binary_data.cpp.
References AppendData(), nitro::exception::code(), and nitro::exception::what().
{ try { AppendData( Buffer.c_str() , Buffer.size() ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::AppendData( const char * Buffer )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::AppendData( const char * Buffer )::An error occured" ) , 0 ) ); } }
void nitro::BinaryData::AppendData | ( | const char * | Buffer, | |
const std::size_t & | Length | |||
) |
Function appends data to an existing one.
Buffer | - Appending data. | |
Length | - Length of the appending data. |
nitro::exception | Throws exception with the description of error. |
Definition at line 166 of file binary_data.cpp.
References nitro::exception::code(), Data, and nitro::exception::what().
{ try { std::size_t OldSize( Data.size() ); Data.resize( OldSize + theLength ); memcpy( &( Data[ OldSize ] ) , Buffer , theLength ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::AppendData( const char * Buffer , const std::size_t & theLength )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::AppendData( const char * Buffer , const std::size_t & theLength )::An error occured" ) , 0 ) ); } }
const char * nitro::BinaryData::GetBuffer | ( | void | ) | const |
Function provides access to stored data.
nitro::exception | Throws exception with the description of error. |
Definition at line 200 of file binary_data.cpp.
References nitro::exception::code(), Data, and nitro::exception::what().
Referenced by nitro::ZIPAbstraction::AddFile(), nitro::CSVFile::AppendRecord(), BinaryData(), GetFirstOccurance(), GetOccuranceCount(), nitro::INIFile::LoadINIFile(), nitro::XMLFile::LoadXML(), operator const char *(), operator=(), nitro::CSVFile::ReadRecord(), and nitro::File::SaveBinDataToFile().
{ try { return( &( Data[ 0 ] ) ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::GetBuffer( void )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::GetBuffer( void )::An error occured" ) , 0 ) ); } }
std::size_t nitro::BinaryData::GetBufferLength | ( | void | ) | const |
Function provides access to stored buffer's length.
nitro::exception | Кидает исключение с описанием ошибки. |
nitro::exception | Throws exception with the description of error. |
Definition at line 184 of file binary_data.cpp.
References nitro::exception::code(), Data, and nitro::exception::what().
Referenced by nitro::ZIPAbstraction::AddFile(), nitro::CSVFile::AppendRecord(), BinaryData(), GetFirstOccurance(), GetOccuranceCount(), nitro::XMLFile::LoadXML(), operator=(), nitro::CSVFile::ReadRecord(), and nitro::File::SaveBinDataToFile().
{ try { return( Data.size() ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::GetBufferLength( void ) const::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::GetBufferLength( void ) const::An error occured" ) , 0 ) ); } }
int nitro::BinaryData::GetFirstOccurance | ( | const BinaryData & | c, | |
const char * | Buffer, | |||
const std::size_t | BufferLength, | |||
const std::size_t | StartFrom = 0 | |||
) | [static] |
Function validates container "c" for existance of chain of bites.
c | - Container with data. | |
Buffer | - Chane of bytes to test. | |
BufferLength | - Length of the searched buffer. | |
StartFrom | - First starting simbol in c. |
Definition at line 308 of file binary_data.cpp.
References nitro::exception::code(), GetBuffer(), GetBufferLength(), GetFirstOccurance(), and nitro::exception::what().
{ try { return( GetFirstOccurance( c.GetBuffer() , c.GetBufferLength() , Buffer , BufferLength ) ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "GetFirstOccurance( const BinaryData & c , const char * Buffer , const std::size_t BufferLength )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "GetFirstOccurance( const BinaryData & c , const char * Buffer , const std::size_t BufferLength )::An error occured while executing template< class container , class raw >int GetFirstOccurance( const container & c , const raw & r )" ) , 0 ) ); } }
int nitro::BinaryData::GetFirstOccurance | ( | const char * | OriginalBuffer, | |
const std::size_t | OriginalBufferLength, | |||
const char * | Buffer, | |||
const std::size_t | BufferLength, | |||
const std::size_t | StartFrom = 0 | |||
) | [static] |
Function validates container "c" for existance of chain of bites.
OriginalBuffer | - Buffer with data. | |
OriginalBufferLength | - Buffer's length. | |
Buffer | - Chane of bytes to test. | |
BufferLength | - Length of the searched buffer. | |
StartFrom | - First starting simbol in c. |
nitro::exception | Throws exception with the description of error. |
Definition at line 280 of file binary_data.cpp.
References nitro::exception::code(), and nitro::exception::what().
Referenced by GetFirstOccurance(), GetOccuranceCount(), ReplaceBuffer(), and nitro::TemplateEngine::SetVariable().
{ try { for( std::size_t i( StartFrom ) ; i < OriginalBufferLength ; i++ ) { std::size_t j( 0 ); for( ; j < BufferLength && i + j < OriginalBufferLength && OriginalBuffer[ i + j ] == Buffer[ j ] ; j++ ); if( j == BufferLength ) { return( ( int )i ); } } return( -1 ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::GetFirstOccurance( const char * OriginalBuffer , const std::size_t OriginalBufferLength , const char * Buffer , const std::size_t BufferLength , const std::size_t StartFrom /* = 0 */ )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::GetFirstOccurance( const char * OriginalBuffer , const std::size_t OriginalBufferLength , const char * Buffer , const std::size_t BufferLength , const std::size_t StartFrom /* = 0 */ )::An error occured while executing template< class container , class raw >int GetFirstOccurance( const container & c , const raw & r )" ) , 0 ) ); } }
int nitro::BinaryData::GetOccuranceCount | ( | const char * | OriginalBuffer, | |
const std::size_t | OriginalBufferLength, | |||
const char * | Buffer, | |||
const std::size_t | BufferLength | |||
) | [static] |
Function counts all occurances of buffer Buffer.
OriginalBuffer | - Buffer with data. | |
OriginalBufferLength | - Buffer's length. | |
Buffer | - Chane of bytes to test. | |
BufferLength | - Length of the searched buffer. |
nitro::exception | Throws exception with the description of error. |
Definition at line 324 of file binary_data.cpp.
References nitro::exception::code(), GetFirstOccurance(), and nitro::exception::what().
Referenced by nitro::CSVFile::AppendRecord(), and GetOccuranceCount().
{ try { std::size_t Counter( 0 ); int Tmp; for( int i( 0 ) ; i < ( int )OriginalBufferLength ; i++ ) { Tmp = GetFirstOccurance( OriginalBuffer , OriginalBufferLength , Buffer , BufferLength , i ); if( Tmp != -1 ) { Counter++; i = ( int )( Tmp + BufferLength - 1 ); } } return( ( int )Counter ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::GetOccuranceCount( const char * OriginalBuffer , const std::size_t OriginalBufferLength , const char * Buffer , const std::size_t BufferLength )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::GetOccuranceCount( const char * OriginalBuffer , const std::size_t OriginalBufferLength , const char * Buffer , const std::size_t BufferLength )::An error occured" ) , 0 ) ); } }
int nitro::BinaryData::GetOccuranceCount | ( | const BinaryData & | c, | |
const char * | Buffer, | |||
const std::size_t | BufferLength | |||
) | [static] |
Function counts all occurances of buffer Buffer.
c | - Container with data. | |
Buffer | - Chane of bytes to test. | |
BufferLength | - Length of the searched buffer. |
nitro::exception | Throws exception with the description of error. |
Definition at line 353 of file binary_data.cpp.
References nitro::exception::code(), GetBuffer(), GetBufferLength(), GetOccuranceCount(), and nitro::exception::what().
{ try { return( GetOccuranceCount( c.GetBuffer() , c.GetBufferLength() , Buffer , BufferLength ) ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::GetOccuranceCount( const BinaryData & c , const char * Buffer , const std::size_t BufferLength )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::GetOccuranceCount( const BinaryData & c , const char * Buffer , const std::size_t BufferLength )::An error occured" ) , 0 ) ); } }
nitro::BinaryData::operator const char * | ( | ) | const |
Function converts data into string.
nitro::exception | Throws exception with the description of error. |
Definition at line 82 of file binary_data.cpp.
References nitro::exception::code(), GetBuffer(), and nitro::exception::what().
{ try { return( GetBuffer() ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::operator const char * () const::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::operator const char * () const::An error occured" ) , 0 ) ); } }
BinaryData nitro::BinaryData::operator= | ( | const BinaryData & | Data | ) |
Assignment operator.
Data | - Initializing data. |
nitro::exception | Throws exception with the description of error. |
Definition at line 98 of file binary_data.cpp.
References AppendData(), nitro::exception::code(), GetBuffer(), GetBufferLength(), Release(), and nitro::exception::what().
{ try { Release(); AppendData( Data.GetBuffer() , Data.GetBufferLength() ); return( *this ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::operator=( const BinaryData & Data )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::operator=( const BinaryData & Data )::An error occured" ) , 0 ) ); } }
void nitro::BinaryData::Release | ( | void | ) |
Function releases buffer with stored data.
nitro::exception | Throws exception with the description of error. |
Definition at line 232 of file binary_data.cpp.
References nitro::exception::code(), Data, and nitro::exception::what().
Referenced by BinaryData(), operator=(), and ~BinaryData().
{ try { Data.clear(); Data.resize( 0 ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::Release( void )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::Release( void )::An error occured" ) , 0 ) ); } }
void nitro::BinaryData::ReplaceBuffer | ( | BinaryData & | c, | |
const char * | NeedleBuffer, | |||
const std::size_t | NeedleBufferLength, | |||
const char * | Buffer, | |||
const std::size_t | BufferLength | |||
) | [static] |
Function replaces part of the buffer.
c | - Binary data. | |
NeedleBuffer | - Buffer to be replaced. | |
NeedleBufferLength | - Length of the replacing buffer. | |
Buffer | - New buffer. | |
BufferLength | - New buffer's length. |
nitro::exception | Throws exception with the description of error. |
Definition at line 392 of file binary_data.cpp.
References nitro::exception::code(), GetFirstOccurance(), ReplaceBuffer(), and nitro::exception::what().
{ try { int Cursor( 0 ); int StartFrom( 0 ); for( ; ( Cursor = GetFirstOccurance( c , NeedleBuffer , NeedleBufferLength , StartFrom ) ) != -1 ; ) { ReplaceBuffer( c , Cursor , NeedleBufferLength , Buffer , BufferLength ); StartFrom = ( int )( Cursor + BufferLength ); } } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::ReplaceBuffer( BinaryData & c , const char * NeedleBuffer , const std::size_t NeedleBufferLength , const char * Buffer , const std::size_t BufferLength )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::ReplaceBuffer( BinaryData & c , const char * NeedleBuffer , const std::size_t NeedleBufferLength , const char * Buffer , const std::size_t BufferLength )::An error occured" ) , 0 ) ); } }
void nitro::BinaryData::ReplaceBuffer | ( | BinaryData & | c, | |
const std::size_t | StartPos, | |||
const std::size_t | ReplaceLength, | |||
const char * | Buffer, | |||
const std::size_t | BufferLength | |||
) | [static] |
Function replaces part of the buffer.
c | - Binary data. | |
StartPos | - Position of the replacing part's beginning. | |
ReplaceLength | - Length of the replacing part. | |
Buffer | - New buffer. | |
BufferLength | - New buffer's length. |
nitro::exception | Throws exception with the description of error. |
Definition at line 369 of file binary_data.cpp.
References nitro::exception::code(), Data, and nitro::exception::what().
Referenced by nitro::INIFile::LoadINIFile(), nitro::CSVFile::ReadRecord(), ReplaceBuffer(), and nitro::TemplateEngine::SetVariable().
{ try { c.Data.erase( c.Data.begin() + StartPos , c.Data.begin() + StartPos + ReplaceLength ); std::insert_iterator< std::vector< char > > InsertIterator( c.Data , c.Data.begin() + StartPos ); for( std::size_t i( 0 ) ; i < BufferLength ; i++ ) { *InsertIterator = Buffer[ i ]; } } catch( nitro::exception e ) { throw( nitro::exception( std::string( "ReplaceBuffer( BinaryData & c , std::size_t StartPos , std::size_t ReplaceLength , const char * Buffer , const std::size_t BufferLength )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "ReplaceBuffer( BinaryData & c , std::size_t StartPos , std::size_t ReplaceLength , const char * Buffer , const std::size_t BufferLength )::An error occured" ) , 0 ) ); } }
void nitro::BinaryData::Reserve | ( | const std::size_t & | theLength | ) |
Function reserves data.
theLength | - Amount of data to reserve. |
nitro::exception | Throws exception with the description of error. |
Definition at line 249 of file binary_data.cpp.
References nitro::exception::code(), Data, and nitro::exception::what().
Referenced by nitro::CSVFile::AppendRecord().
{ try { if( Data.size() < theLength ) { Data.reserve( theLength ); } Data.resize( 0 ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::Reserve( const std::size_t & theLength )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::Reserve( const std::size_t & theLength )::An error occured" ) , 0 ) ); } }
void nitro::BinaryData::SetByte | ( | std::size_t | BytePos, | |
char | ByteValue | |||
) |
Function sets byte in buffer.
BytePos | - Position of the setting byte. | |
ByteValue | - Value of the setting byte. |
nitro::exception | Throws exception with the description of error. |
Definition at line 216 of file binary_data.cpp.
References nitro::exception::code(), Data, and nitro::exception::what().
{ try { Data[ BytePos ] = ByteValue; } catch( nitro::exception e ) { throw( nitro::exception( std::string( "BinaryData::SetByte( std::size_t BytePos , char ByteValue )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "BinaryData::SetByte( std::size_t BytePos , char ByteValue )::An error occured" ) , 0 ) ); } }
std::vector< char > nitro::BinaryData::Data [private] |
Buffer for stored data.
Definition at line 628 of file binary_data.h.
Referenced by AppendData(), BinaryData(), GetBuffer(), GetBufferLength(), Release(), ReplaceBuffer(), Reserve(), and SetByte().