#ifndef VM_GROWABLE_BYTE_ARRAY_H_INCLUDED
#define VM_GROWABLE_BYTE_ARRAY_H_INCLUDED
/*****************************************************************************/
/* HEADER FILE */
/*****************************************************************************/
/*
$Archive: $
$Revision: $
$Date: $
$Author: $
Description: Declaration of an expandable byte array class and a derivation
of the same that converts back and forth between char arrays
and byte arrays
TOOL And XML FORMS License
==========================
Except where otherwise noted, all of the documentation
and software included in the TOOL package is
copyrighted by Michael Swartzendruber.
Copyright (C) 2005 Michael John Swartzendruber.
All rights reserved.
Access to this code, whether intentional or accidental,
does NOT IMPLY any transfer of rights.
This software is provided "as-is," without any express
or implied warranty. In no event shall the author be held
liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for
any purpose, including commercial applications, and to
alter and redistribute it, provided that the following
conditions are met:
1. All redistributions of source code files must retain
all copyright notices that are currently in place,
and this list of conditions without modification.
2. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software.
3. If you use this software in another product, an acknowledgment
in the product documentation would be appreciated but is
not required.
4. Modified versions in source or binary form must be plainly
marked as such, and must not be misrepresented as being
the original software.
*/
/*****************************************************************************/
#include <windows.h>
#include "../../../stdafx.h"
#pragma warning( disable : 4786 )
#pragma warning( disable : 4800 )
#pragma warning( disable : 4231 ) // disable warning "extern before template instantiation"
#pragma warning( disable : 4251 )
#include <map>
#include <string>
class VMByteArray
{
public:
// default ctor
//
VMByteArray( void );
virtual ~VMByteArray( void );
// copy ctor and assignment operator
//
VMByteArray( const VMByteArray& roOther );
VMByteArray& operator = ( const VMByteArray& roOther );
VMByteArray( const char* pchString );
VMByteArray( const char* pchString, int iSize );
// another way to copy objects
//
void Copy( const VMByteArray& roOther );
// buffer size accessors
//
void SetSize( long lNewSize, long lGrowBy = -1 );
long GetSize( void ) const;
long GetUpperBound( void ) const;
long GetGrowBySize( void ) const;
// eliminate buffer space that is not used
//
void FreeExtra( void );
// delete all internal data
//
void FreeAll( void );
// ways to fetch a specific element in the collection
//
const BYTE GetAt( long lIndex ) const;
const BYTE ElementAt( long lIndex ) const;
const BYTE operator[]( long lIndex );
// ways to add new data elements to the data array
//
void SetAt( long lIndex, BYTE& rNewByte );
void SetAtGrow( long lIndex, BYTE& roNewByte );
long Append( BYTE& roNewByte );
long Append( const VMByteArray& roToAppend );
long Append( const char* pchToAppend, int iCount );
void InsertAt( long lIndex, BYTE& roToInsert, long lCount = 1 );
void InsertAt( long lIndex, VMByteArray& roToInsert );
void InsertAt( long lIndex, const char* pchToInsert, long lCount = 1 );
void RemoveAt( long lIndex, long lCount = 1 );
int Add( BYTE chNewElement );
// get a const ptr to the internal data
//
const BYTE* GetData( void ) const;
private:
BYTE* m_pData;
long m_lBufferSize;
long m_lAllocated;
long m_lGrowBy;
};
///////////////////////////////////////////////////////////////////////////////
//
// derived class that allows byte arrays to be converted to/from character
// strings
//
///////////////////////////////////////////////////////////////////////////////
class VMCharByteArray : public VMByteArray
{
public:
VMCharByteArray( void ) : VMByteArray(){;};
VMCharByteArray( const char* pchString) : VMByteArray( pchString ){;};
VMCharByteArray( const char* pchString, int iSize ) : VMByteArray( pchString, iSize ){;};
~VMCharByteArray( void ){;};
VMByteArray& FromString( const char* pchString, unsigned int uiTop, bool bCheckForOx = true );
void ToString( char* pchOutput, long lOutBufferSize, bool bStampDataWithOx = true );
const char* AsString( void );
private:
char GetCharValue( BYTE iByte );
BYTE GetNibbleValue( char chChar );
};
typedef std::map< std::string, VMCharByteArray* > VM_MAP_STRING_TO_BYTEARRAY;
typedef VM_MAP_STRING_TO_BYTEARRAY::iterator VM_ITER_MAP_STRING_TO_BYTEARRAY;
#endif
/*****************************************************************************/
/* Check-in history */
/*
*$Log: $
*/
/*****************************************************************************/