Evo C++ Library v0.5.1
Public Member Functions | Public Attributes | List of all members
RawBuffer Struct Reference

#include <evo/impl/rawbuffer.h>

Inheritance diagram for RawBuffer:
Inheritance graph
[legend]

Detailed Description

Simple raw memory buffer.

Public Member Functions

 RawBuffer ()
 Constructor. More...
 
 RawBuffer (ulong size)
 Constructor. More...
 
 ~RawBuffer ()
 Destructor. More...
 
ulong avail () const
 Get size available. More...
 
ulong avail (ulong checksize) const
 Get size up to size available. More...
 
RawBufferclear ()
 Clear buffer. More...
 
void flush (ulong &offset)
 Flush data already read from buffer using offset. More...
 
ulong insert (ulong index, ulong size=1)
 Make room to insert items. More...
 
RawBufferminsize (ulong min)
 Resize buffer if smaller than minimum size. More...
 
ulong read (ulong &offset, char *buf, ulong readsize)
 Read from buffer using offset. More...
 
RawBufferref (char *data, ulong size, ulong used=0)
 Reference another buffer. More...
 
RawBufferremove (ulong index, ulong size=1)
 Remove items. More...
 
RawBufferreset ()
 Reset to empty state without a buffer. More...
 
RawBufferresize (ulong newsize)
 Resize buffer. More...
 
ulong write (const char *buf, ulong writesize)
 Write at end of buffer. More...
 
ulong write (char ch, ulong count=1)
 Write character at end of buffer. More...
 

Public Attributes

char * data
 Buffer data pointer, NULL if empty (size=0) More...
 
bool owned
 Whether this owns the buffer and must free it. More...
 
ulong size
 Buffer size (capacity) in bytes – do not modify, use: resize(), minsize(), reset(), ref() More...
 
ulong used
 Buffer size in use in bytes. More...
 

Constructor & Destructor Documentation

◆ RawBuffer() [1/2]

RawBuffer ( )
inline

Constructor.

◆ RawBuffer() [2/2]

RawBuffer ( ulong  size)
inline

Constructor.

◆ ~RawBuffer()

~RawBuffer ( )
inline

Destructor.

Member Function Documentation

◆ avail() [1/2]

ulong avail ( ) const
inline

Get size available.

Returns
Size available at end (size - used)

◆ avail() [2/2]

ulong avail ( ulong  checksize) const
inline

Get size up to size available.

Parameters
checksizeSize to check against size available
Returns
Size available at end (size - used) or checksize, whichever is smaller

◆ clear()

RawBuffer& clear ( )
inline

Clear buffer.

  • This sets 'used' to 0
Returns
This

◆ flush()

void flush ( ulong &  offset)
inline

Flush data already read from buffer using offset.

  • This moves data at offset to beginning of buffer to make room for more data
Parameters
offsetOffset to use and update, will be set to 0 [in/out]

◆ insert()

ulong insert ( ulong  index,
ulong  size = 1 
)
inline

Make room to insert items.

  • This shifts items over to make room and updates 'used' but doesn't actually insert
Parameters
indexInsert index, END to append
sizeInsert size in bytes, must be postive
Returns
Actual insert index

◆ minsize()

RawBuffer& minsize ( ulong  min)
inline

Resize buffer if smaller than minimum size.

Parameters
minMinimum size in bytes
Returns
This

◆ read()

ulong read ( ulong &  offset,
char *  buf,
ulong  readsize 
)
inline

Read from buffer using offset.

  • This copies from offset (data+offset) and increments offset
Parameters
offsetOffset to use and update [in/out]
bufBuffer to read/copy to
readsizeRead size in bytes, reduced if too large
Returns
Actual size read/copied, may be less than readsize if end reached (offset=used)

◆ ref()

RawBuffer& ref ( char *  data,
ulong  size,
ulong  used = 0 
)
inline

Reference another buffer.

  • Use to access and/or modify another buffer
  • This will not take ownership of the buffer (will not free it)
Parameters
dataBuffer data pointer, must not be NULL
sizeBuffer size (capacity) in bytes, must be > 0
usedBuffer size in use in bytes, must be <= size
Returns
This

◆ remove()

RawBuffer& remove ( ulong  index,
ulong  size = 1 
)
inline

Remove items.

  • This removes items and updates 'used'
Parameters
indexInsert index
sizeRemove size in bytes
Returns
This

◆ reset()

RawBuffer& reset ( )
inline

Reset to empty state without a buffer.

  • This is useful for clearing a reference to another buffer
Returns
This

◆ resize()

RawBuffer& resize ( ulong  newsize)
inline

Resize buffer.

  • This updates 'used' if the new size truncates items
  • If newsize is the same as current size this does nothing
  • If newsize is 0 this will free the buffer (if owned) and reset the data
  • If newsize is positive this will: allocate a new buffer, copy existing data if needed (up to 'used'), and free the old buffer (if owned)
Parameters
newsizeNew size in bytes, 0 to free
Returns
This

◆ write() [1/2]

ulong write ( const char *  buf,
ulong  writesize 
)
inline

Write at end of buffer.

  • This appends to buffer and increments used
  • If write is too big for buffer it will be truncated to fit
Parameters
bufBuffer to write from
writesizeWrite size in bytes, reduced if too large
Returns
Actual size written, may be less than writesize if buffer is full

◆ write() [2/2]

ulong write ( char  ch,
ulong  count = 1 
)
inline

Write character at end of buffer.

  • This appends to buffer and increments used
  • If count is too big for buffer it will be truncated to fit
Parameters
chCharacter to write
countCharacter repeat count, reduced if too large
Returns
Actual size written, may be less than count if buffer is full

Member Data Documentation

◆ data

char* data

Buffer data pointer, NULL if empty (size=0)

◆ owned

bool owned

Whether this owns the buffer and must free it.

◆ size

ulong size

Buffer size (capacity) in bytes – do not modify, use: resize(), minsize(), reset(), ref()

◆ used

ulong used

Buffer size in use in bytes.


The documentation for this struct was generated from the following file: