OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::ConstBufferType< T > Class Template Reference

Immutable buffer with double ended access and adjustable free space at both ends. More...

#include <buffer.hpp>

Inheritance diagram for openvpn::ConstBufferType< T >:
[legend]

Public Types

typedef T value_type
 
typedef T * type
 
typedef const T * const_type
 
typedef std::remove_const_t< T > NCT
 

Public Member Functions

 ConstBufferType ()
 Default constructor for ConstBufferType.
 
 ConstBufferType (void *data, const size_t size, const bool filled)
 Constructs a ConstBufferType from a void pointer and size.
 
template<typename U = T, typename std::enable_if_t<!std::is_const_v< U >, int > = 0>
 ConstBufferType (const void *data, const size_t size, const bool filled)
 Constructs a ConstBufferType from a const void pointer and size. This constructor is disabled when T is already const.
 
 ConstBufferType (T *data, const size_t size, const bool filled)
 Constructs a ConstBufferType from a pointer to T and size.
 
template<typename U = T, typename std::enable_if_t<!std::is_const_v< U >, int > = 0>
 ConstBufferType (const U *data, const size_t size, const bool filled)
 Constructs a ConstBufferType from a const pointer to T and size. This constructor is disabled when T is already const.
 
virtual ~ConstBufferType ()=default
 Needed because this class has virtual member functions and is intended as a base class.
 
const auto & operator[] (const size_t index) const
 Const indexing operator for ConstBufferType.
 
auto & operator[] (const size_t index)
 Non-const indexing operator for ConstBufferType.
 
void init_headroom (const size_t headroom)
 Initializes the headroom (offset) of the buffer.
 
void reset_offset (const size_t offset)
 Resets the offset of the buffer.
 
void reset_size ()
 Resets the size of the buffer to zero.
 
void reset_content ()
 Resets the content of the buffer.
 
const T * c_str () const
 Returns a const pointer to the null-terminated string representation of the buffer.
 
size_t length () const
 Returns the length of the buffer.
 
const T * c_data () const
 Returns a const pointer to the start of the buffer.
 
const T * c_data_end () const
 Returns a const pointer to the end of the buffer.
 
const T * c_data_raw () const
 Returns a const pointer to the start of the raw data in the buffer.
 
size_t capacity () const
 Returns the capacity (raw size) of the allocated buffer in T objects.
 
size_t offset () const
 Returns the current offset (headroom) into the buffer.
 
bool defined () const
 Returns true if the buffer is not empty.
 
bool allocated () const
 Returns true if the data memory is defined (allocated).
 
bool empty () const
 Returns true if the buffer is empty.
 
size_t size () const
 Returns the size of the buffer in T objects.
 
pop_back ()
 Removes and returns the last element from the buffer.
 
pop_front ()
 Removes and returns the first element from the buffer.
 
front () const
 Returns the first element of the buffer.
 
back () const
 Returns the last element of the buffer.
 
void advance (const size_t delta)
 Advances the buffer by the specified delta.
 
bool contains_null () const
 Returns true if the buffer contains a null character.
 
bool is_zeroed () const
 Returns true if the buffer is zeroed (all elements are zero).
 
openvpn_io::const_buffer const_buffer () const
 Return an openvpn_io::const_buffer object used by asio write methods.
 
openvpn_io::const_buffer const_buffer_clamp () const
 Return a clamped version of const_buffer().
 
openvpn_io::const_buffer const_buffer_limit (const size_t limit) const
 Return a const_buffer object with a specified size limit.
 
void read (NCT *data, const size_t size)
 Read data from the buffer into the specified memory location.
 
void read (void *data, const size_t size)
 Read data from the buffer into the specified memory location.
 
auto * read_alloc (const size_t size)
 Allocate memory and read data from the buffer into the allocated memory.
 
auto read_alloc_buf (const size_t size)
 Allocate memory and read data from the buffer into the allocated memory.
 
size_t max_size () const
 Return the maximum allowable size value in T objects given the current offset (without considering resize).
 
void set_size (const size_t size)
 After an external method, operating on the array as a mutable unsigned char buffer, has written data to the array, use this method to set the array length in terms of T objects.
 
void inc_size (const size_t delta)
 Increment the size of the array (usually used in a similar context to set_size such as after mutable_buffer_append).
 
ConstBufferType range (size_t offset, size_t len) const
 Get a range of the buffer as a ConstBufferType object.
 
const T * c_index (const size_t index) const
 Get a const pointer to the element at the specified index in the array.
 
bool operator== (const ConstBufferType &other) const
 Equality operator to compare this buffer with another ConstBufferType object.
 
bool operator!= (const ConstBufferType &other) const
 Inequality operator to compare this buffer with another ConstBufferType object.
 

Protected Member Functions

void reserve (const size_t n)
 Reserve additional memory for the buffer.
 
T * data ()
 Get a mutable pointer to the start of the array.
 
T * data_end ()
 Get a mutable pointer to the end of the array.
 
T * data_raw ()
 Get a mutable pointer to the start of the raw data.
 
size_t remaining (const size_t tailroom=0) const
 Return the number of additional T objects that can be added before capacity is reached (without considering resize).
 
size_t max_size_tailroom (const size_t tailroom) const
 Return the maximum allowable size value in T objects, taking into account the specified tailroom.
 
void push_back (const T &value)
 Append a T object to the end of the array, resizing the array if necessary.
 
void push_front (const T &value)
 Append a T object to the array, with possible resize.
 
void set_trailer (const T &value)
 Place a T object after the last object in the array, with possible resize to contain it. However, it doesn't actually change the size of the array to reflect the added object. Useful for maintaining null-terminated strings.
 
void null_terminate ()
 Null-terminate the array.
 
T * index (const size_t index)
 Get a mutable index into the array.
 
openvpn_io::mutable_buffer mutable_buffer (const size_t tailroom=0)
 Return an openvpn_io::mutable_buffer object used by asio read methods, starting from data().
 
openvpn_io::mutable_buffer mutable_buffer_append (const size_t tailroom=0)
 Return an openvpn_io::mutable_buffer object used by asio read methods, starting from data_end().
 
openvpn_io::mutable_buffer mutable_buffer_clamp (const size_t tailroom=0)
 Clamped version of mutable_buffer().
 
openvpn_io::mutable_buffer mutable_buffer_append_clamp (const size_t tailroom=0)
 Clamped version of mutable_buffer_append().
 
void realign (size_t headroom)
 Realign the buffer with the specified headroom.
 
void write (const T *data, const size_t size)
 Write data to the buffer.
 
void write (const void *data, const size_t size)
 Write data to the buffer.
 
void prepend (const T *data, const size_t size)
 Prepend data to the buffer.
 
void prepend (const void *data, const size_t size)
 Prepend data to the buffer.
 
T * write_alloc (const size_t size)
 Allocate space for writing data to the buffer.
 
T * prepend_alloc (const size_t size)
 Allocate space for prepending data to the buffer.
 
void reset (const size_t min_capacity, const unsigned int flags)
 Reset the buffer with the specified minimum capacity and flags.
 
void reset (const size_t headroom, const size_t min_capacity, const unsigned int flags)
 Reset the buffer with the specified headroom, minimum capacity, and flags.
 
template<typename B >
void append (const B &other)
 Append data from another buffer to this buffer.
 
template<typename T_ >
void swap (ConstBufferType< T_ > &other)
 Swap the contents of this buffer with another buffer.
 
void buffer_full_error (const size_t newcap, const bool allocated) const
 Throw an exception when the buffer is full.
 
virtual void reset_impl (const size_t min_capacity, const unsigned int flags)
 Called when the reset method needs to expand the buffer size.
 
virtual void resize (const size_t new_capacity)
 Derived classes can implement buffer growing semantics by overloading this method. In the default implementation, buffers are non-growable, so an exception is thrown.
 
 ConstBufferType (T *data, const size_t offset, const size_t size, const size_t capacity)
 Construct a ConstBufferType object.
 
template<typename U = T, typename std::enable_if_t<!std::is_const_v< U >, int > = 0>
 ConstBufferType (const U *data, const size_t offset, const size_t size, const size_t capacity)
 Construct a ConstBufferType object from a const U* pointer. This constructor is disabled when T is already const.
 

Private Attributes

T * data_
 
size_t offset_
 
size_t size_
 
size_t capacity_
 

Detailed Description

template<typename T>
class openvpn::ConstBufferType< T >

Immutable buffer with double ended access and adjustable free space at both ends.

This template implements a buffer with double ended access and adjustable free space at both ends. It's generalized for type T but is only really fully functional with various types that can represent strings, as it does have string interoperation helpers. It is particularly useful for use as a building block in implementing protocols such as wire protocols for a network.

Data layout:

 data_ ->|--------------|------------------ Buffered Data --------------------|--------------|
         ^-- offset_ ---^                                                     ^              ^
         ^              ^----- size_ -----------------------------------------^              ^
         ^                                                                                   ^
         ^-- capacity_ ----------------------------------------------------------------------^

Definition at line 228 of file buffer.hpp.

Member Typedef Documentation

◆ const_type

template<typename T >
typedef const T* openvpn::ConstBufferType< T >::const_type

Definition at line 233 of file buffer.hpp.

◆ NCT

template<typename T >
typedef std::remove_const_t<T> openvpn::ConstBufferType< T >::NCT

Definition at line 234 of file buffer.hpp.

◆ type

template<typename T >
typedef T* openvpn::ConstBufferType< T >::type

Definition at line 232 of file buffer.hpp.

◆ value_type

template<typename T >
typedef T openvpn::ConstBufferType< T >::value_type

Definition at line 231 of file buffer.hpp.

Constructor & Destructor Documentation

◆ ConstBufferType() [1/7]

template<typename T >
openvpn::ConstBufferType< T >::ConstBufferType ( )

Default constructor for ConstBufferType.

Definition at line 1085 of file buffer.hpp.

◆ ConstBufferType() [2/7]

template<typename T >
openvpn::ConstBufferType< T >::ConstBufferType ( void *  data,
const size_t  size,
const bool  filled 
)

Constructs a ConstBufferType from a void pointer and size.

Parameters
dataPointer to the data.
sizeSize of the data in bytes.
filledIndicates whether the buffer is filled or not.
Note
The term filled indicates that the memory pointed to contains desired data and that the size of the buffer should be set equal to its capacity, as opposed to this being a buffer of available memory with capacity 'size' and size zero. See layout diagram for more insight.

Definition at line 1094 of file buffer.hpp.

◆ ConstBufferType() [3/7]

template<typename T >
template<typename U , typename std::enable_if_t<!std::is_const_v< U >, int > >
openvpn::ConstBufferType< T >::ConstBufferType ( const void *  data,
const size_t  size,
const bool  filled 
)

Constructs a ConstBufferType from a const void pointer and size. This constructor is disabled when T is already const.

Parameters
dataPointer to the const data.
sizeSize of the data in bytes.
filledIndicates whether the buffer is filled or not.

Definition at line 1099 of file buffer.hpp.

◆ ConstBufferType() [4/7]

template<typename T >
openvpn::ConstBufferType< T >::ConstBufferType ( T *  data,
const size_t  size,
const bool  filled 
)

Constructs a ConstBufferType from a pointer to T and size.

Parameters
dataPointer to the data.
sizeSize of the data in bytes.
filledIndicates whether the buffer is filled or not.

Definition at line 1103 of file buffer.hpp.

◆ ConstBufferType() [5/7]

template<typename T >
template<typename U , typename std::enable_if_t<!std::is_const_v< U >, int > >
openvpn::ConstBufferType< T >::ConstBufferType ( const U *  data,
const size_t  size,
const bool  filled 
)

Constructs a ConstBufferType from a const pointer to T and size. This constructor is disabled when T is already const.

Parameters
dataPointer to the const data.
sizeSize of the data in bytes.
filledIndicates whether the buffer is filled or not.

Definition at line 1111 of file buffer.hpp.

◆ ~ConstBufferType()

template<typename T >
virtual openvpn::ConstBufferType< T >::~ConstBufferType ( )
virtualdefault

Needed because this class has virtual member functions and is intended as a base class.

◆ ConstBufferType() [6/7]

template<typename T >
openvpn::ConstBufferType< T >::ConstBufferType ( T *  data,
const size_t  offset,
const size_t  size,
const size_t  capacity 
)
protected

Construct a ConstBufferType object.

Parameters
dataA pointer to the data buffer.
offsetThe offset from data where the T array starts.
sizeThe number of T objects in the array.
capacityThe maximum number of T objects that can be stored in the buffer.

Definition at line 1636 of file buffer.hpp.

◆ ConstBufferType() [7/7]

template<typename T >
template<typename U , typename std::enable_if_t<!std::is_const_v< U >, int > >
openvpn::ConstBufferType< T >::ConstBufferType ( const U *  data,
const size_t  offset,
const size_t  size,
const size_t  capacity 
)
protected

Construct a ConstBufferType object from a const U* pointer. This constructor is disabled when T is already const.

Template Parameters
UThe type of the data pointer.
Parameters
dataA pointer to the data buffer.
offsetThe offset from data where the T array starts.
sizeThe number of T objects in the array.
capacityThe maximum number of T objects that can be stored in the buffer.

Definition at line 1641 of file buffer.hpp.

Member Function Documentation

◆ advance()

template<typename T >
void openvpn::ConstBufferType< T >::advance ( const size_t  delta)

Advances the buffer by the specified delta.

Parameters
deltaThe amount to advance the buffer.

Definition at line 1260 of file buffer.hpp.

Here is the caller graph for this function:

◆ allocated()

template<typename T >
bool openvpn::ConstBufferType< T >::allocated ( ) const

Returns true if the data memory is defined (allocated).

Returns
True if the data memory is defined, false otherwise.

Definition at line 1213 of file buffer.hpp.

Here is the caller graph for this function:

◆ append()

template<typename T >
template<typename B >
void openvpn::ConstBufferType< T >::append ( const B &  other)
protected

Append data from another buffer to this buffer.

Template Parameters
BThe type of the other buffer.
Parameters
otherThe other buffer to be appended.

Definition at line 1607 of file buffer.hpp.

Here is the caller graph for this function:

◆ back()

template<typename T >
T openvpn::ConstBufferType< T >::back ( ) const

Returns the last element of the buffer.

Returns
The last element of the buffer.

Definition at line 1254 of file buffer.hpp.

Here is the caller graph for this function:

◆ buffer_full_error()

template<typename T >
void openvpn::ConstBufferType< T >::buffer_full_error ( const size_t  newcap,
const bool  allocated 
) const
protected

Throw an exception when the buffer is full.

Parameters
newcapThe new capacity required for the buffer.
allocatedA flag indicating whether memory was allocated.

Definition at line 1626 of file buffer.hpp.

◆ c_data()

template<typename T >
const T * openvpn::ConstBufferType< T >::c_data ( ) const

Returns a const pointer to the start of the buffer.

Returns
Const pointer to the start of the buffer.

Definition at line 1177 of file buffer.hpp.

Here is the caller graph for this function:

◆ c_data_end()

template<typename T >
const T * openvpn::ConstBufferType< T >::c_data_end ( ) const

Returns a const pointer to the end of the buffer.

Returns
Const pointer to the end of the buffer.

Definition at line 1183 of file buffer.hpp.

◆ c_data_raw()

template<typename T >
const T * openvpn::ConstBufferType< T >::c_data_raw ( ) const

Returns a const pointer to the start of the raw data in the buffer.

Returns
Const pointer to the start of the raw data.

Definition at line 1189 of file buffer.hpp.

Here is the caller graph for this function:

◆ c_index()

template<typename T >
const T * openvpn::ConstBufferType< T >::c_index ( const size_t  index) const

Get a const pointer to the element at the specified index in the array.

Parameters
indexThe index of the element to retrieve.
Returns
A const pointer to the element at the specified index.

Definition at line 1394 of file buffer.hpp.

Here is the caller graph for this function:

◆ c_str()

template<typename T >
const T * openvpn::ConstBufferType< T >::c_str ( ) const

Returns a const pointer to the null-terminated string representation of the buffer.

Returns
Const pointer to the null-terminated string.

Definition at line 1165 of file buffer.hpp.

Here is the caller graph for this function:

◆ capacity()

template<typename T >
size_t openvpn::ConstBufferType< T >::capacity ( ) const

Returns the capacity (raw size) of the allocated buffer in T objects.

Returns
The capacity of the buffer in T objects.

Definition at line 1195 of file buffer.hpp.

Here is the caller graph for this function:

◆ const_buffer()

template<typename T >
openvpn_io::const_buffer openvpn::ConstBufferType< T >::const_buffer ( ) const

Return an openvpn_io::const_buffer object used by asio write methods.

Returns
A const_buffer object representing the underlying buffer data.

Definition at line 1295 of file buffer.hpp.

Here is the caller graph for this function:

◆ const_buffer_clamp()

template<typename T >
openvpn_io::const_buffer openvpn::ConstBufferType< T >::const_buffer_clamp ( ) const

Return a clamped version of const_buffer().

This function returns a const_buffer object that represents the underlying buffer data, but with a size clamped to a certain limit. This can be useful when you want to ensure that the buffer size does not exceed a specific value.

Returns
A const_buffer object representing the underlying buffer data, with the size clamped to a certain limit.

Definition at line 1301 of file buffer.hpp.

Here is the caller graph for this function:

◆ const_buffer_limit()

template<typename T >
openvpn_io::const_buffer openvpn::ConstBufferType< T >::const_buffer_limit ( const size_t  limit) const

Return a const_buffer object with a specified size limit.

This function returns a const_buffer object that represents the underlying buffer data, but with a size limited to the specified limit value. This can be useful when you want to ensure that the buffer size does not exceed a specific value.

Parameters
limitThe maximum size of the returned const_buffer object.
Returns
A const_buffer object representing the underlying buffer data, with the size limited to the specified limit value.

Definition at line 1307 of file buffer.hpp.

Here is the caller graph for this function:

◆ contains_null()

template<typename T >
bool openvpn::ConstBufferType< T >::contains_null ( ) const

Returns true if the buffer contains a null character.

Returns
True if the buffer contains a null character, false otherwise.

Definition at line 1269 of file buffer.hpp.

◆ data()

template<typename T >
T * openvpn::ConstBufferType< T >::data ( )
protected

