Removed double carriage-returns
This commit is contained in:
parent
90af2a0339
commit
514aef86f7
|
|
@ -1,155 +1,155 @@
|
|||
#define MEMBUF_THRASH_SIZE 25
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::ClearBuffer
|
||||
// Description : Releases all resources(Memory USed) is locally allocated
|
||||
// Return type : inline void
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline void MemBuffer::ClearBuffer(void)
|
||||
{
|
||||
if(_BufferLocal == true)
|
||||
{
|
||||
if(_Buffer != NULL)
|
||||
delete [] _Buffer;
|
||||
|
||||
_Buffer = NULL;
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::AllocBuffer
|
||||
// Description : Locally allocate a new buffer
|
||||
// Return type : inline void
|
||||
// Argument : int len
|
||||
//////////////////////////////////////////////////////////
|
||||
inline void MemBuffer::AllocBuffer(size_t len)
|
||||
{
|
||||
_Buffer = new char[len];
|
||||
_BufferLocal = true;
|
||||
_BufferLen = len;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::MemBuffer
|
||||
// Description : default constructor
|
||||
// Return type :
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline MemBuffer::MemBuffer(void)
|
||||
{
|
||||
_Buffer = NULL;
|
||||
_BufferLocal = false;
|
||||
_BufferLen = 0;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::MemBuffer
|
||||
// Description : Constructure to locall allocate a buffer
|
||||
// Return type :
|
||||
// Argument : int len
|
||||
//////////////////////////////////////////////////////////
|
||||
inline MemBuffer::MemBuffer(size_t len)
|
||||
{
|
||||
AllocBuffer(len);
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::MemBuffer
|
||||
// Description : Constructure to use an external buffer
|
||||
// Return type :
|
||||
// Argument : char * data
|
||||
// Argument : int len
|
||||
//////////////////////////////////////////////////////////
|
||||
inline MemBuffer::MemBuffer(char * data, size_t len)
|
||||
{
|
||||
_BufferLocal = false;
|
||||
_BufferLen = len;
|
||||
_Buffer = data;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::~MemBuffer
|
||||
// Description : CLean UP a mess on Deletetion
|
||||
// Return type :
|
||||
//////////////////////////////////////////////////////////
|
||||
inline MemBuffer::~MemBuffer()
|
||||
{
|
||||
ClearBuffer();
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::SetBuffer
|
||||
// Description : Assigne a buffer
|
||||
// Return type : inline void
|
||||
// Argument : char * data
|
||||
// Argument : int len
|
||||
//////////////////////////////////////////////////////////
|
||||
inline void MemBuffer::SetBuffer(char * data, size_t len)
|
||||
{
|
||||
if(_BufferLocal == true)
|
||||
ClearBuffer();
|
||||
|
||||
_BufferLocal = false;
|
||||
_BufferLen = len;
|
||||
_Buffer = data;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::GrowBuffer
|
||||
// Description : Grow a buffer is needed to get to a sertion size
|
||||
// No care is made here to preserve convtent unlike a vector of chars
|
||||
//
|
||||
// Return type : inline void
|
||||
// Argument : int len
|
||||
//////////////////////////////////////////////////////////
|
||||
inline void MemBuffer::GrowBuffer(size_t new_len)
|
||||
{
|
||||
if(new_len >= _BufferLen)
|
||||
{
|
||||
size_t len = new_len + MEMBUF_THRASH_SIZE;
|
||||
len = len +len;
|
||||
|
||||
char * tmp = new char[len];
|
||||
|
||||
if(_Buffer != NULL)
|
||||
memcpy(tmp,_Buffer,_BufferLen);
|
||||
|
||||
ClearBuffer();
|
||||
|
||||
_Buffer = tmp;
|
||||
_BufferLocal = true;
|
||||
_BufferLen = len;
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::GetBufferSize
|
||||
// Description : Access to the BUffer Size Information
|
||||
// Return type : inline int
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline size_t MemBuffer::GetBufferSize(void ) const
|
||||
{
|
||||
return _BufferLen;
|
||||
};
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : * MemBuffer::GetBuffer
|
||||
// Description : Access to the actual BUffer
|
||||
// Return type : inline char
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline char * MemBuffer::GetBuffer(void)
|
||||
{
|
||||
return _Buffer;
|
||||
};
|
||||
inline const char * MemBuffer::GetBuffer(void) const
|
||||
{
|
||||
return _Buffer;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::InBufferRange
|
||||
// Description :
|
||||
//
|
||||
// Return type : inline bool
|
||||
// Argument : char * inpos
|
||||
////////////////////////////////////////////////////////////////////
|
||||
inline bool MemBuffer::InBufferRange(char * inpos)
|
||||
{
|
||||
return (inpos >= _Buffer && inpos <= (_Buffer + _BufferLen));
|
||||
}
|
||||
|
||||
#define MEMBUF_THRASH_SIZE 25
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::ClearBuffer
|
||||
// Description : Releases all resources(Memory USed) is locally allocated
|
||||
// Return type : inline void
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline void MemBuffer::ClearBuffer(void)
|
||||
{
|
||||
if(_BufferLocal == true)
|
||||
{
|
||||
if(_Buffer != NULL)
|
||||
delete [] _Buffer;
|
||||
|
||||
_Buffer = NULL;
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::AllocBuffer
|
||||
// Description : Locally allocate a new buffer
|
||||
// Return type : inline void
|
||||
// Argument : int len
|
||||
//////////////////////////////////////////////////////////
|
||||
inline void MemBuffer::AllocBuffer(size_t len)
|
||||
{
|
||||
_Buffer = new char[len];
|
||||
_BufferLocal = true;
|
||||
_BufferLen = len;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::MemBuffer
|
||||
// Description : default constructor
|
||||
// Return type :
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline MemBuffer::MemBuffer(void)
|
||||
{
|
||||
_Buffer = NULL;
|
||||
_BufferLocal = false;
|
||||
_BufferLen = 0;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::MemBuffer
|
||||
// Description : Constructure to locall allocate a buffer
|
||||
// Return type :
|
||||
// Argument : int len
|
||||
//////////////////////////////////////////////////////////
|
||||
inline MemBuffer::MemBuffer(size_t len)
|
||||
{
|
||||
AllocBuffer(len);
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::MemBuffer
|
||||
// Description : Constructure to use an external buffer
|
||||
// Return type :
|
||||
// Argument : char * data
|
||||
// Argument : int len
|
||||
//////////////////////////////////////////////////////////
|
||||
inline MemBuffer::MemBuffer(char * data, size_t len)
|
||||
{
|
||||
_BufferLocal = false;
|
||||
_BufferLen = len;
|
||||
_Buffer = data;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::~MemBuffer
|
||||
// Description : CLean UP a mess on Deletetion
|
||||
// Return type :
|
||||
//////////////////////////////////////////////////////////
|
||||
inline MemBuffer::~MemBuffer()
|
||||
{
|
||||
ClearBuffer();
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::SetBuffer
|
||||
// Description : Assigne a buffer
|
||||
// Return type : inline void
|
||||
// Argument : char * data
|
||||
// Argument : int len
|
||||
//////////////////////////////////////////////////////////
|
||||
inline void MemBuffer::SetBuffer(char * data, size_t len)
|
||||
{
|
||||
if(_BufferLocal == true)
|
||||
ClearBuffer();
|
||||
|
||||
_BufferLocal = false;
|
||||
_BufferLen = len;
|
||||
_Buffer = data;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::GrowBuffer
|
||||
// Description : Grow a buffer is needed to get to a sertion size
|
||||
// No care is made here to preserve convtent unlike a vector of chars
|
||||
//
|
||||
// Return type : inline void
|
||||
// Argument : int len
|
||||
//////////////////////////////////////////////////////////
|
||||
inline void MemBuffer::GrowBuffer(size_t new_len)
|
||||
{
|
||||
if(new_len >= _BufferLen)
|
||||
{
|
||||
size_t len = new_len + MEMBUF_THRASH_SIZE;
|
||||
len = len +len;
|
||||
|
||||
char * tmp = new char[len];
|
||||
|
||||
if(_Buffer != NULL)
|
||||
memcpy(tmp,_Buffer,_BufferLen);
|
||||
|
||||
ClearBuffer();
|
||||
|
||||
_Buffer = tmp;
|
||||
_BufferLocal = true;
|
||||
_BufferLen = len;
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::GetBufferSize
|
||||
// Description : Access to the BUffer Size Information
|
||||
// Return type : inline int
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline size_t MemBuffer::GetBufferSize(void ) const
|
||||
{
|
||||
return _BufferLen;
|
||||
};
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : * MemBuffer::GetBuffer
|
||||
// Description : Access to the actual BUffer
|
||||
// Return type : inline char
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline char * MemBuffer::GetBuffer(void)
|
||||
{
|
||||
return _Buffer;
|
||||
};
|
||||
inline const char * MemBuffer::GetBuffer(void) const
|
||||
{
|
||||
return _Buffer;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : MemBuffer::InBufferRange
|
||||
// Description :
|
||||
//
|
||||
// Return type : inline bool
|
||||
// Argument : char * inpos
|
||||
////////////////////////////////////////////////////////////////////
|
||||
inline bool MemBuffer::InBufferRange(char * inpos)
|
||||
{
|
||||
return (inpos >= _Buffer && inpos <= (_Buffer + _BufferLen));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,186 +1,187 @@
|
|||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::GetMessageHead
|
||||
// Description : This will get a pointer to the fist undelivered data in buffer
|
||||
// Return type : char *
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline char * RingBuffer::GetMessageHead(void)
|
||||
{
|
||||
return _Buffer+_StartPos;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::GetBufferOpen
|
||||
// Description : This will get the first writabe section of the buffer space
|
||||
// Return type :
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline char * RingBuffer::GetBufferOpen(void)
|
||||
{
|
||||
return _Buffer+_EndPos;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::ForceWindowSlide
|
||||
// Description : Will force a compression of data // shift left to start position
|
||||
// Return type : inline void
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline void RingBuffer::ForceWindowSlide(void)
|
||||
{
|
||||
size_t len = AmountBuffered();
|
||||
if(len > 0 && _StartPos != 0) // basic flush left..
|
||||
{
|
||||
memmove(_Buffer,GetMessageHead(),len);
|
||||
_StartPos = 0;
|
||||
_EndPos = len;
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::AmountBuffered
|
||||
// Description : Will report the number of unread chars in buffer
|
||||
// Return type : int
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline size_t RingBuffer::AmountBuffered(void)
|
||||
{
|
||||
return _EndPos - _StartPos;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::BufferAvailabe
|
||||
// Description : Will report amount of data that is contiguas that can be writen at
|
||||
// the location returned by GetBufferOpen
|
||||
// Return type : inline int
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline size_t RingBuffer::BufferAvailabe(void)
|
||||
{
|
||||
return GetBufferSize() - _EndPos;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::ResetContent
|
||||
// Description : Throw away all inread information
|
||||
// Return type : void
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
void RingBuffer::ResetContent(void)
|
||||
{
|
||||
_StartPos = 0;
|
||||
_EndPos = 0;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::RingBuffer
|
||||
// Description :
|
||||
// Return type : inline
|
||||
// Argument : int in_size
|
||||
//////////////////////////////////////////////////////////
|
||||
inline RingBuffer::RingBuffer(size_t in_size) : MemBuffer(in_size)
|
||||
{
|
||||
_EndPos = 0;
|
||||
_StartPos = 0;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::FullCompress
|
||||
// Description : Force a compress of the data
|
||||
// Return type : inline void
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline void RingBuffer::FullCompress(void)
|
||||
{
|
||||
if(_StartPos == _EndPos)
|
||||
{
|
||||
_StartPos = 0;
|
||||
_EndPos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ForceWindowSlide();
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::Compress
|
||||
// Description : Try and do a intelegent compress of the data space
|
||||
// the algorithem is really stupid right know.. just say if i have
|
||||
// read past 1/2 my space do a compress...Im open for sugestions
|
||||
//
|
||||
//
|
||||
// Return type : inline void
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline void RingBuffer::Compress(void)
|
||||
{
|
||||
if(_StartPos == _EndPos)
|
||||
{
|
||||
_StartPos = 0;
|
||||
_EndPos = 0;
|
||||
}
|
||||
else if(_StartPos >= GetBufferSize() / 2)
|
||||
{
|
||||
ForceWindowSlide();
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::Put
|
||||
// Description : Adds Data to a ring Buffer
|
||||
// Will do a compress if needed so pointers suplied by Get Call are no longer valide
|
||||
//
|
||||
// Return type : inline bool
|
||||
// Argument : char * data
|
||||
// Argument : int len
|
||||
//////////////////////////////////////////////////////////
|
||||
inline bool RingBuffer::Put(const char * data, size_t len)
|
||||
{
|
||||
bool answer = false;
|
||||
|
||||
if(len > BufferAvailabe() )
|
||||
Compress();
|
||||
|
||||
if(len <= BufferAvailabe() )
|
||||
{
|
||||
memcpy(GetBufferOpen(),data,len);
|
||||
_EndPos += len;
|
||||
answer = true;
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::PutFast
|
||||
// Description :
|
||||
//
|
||||
// Return type : inline bool
|
||||
// Argument : const char * data
|
||||
// Argument : int len
|
||||
////////////////////////////////////////////////////////////////////
|
||||
inline bool RingBuffer::PutFast(const char * data, size_t len)
|
||||
{
|
||||
// no checking be carefull
|
||||
memcpy(GetBufferOpen(),data,len); // should i be using memcopy..
|
||||
_EndPos += len;
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::Get
|
||||
// Description : will copy the data ..
|
||||
// false indicates not enogh data to read .. sorry...
|
||||
//
|
||||
// Return type : inline bool
|
||||
// Argument : char * data
|
||||
// Argument : int len
|
||||
//////////////////////////////////////////////////////////
|
||||
inline bool RingBuffer::Get(char * data, size_t len)
|
||||
{
|
||||
bool answer = false;
|
||||
|
||||
if(len <= AmountBuffered() )
|
||||
{
|
||||
memcpy(data,GetMessageHead(),len);
|
||||
_StartPos += len;
|
||||
Compress();
|
||||
answer = true;
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::GetMessageHead
|
||||
// Description : This will get a pointer to the fist undelivered data in buffer
|
||||
// Return type : char *
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline char * RingBuffer::GetMessageHead(void)
|
||||
{
|
||||
return _Buffer+_StartPos;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::GetBufferOpen
|
||||
// Description : This will get the first writabe section of the buffer space
|
||||
// Return type :
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline char * RingBuffer::GetBufferOpen(void)
|
||||
{
|
||||
return _Buffer+_EndPos;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::ForceWindowSlide
|
||||
// Description : Will force a compression of data // shift left to start position
|
||||
// Return type : inline void
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline void RingBuffer::ForceWindowSlide(void)
|
||||
{
|
||||
size_t len = AmountBuffered();
|
||||
if(len > 0 && _StartPos != 0) // basic flush left..
|
||||
{
|
||||
memmove(_Buffer,GetMessageHead(),len);
|
||||
_StartPos = 0;
|
||||
_EndPos = len;
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::AmountBuffered
|
||||
// Description : Will report the number of unread chars in buffer
|
||||
// Return type : int
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline size_t RingBuffer::AmountBuffered(void)
|
||||
{
|
||||
return _EndPos - _StartPos;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::BufferAvailabe
|
||||
// Description : Will report amount of data that is contiguas that can be writen at
|
||||
// the location returned by GetBufferOpen
|
||||
// Return type : inline int
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline size_t RingBuffer::BufferAvailabe(void)
|
||||
{
|
||||
return GetBufferSize() - _EndPos;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::ResetContent
|
||||
// Description : Throw away all inread information
|
||||
// Return type : void
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
void RingBuffer::ResetContent(void)
|
||||
{
|
||||
_StartPos = 0;
|
||||
_EndPos = 0;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::RingBuffer
|
||||
// Description :
|
||||
// Return type : inline
|
||||
// Argument : int in_size
|
||||
//////////////////////////////////////////////////////////
|
||||
inline RingBuffer::RingBuffer(size_t in_size) : MemBuffer(in_size)
|
||||
{
|
||||
_EndPos = 0;
|
||||
_StartPos = 0;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::FullCompress
|
||||
// Description : Force a compress of the data
|
||||
// Return type : inline void
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline void RingBuffer::FullCompress(void)
|
||||
{
|
||||
if(_StartPos == _EndPos)
|
||||
{
|
||||
_StartPos = 0;
|
||||
_EndPos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ForceWindowSlide();
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::Compress
|
||||
// Description : Try and do a intelegent compress of the data space
|
||||
// the algorithem is really stupid right know.. just say if i have
|
||||
// read past 1/2 my space do a compress...Im open for sugestions
|
||||
//
|
||||
//
|
||||
// Return type : inline void
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline void RingBuffer::Compress(void)
|
||||
{
|
||||
if(_StartPos == _EndPos)
|
||||
{
|
||||
_StartPos = 0;
|
||||
_EndPos = 0;
|
||||
}
|
||||
else if(_StartPos >= GetBufferSize() / 2)
|
||||
{
|
||||
ForceWindowSlide();
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::Put
|
||||
// Description : Adds Data to a ring Buffer
|
||||
// Will do a compress if needed so pointers suplied by Get Call are no longer valide
|
||||
//
|
||||
// Return type : inline bool
|
||||
// Argument : char * data
|
||||
// Argument : int len
|
||||
//////////////////////////////////////////////////////////
|
||||
inline bool RingBuffer::Put(const char * data, size_t len)
|
||||
{
|
||||
bool answer = false;
|
||||
|
||||
if(len > BufferAvailabe() )
|
||||
Compress();
|
||||
|
||||
if(len <= BufferAvailabe() )
|
||||
{
|
||||
memcpy(GetBufferOpen(),data,len);
|
||||
_EndPos += len;
|
||||
answer = true;
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::PutFast
|
||||
// Description :
|
||||
//
|
||||
// Return type : inline bool
|
||||
// Argument : const char * data
|
||||
// Argument : int len
|
||||
////////////////////////////////////////////////////////////////////
|
||||
inline bool RingBuffer::PutFast(const char * data, size_t len)
|
||||
{
|
||||
// no checking be carefull
|
||||
memcpy(GetBufferOpen(),data,len); // should i be using memcopy..
|
||||
_EndPos += len;
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer::Get
|
||||
// Description : will copy the data ..
|
||||
// false indicates not enogh data to read .. sorry...
|
||||
//
|
||||
// Return type : inline bool
|
||||
// Argument : char * data
|
||||
// Argument : int len
|
||||
//////////////////////////////////////////////////////////
|
||||
inline bool RingBuffer::Get(char * data, size_t len)
|
||||
{
|
||||
bool answer = false;
|
||||
|
||||
if(len <= AmountBuffered() )
|
||||
{
|
||||
memcpy(data,GetMessageHead(),len);
|
||||
_StartPos += len;
|
||||
Compress();
|
||||
answer = true;
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue