C++/Tree Mapping Runtime Library
Public Types | List of all members
buffer< C > Class Template Reference

Simple binary buffer abstraction. More...

#include <buffer.hxx>

Inheritance diagram for buffer< C >:
base64_binary< C, B > hex_binary< C, B >

Public Types

typedef std::size_t size_t
 Size type.
 

Constructors

 buffer (size_t size=0)
 Allocate a buffer of the specified size.
 
 buffer (size_t size, size_t capacity)
 Allocate a buffer of the specified size and capacity.
 
 buffer (const void *data, size_t size)
 Allocate a buffer of the specified size and copy the data.
 
 buffer (const void *data, size_t size, size_t capacity)
 Allocate a buffer of the specified size and capacity and copy the data.
 
 buffer (void *data, size_t size, size_t capacity, bool assume_ownership)
 Reuse an existing buffer.
 
 buffer (const buffer &x)
 Copy constructor.
 
bufferoperator= (const buffer &x)
 Copy assignment operator.
 
size_t capacity () const
 Get buffer's capacity.
 
bool capacity (size_t c)
 Set buffer's capacity.
 
size_t size () const
 Get buffer's size.
 
bool size (size_t s)
 Set buffer's size.
 
const char * data () const
 Get the underlying memory region.
 
char * data ()
 Get the underlying memory region.
 
const char * begin () const
 Get the beginning of the underlying memory region.
 
char * begin ()
 Get the beginning of the underlying memory region.
 
const char * end () const
 Get the end of the underlying memory region.
 
char * end ()
 Get the end of the underlying memory region.
 
void swap (buffer &x)
 Swap data with another buffer.
 

Detailed Description

template<typename C>
class xsd::cxx::tree::buffer< C >

Simple binary buffer abstraction.

The buffer class manages a continuous binary buffer. The base concepts are data (actual memory region), size (the portion of the buffer that contains useful information), and capacity (the actual size of the underlying memory region). The bounds exception is thrown from the constructors and modifier functions if the (size <= capacity) constraint is violated.

Note that the template parameter is only used to instantiate exception types. The underlying buffer type is always char.

Constructor & Destructor Documentation

◆ buffer() [1/6]

template<typename C >
buffer ( size_t  size = 0)
explicit

Allocate a buffer of the specified size.

The resulting buffer has the same size and capacity.

Parameters
sizeA buffer size in bytes.

◆ buffer() [2/6]

template<typename C >
buffer ( size_t  size,
size_t  capacity 
)

Allocate a buffer of the specified size and capacity.

Parameters
sizeA buffer size in bytes.
capacityA buffer capacity in bytes.
Exceptions
boundsIf size exceeds capacity

◆ buffer() [3/6]

template<typename C >
buffer ( const void *  data,
size_t  size 
)

Allocate a buffer of the specified size and copy the data.

The resulting buffer has the same size and capacity with size bytes copied from data.

Parameters
dataA buffer to copy the data from.
sizeA buffer size in bytes.

◆ buffer() [4/6]

template<typename C >
buffer ( const void *  data,
size_t  size,
size_t  capacity 
)

Allocate a buffer of the specified size and capacity and copy the data.

size bytes are copied from data to the resulting buffer.

Parameters
dataA buffer to copy the data from.
sizeA buffer size in bytes.
capacityA buffer capacity in bytes.
Exceptions
boundsIf size exceeds capacity

◆ buffer() [5/6]

template<typename C >
buffer ( void *  data,
size_t  size,
size_t  capacity,
bool  assume_ownership 
)

Reuse an existing buffer.

If the assume_ownership argument is true, the buffer will assume ownership of data and will release the memory by calling operator delete().

Parameters
dataA buffer to reuse.
sizeA buffer size in bytes.
capacityA buffer capacity in bytes.
assume_ownershipA boolean value indication whether to assume ownership.
Exceptions
boundsIf size exceeds capacity

◆ buffer() [6/6]

template<typename C >
buffer ( const buffer< C > &  x)

Copy constructor.

The copy constructor performs a deep copy of the underlying memory buffer.

Parameters
xAn instance to make a copy of.

Member Function Documentation

◆ operator=()

template<typename C >
buffer & operator= ( const buffer< C > &  x)

Copy assignment operator.

The copy assignment operator changes the buffer's capacity to x.capacity() and copies x.size() bytes from x.

Parameters
xAn instance to assign.
Returns
A reference to the instance.

◆ capacity() [1/2]

template<typename C >
size_t capacity ( ) const
inline

Get buffer's capacity.

Returns
A number of bytes that the buffer can hold without reallocation.

Referenced by buffer< C >::capacity(), and buffer< C >::size().

◆ capacity() [2/2]

template<typename C >
bool capacity ( size_t  c)
inline

Set buffer's capacity.

Parameters
cThe new capacity in bytes.
Returns
True if the underlying buffer has moved, false otherwise.

References buffer< C >::capacity().

◆ size() [1/2]

template<typename C >
size_t size ( ) const
inline

Get buffer's size.

Returns
A number of bytes that the buffer holds.

Referenced by xsd::cxx::tree::operator==().

◆ size() [2/2]

template<typename C >
bool size ( size_t  s)
inline

Set buffer's size.

Parameters
sThe new size in bytes.
Returns
True if the underlying buffer has moved, false otherwise.

References buffer< C >::capacity().

◆ data() [1/2]

template<typename C >
const char * data ( ) const
inline

Get the underlying memory region.

Returns
A constant pointer to the underlying memory region.

Referenced by xsd::cxx::tree::operator==().

◆ data() [2/2]

template<typename C >
char * data ( )
inline

Get the underlying memory region.

Returns
A pointer to the underlying memory region.

◆ begin() [1/2]

template<typename C >
const char * begin ( ) const
inline

Get the beginning of the underlying memory region.

Returns
A constant pointer to the first byte of the underlying memory region.

◆ begin() [2/2]

template<typename C >
char * begin ( )
inline

Get the beginning of the underlying memory region.

Returns
A pointer to the first byte of the underlying memory region.

◆ end() [1/2]

template<typename C >
const char * end ( ) const
inline

Get the end of the underlying memory region.

Returns
A constant pointer to the one past last byte of the underlying memory region (that is begin() + size() ).

◆ end() [2/2]

template<typename C >
char * end ( )
inline

Get the end of the underlying memory region.

Returns
A pointer to the one past last byte of the underlying memory region (that is begin() + size() ).

◆ swap()

template<typename C >
void swap ( buffer< C > &  x)

Swap data with another buffer.

Parameters
xA buffer to swap with.

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

Copyright © 2005-2023 Code Synthesis.