Get a mutable pointer to the start of the array.

Returns
A mutable pointer to the start of the array.

Definition at line 1433 of file buffer.hpp.

Here is the caller graph for this function:

◆ data_end()

template<typename T >
T * openvpn::ConstBufferType< T >::data_end ( )
protected

Get a mutable pointer to the end of the array.

Returns
A mutable pointer to the end of the array.

Definition at line 1439 of file buffer.hpp.

Here is the caller graph for this function:

◆ data_raw()

template<typename T >
T * openvpn::ConstBufferType< T >::data_raw ( )
protected

Get a mutable pointer to the start of the raw data.

Returns
A mutable pointer to the start of the raw data.

Definition at line 1445 of file buffer.hpp.

Here is the caller graph for this function:

◆ defined()

template<typename T >
bool openvpn::ConstBufferType< T >::defined ( ) const

Returns true if the buffer is not empty.

Returns
True if the buffer is not empty, false otherwise.

Definition at line 1207 of file buffer.hpp.

Here is the caller graph for this function:

◆ empty()

template<typename T >
bool openvpn::ConstBufferType< T >::empty ( ) const

Returns true if the buffer is empty.

Returns
True if the buffer is empty, false otherwise.

Definition at line 1219 of file buffer.hpp.

Here is the caller graph for this function:

◆ front()

template<typename T >
T openvpn::ConstBufferType< T >::front ( ) const

Returns the first element of the buffer.

Returns
The first element of the buffer.

Definition at line 1248 of file buffer.hpp.

Here is the caller graph for this function:

◆ inc_size()

template<typename T >
void openvpn::ConstBufferType< T >::inc_size ( const size_t  delta)

Increment the size of the array (usually used in a similar context to set_size such as after mutable_buffer_append).

Parameters
deltaThe amount to increment the size by.

Definition at line 1375 of file buffer.hpp.

Here is the caller graph for this function:

◆ index()

template<typename T >
T * openvpn::ConstBufferType< T >::index ( const size_t  index)
protected

Get a mutable index into the array.

Parameters
indexThe index of the element to be accessed.
Returns
A pointer to the element at the specified index.

Definition at line 1498 of file buffer.hpp.

Here is the caller graph for this function:

◆ init_headroom()

template<typename T >
void openvpn::ConstBufferType< T >::init_headroom ( const size_t  headroom)

Initializes the headroom (offset) of the buffer.

Parameters
headroomThe desired headroom value.

Definition at line 1134 of file buffer.hpp.

Here is the caller graph for this function:

◆ is_zeroed()

template<typename T >
bool openvpn::ConstBufferType< T >::is_zeroed ( ) const

Returns true if the buffer is zeroed (all elements are zero).

Returns
True if the buffer is zeroed, false otherwise.

Definition at line 1281 of file buffer.hpp.

◆ length()

template<typename T >
size_t openvpn::ConstBufferType< T >::length ( ) const

Returns the length of the buffer.

Returns
The length of the buffer in elements.

Definition at line 1171 of file buffer.hpp.

Here is the caller graph for this function:

◆ max_size()

template<typename T >
size_t openvpn::ConstBufferType< T >::max_size ( ) const

Return the maximum allowable size value in T objects given the current offset (without considering resize).

Returns
The maximum allowable size value in T objects.

Definition at line 1360 of file buffer.hpp.

Here is the caller graph for this function:

◆ max_size_tailroom()

template<typename T >
size_t openvpn::ConstBufferType< T >::max_size_tailroom ( const size_t  tailroom) const
protected

Return the maximum allowable size value in T objects, taking into account the specified tailroom.

Parameters
tailroomThe amount of additional space to reserve at the end of the buffer.
Returns
The maximum allowable size value in T objects, considering the tailroom.

Definition at line 1458 of file buffer.hpp.

◆ mutable_buffer()

template<typename T >
openvpn_io::mutable_buffer openvpn::ConstBufferType< T >::mutable_buffer ( const size_t  tailroom = 0)
protected

Return an openvpn_io::mutable_buffer object used by asio read methods, starting from data().

Parameters
tailroomThe amount of tailroom to reserve in the buffer (default: 0).
Returns
An openvpn_io::mutable_buffer object.

Definition at line 1509 of file buffer.hpp.

◆ mutable_buffer_append()

template<typename T >
openvpn_io::mutable_buffer openvpn::ConstBufferType< T >::mutable_buffer_append ( const size_t  tailroom = 0)
protected

Return an openvpn_io::mutable_buffer object used by asio read methods, starting from data_end().

Parameters
tailroomThe amount of tailroom to reserve in the buffer (default: 0).
Returns
An openvpn_io::mutable_buffer object.

Definition at line 1515 of file buffer.hpp.

