mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2024-12-23 01:59:43 +08:00
108 lines
2.3 KiB
C
108 lines
2.3 KiB
C
|
//====== Copyright <20> 1996-2004, Valve Corporation, All rights reserved. =======
|
|||
|
//
|
|||
|
// Purpose:
|
|||
|
//
|
|||
|
//=============================================================================
|
|||
|
|
|||
|
#ifndef UTLBINARYBLOCK_H
|
|||
|
#define UTLBINARYBLOCK_H
|
|||
|
#ifdef _WIN32
|
|||
|
#pragma once
|
|||
|
#endif
|
|||
|
|
|||
|
#include "tier1/utlmemory.h"
|
|||
|
#include "tier1/strtools.h"
|
|||
|
#include "limits.h"
|
|||
|
|
|||
|
//-----------------------------------------------------------------------------
|
|||
|
// Base class, containing simple memory management
|
|||
|
//-----------------------------------------------------------------------------
|
|||
|
class CUtlBinaryBlock
|
|||
|
{
|
|||
|
public:
|
|||
|
CUtlBinaryBlock( int growSize = 0, int initSize = 0 );
|
|||
|
|
|||
|
// NOTE: nInitialLength indicates how much of the buffer starts full
|
|||
|
CUtlBinaryBlock( void* pMemory, int nSizeInBytes, int nInitialLength );
|
|||
|
CUtlBinaryBlock( const void* pMemory, int nSizeInBytes );
|
|||
|
CUtlBinaryBlock( const CUtlBinaryBlock& src );
|
|||
|
|
|||
|
void Get( void *pValue, int nMaxLen ) const;
|
|||
|
void Set( const void *pValue, int nLen );
|
|||
|
const void *Get( ) const;
|
|||
|
void *Get( );
|
|||
|
|
|||
|
unsigned char& operator[]( int i );
|
|||
|
const unsigned char& operator[]( int i ) const;
|
|||
|
|
|||
|
int Length() const;
|
|||
|
void SetLength( int nLength ); // Undefined memory will result
|
|||
|
bool IsEmpty() const;
|
|||
|
void Clear();
|
|||
|
void Purge();
|
|||
|
|
|||
|
bool IsReadOnly() const;
|
|||
|
|
|||
|
CUtlBinaryBlock &operator=( const CUtlBinaryBlock &src );
|
|||
|
|
|||
|
// Test for equality
|
|||
|
bool operator==( const CUtlBinaryBlock &src ) const;
|
|||
|
|
|||
|
private:
|
|||
|
CUtlMemory<unsigned char> m_Memory;
|
|||
|
int m_nActualLength;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
//-----------------------------------------------------------------------------
|
|||
|
// class inlines
|
|||
|
//-----------------------------------------------------------------------------
|
|||
|
inline const void *CUtlBinaryBlock::Get( ) const
|
|||
|
{
|
|||
|
return m_Memory.Base();
|
|||
|
}
|
|||
|
|
|||
|
inline void *CUtlBinaryBlock::Get( )
|
|||
|
{
|
|||
|
return m_Memory.Base();
|
|||
|
}
|
|||
|
|
|||
|
inline int CUtlBinaryBlock::Length() const
|
|||
|
{
|
|||
|
return m_nActualLength;
|
|||
|
}
|
|||
|
|
|||
|
inline unsigned char& CUtlBinaryBlock::operator[]( int i )
|
|||
|
{
|
|||
|
return m_Memory[i];
|
|||
|
}
|
|||
|
|
|||
|
inline const unsigned char& CUtlBinaryBlock::operator[]( int i ) const
|
|||
|
{
|
|||
|
return m_Memory[i];
|
|||
|
}
|
|||
|
|
|||
|
inline bool CUtlBinaryBlock::IsReadOnly() const
|
|||
|
{
|
|||
|
return m_Memory.IsReadOnly();
|
|||
|
}
|
|||
|
|
|||
|
inline bool CUtlBinaryBlock::IsEmpty() const
|
|||
|
{
|
|||
|
return Length() == 0;
|
|||
|
}
|
|||
|
|
|||
|
inline void CUtlBinaryBlock::Clear()
|
|||
|
{
|
|||
|
SetLength( 0 );
|
|||
|
}
|
|||
|
|
|||
|
inline void CUtlBinaryBlock::Purge()
|
|||
|
{
|
|||
|
SetLength( 0 );
|
|||
|
m_Memory.Purge();
|
|||
|
}
|
|||
|
|
|||
|
#endif // UTLBINARYBLOCK_H
|
|||
|
|