◆ mutable_buffer_append_clamp()

template<typename T >
openvpn_io::mutable_buffer openvpn::ConstBufferType< T >::mutable_buffer_append_clamp ( const size_t  tailroom = 0)
protected

Clamped version of mutable_buffer_append().

Parameters
tailroomThe amount of tailroom to reserve in the buffer (default: 0).
Returns
An openvpn_io::mutable_buffer object.

Definition at line 1527 of file buffer.hpp.

◆ mutable_buffer_clamp()

template<typename T >
openvpn_io::mutable_buffer openvpn::ConstBufferType< T >::mutable_buffer_clamp ( const size_t  tailroom = 0)
protected

Clamped version of mutable_buffer().

Parameters
tailroomThe amount of tailroom to reserve in the buffer (default: 0).
Returns
An openvpn_io::mutable_buffer object.

Definition at line 1521 of file buffer.hpp.

◆ null_terminate()

template<typename T >
void openvpn::ConstBufferType< T >::null_terminate ( )
protected

Null-terminate the array.

Exceptions
Willthrow an exception if there is no room, termination is required, and the resize fails.

Definition at line 1491 of file buffer.hpp.

Here is the caller graph for this function:

◆ offset()

template<typename T >
size_t openvpn::ConstBufferType< T >::offset ( ) const

Returns the current offset (headroom) into the buffer.

Returns
The offset into the buffer.

Definition at line 1201 of file buffer.hpp.

Here is the caller graph for this function:

◆ operator!=()

template<typename T >
bool openvpn::ConstBufferType< T >::operator!= ( const ConstBufferType< T > &  other) const

Inequality operator to compare this buffer with another ConstBufferType object.

Parameters
otherThe ConstBufferType object to compare with.
Returns
true if the buffers are not equal, false otherwise.

Definition at line 1420 of file buffer.hpp.

◆ operator==()

template<typename T >
bool openvpn::ConstBufferType< T >::operator== ( const ConstBufferType< T > &  other) const

Equality operator to compare this buffer with another ConstBufferType object.

Parameters
otherThe ConstBufferType object to compare with.
Returns
true if the buffers are equal, false otherwise.

Definition at line 1412 of file buffer.hpp.

◆ operator[]() [1/2]

template<typename T >
auto & openvpn::ConstBufferType< T >::operator[] ( const size_t  index)

Non-const indexing operator for ConstBufferType.

Parameters
indexIndex of the element to access.
Returns
Non-const reference to the element at the specified index.

Definition at line 1123 of file buffer.hpp.

◆ operator[]() [2/2]

template<typename T >
const auto & openvpn::ConstBufferType< T >::operator[] ( const size_t  index) const

Const indexing operator for ConstBufferType.

Parameters
indexIndex of the element to access.
Returns
Const reference to the element at the specified index.

Definition at line 1115 of file buffer.hpp.

◆ pop_back()

template<typename T >
T openvpn::ConstBufferType< T >::pop_back ( )

Removes and returns the last element from the buffer.

Returns
The last element of the buffer.

Definition at line 1231 of file buffer.hpp.

Here is the caller graph for this function:

◆ pop_front()

template<typename T >
T openvpn::ConstBufferType< T >::pop_front ( )

Removes and returns the first element from the buffer.

Returns
The first element of the buffer.

Definition at line 1239 of file buffer.hpp.

Here is the caller graph for this function:

◆ prepend() [1/2]

template<typename T >
void openvpn::ConstBufferType< T >::prepend ( const T *  data,
const size_t  size 
)
protected

Prepend data to the buffer.

Parameters
dataA pointer to the data to be prepended.
sizeThe number of T objects to be prepended.

Definition at line 1558 of file buffer.hpp.

Here is the caller graph for this function:

◆ prepend() [2/2]

template<typename T >
void openvpn::ConstBufferType< T >::prepend ( const void *  data,
const size_t  size 
)
protected

Prepend data to the buffer.

Parameters
dataA pointer to the data to be prepended.
sizeThe number of bytes to be prepended.

Definition at line 1564 of file buffer.hpp.

◆ prepend_alloc()

template<typename T >
T * openvpn::ConstBufferType< T >::prepend_alloc ( const size_t  size)
protected

Allocate space for prepending data to the buffer.

Parameters
sizeThe number of T objects to allocate space for.
Returns
A pointer to the allocated space in the buffer.
Note
This function may move the data in the buffer to make room for the prepended data. If insufficient space is available, this will throw with the strong exception guarantee.

Definition at line 1580 of file buffer.hpp.

Here is the caller graph for this function:

◆ push_back()

template<typename T >
void openvpn::ConstBufferType< T >::push_back ( const T &  value)
protected

Append a T object to the end of the array, resizing the array if necessary.

Parameters
valueThe T object to append.

Definition at line 1465 of file buffer.hpp.

Here is the caller graph for this function:

◆ push_front()

template<typename T >
void openvpn::ConstBufferType< T >::push_front ( const T &  value)
protected

Append a T object to the array, with possible resize.

Parameters
valueThe T object to be appended to the array.

Definition at line 1473 of file buffer.hpp.

Here is the caller graph for this function:

◆ range()

template<typename T >
ConstBufferType< T > openvpn::ConstBufferType< T >::range ( size_t  offset,
size_t  len 
) const

Get a range of the buffer as a ConstBufferType object.

Parameters
offsetThe starting offset of the range.
lenThe length of the range.
Returns
A ConstBufferType object representing the specified range of the buffer.

Definition at line 1381 of file buffer.hpp.

Here is the caller graph for this function:

◆ read() [1/2]

template<typename T >
void openvpn::ConstBufferType< T >::read ( NCT data,
const size_t  size 
)

Read data from the buffer into the specified memory location.

Parameters
dataPointer to the memory location where the data will be read.
sizeNumber of bytes to read from the buffer.

Definition at line 1314 of file buffer.hpp.

Here is the caller graph for this function:

◆ read() [2/2]

template<typename T >
void openvpn::ConstBufferType< T >::read ( void *  data,
const size_t  size 
)

Read data from the buffer into the specified memory location.

Parameters
dataPointer to the memory location where the data will be read.
sizeNumber of bytes to read from the buffer.

Definition at line 1320 of file buffer.hpp.

◆ read_alloc()

template<typename T >
auto * openvpn::ConstBufferType< T >::read_alloc ( const size_t  size)

Allocate memory and read data from the buffer into the allocated memory.

Parameters
sizeNumber of bytes to read from the buffer.
Returns
Pointer to the allocated memory containing the read data.

Definition at line 1326 of file buffer.hpp.

Here is the caller graph for this function:

◆ read_alloc_buf()

template<typename T >
auto openvpn::ConstBufferType< T >::read_alloc_buf ( const size_t  size)

Allocate memory and read data from the buffer into the allocated memory.

Parameters
sizeNumber of bytes to read from the buffer.
Returns
Buffer containing the read data.

Definition at line 1345 of file buffer.hpp.

Here is the caller graph for this function:

◆ realign()

template<typename T >
void openvpn::ConstBufferType< T >::realign ( size_t  headroom)
protected

Realign the buffer with the specified headroom.

Parameters
headroomThe amount of headroom to reserve in the buffer.
Note
This is useful for aligning structures within the buffer or for adjusting the headroom in the buffer. It does one by adjusting the other.

Definition at line 1534 of file buffer.hpp.

Here is the caller graph for this function:

◆ remaining()

template<typename T >
size_t openvpn::ConstBufferType< T >::remaining ( const size_t  tailroom = 0) const
protected

Return the number of additional T objects that can be added before capacity is reached (without considering resize).

Parameters
tailroom(Optional) The amount of additional space to reserve at the end of the buffer.
Returns
The number of additional T objects that can be added.

Definition at line 1451 of file buffer.hpp.

Here is the caller graph for this function:

◆ reserve()

template<typename T >
void openvpn::ConstBufferType< T >::reserve ( const size_t  n)
protected

Reserve additional memory for the buffer.

Parameters
nThe amount of additional memory to reserve.

Definition at line 1426 of file buffer.hpp.

Here is the caller graph for this function:

◆ reset() [1/2]

template<typename T >
void openvpn::ConstBufferType< T >::reset ( const size_t  headroom,
const size_t  min_capacity,
const unsigned int  flags 
)
protected

Reset the buffer with the specified headroom, minimum capacity, and flags.

Parameters
headroomThe amount of headroom to reserve in the buffer.
min_capacityThe minimum capacity of the buffer.
flagsFlags to control the behavior of the reset operation.

Definition at line 1599 of file buffer.hpp.

◆ reset() [2/2]

template<typename T >
void openvpn::ConstBufferType< T >::reset ( const size_t  min_capacity,
const unsigned int  flags 
)
protected

Reset the buffer with the specified minimum capacity and flags.

Parameters
min_capacityThe minimum capacity of the buffer.
flagsFlags to control the behavior of the reset operation.

Definition at line 1592 of file buffer.hpp.

Here is the caller graph for this function:

◆ reset_content()

template<typename T >
void openvpn::ConstBufferType< T >::reset_content ( )

Resets the content of the buffer.

Definition at line 1159 of file buffer.hpp.

Here is the caller graph for this function:

◆ reset_impl()

template<typename T >
void openvpn::ConstBufferType< T >::reset_impl ( const size_t  min_capacity,
const unsigned int  flags 
)
protectedvirtual

Called when the reset method needs to expand the buffer size.

Parameters
min_capacityThe minimum capacity required for the buffer.
flagsFlags to control the behavior of the reset operation.

Reimplemented in openvpn::BufferAllocatedType< T >, and openvpn::BufferAllocatedType< unsigned char >.

Definition at line 1613 of file buffer.hpp.

◆ reset_offset()

template<typename T >
void openvpn::ConstBufferType< T >::reset_offset ( const size_t  offset)

Resets the offset of the buffer.

Parameters
offsetThe new offset value.

Definition at line 1143 of file buffer.hpp.

Here is the caller graph for this function:

◆ reset_size()

template<typename T >
void openvpn::ConstBufferType< T >::reset_size ( )

Resets the size of the buffer to zero.

Definition at line 1153 of file buffer.hpp.

Here is the caller graph for this function:

◆ resize()

template<typename T >
void openvpn::ConstBufferType< T >::resize ( const size_t  new_capacity)
protectedvirtual

Derived classes can implement buffer growing semantics by overloading this method. In the default implementation, buffers are non-growable, so an exception is thrown.

Parameters
new_capacityThe new capacity required for the buffer.
Exceptions
std::exceptionif the buffer cannot be resized.

Reimplemented in openvpn::BufferAllocatedType< T >, and openvpn::BufferAllocatedType< unsigned char >.

Definition at line 1619 of file buffer.hpp.

◆ set_size()

template<typename T >
void openvpn::ConstBufferType< T >::set_size ( const size_t  size)

After an external method, operating on the array as a mutable unsigned char buffer, has written data to the array, use this method to set the array length in terms of T objects.

Parameters
sizeThe new size of the array in terms of T objects.

Definition at line 1367 of file buffer.hpp.

Here is the caller graph for this function:

◆ set_trailer()

template<typename T >
void openvpn::ConstBufferType< T >::set_trailer ( const T &  value)
protected

Place a T object after the last object in the array, with possible resize to contain it. However, it doesn't actually change the size of the array to reflect the added object. Useful for maintaining null-terminated strings.

Parameters
valueThe T object to be placed after the last object in the array.
Exceptions
Willthrow an exception if there is no room for the trailing value and the resize fails.

Definition at line 1483 of file buffer.hpp.

Here is the caller graph for this function:

◆ size()

template<typename T >
size_t openvpn::ConstBufferType< T >::size ( ) const

Returns the size of the buffer in T objects.

Returns
The size of the buffer in T objects.

Definition at line 1225 of file buffer.hpp.

Here is the caller graph for this function:

◆ swap()

template<typename T >
template<typename T_ >
void openvpn::ConstBufferType< T >::swap ( ConstBufferType< T_ > &  other)
protected

Swap the contents of this buffer with another buffer.

Template Parameters
T_The type of the other buffer.
Parameters
otherThe other buffer to swap with.

Definition at line 1403 of file buffer.hpp.

Here is the caller graph for this function:

◆ write() [1/2]

template<typename T >
void openvpn::ConstBufferType< T >::write ( const T *  data,
const size_t  size 
)
protected

Write data to the buffer.

Parameters
dataA pointer to the data to be written.
sizeThe number of T objects to be written.

Definition at line 1546 of file buffer.hpp.

Here is the caller graph for this function:

◆ write() [2/2]

template<typename T >
void openvpn::ConstBufferType< T >::write ( const void *  data,
const size_t  size 
)
protected

Write data to the buffer.

Parameters
dataA pointer to the data to be written.
sizeThe number of bytes to be written.

Definition at line 1552 of file buffer.hpp.

◆ write_alloc()

template<typename T >
T * openvpn::ConstBufferType< T >::write_alloc ( const size_t  size)
protected

Allocate space for writing data to the buffer.

Parameters
sizeThe number of T objects to allocate space for.
Returns
A pointer to the allocated space in the buffer.

Definition at line 1570 of file buffer.hpp.

Here is the caller graph for this function:

Member Data Documentation

◆ capacity_

template<typename T >
size_t openvpn::ConstBufferType< T >::capacity_
private

Definition at line 777 of file buffer.hpp.

◆ data_

template<typename T >
T* openvpn::ConstBufferType< T >::data_
private

Definition at line 774 of file buffer.hpp.

◆ offset_

template<typename T >
size_t openvpn::ConstBufferType< T >::offset_
private

Definition at line 775 of file buffer.hpp.

◆ size_

template<typename T >
size_t openvpn::ConstBufferType< T >::size_
private

Definition at line 776 of file buffer.hpp.


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