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

#include <buffer.hpp>

Inheritance diagram for openvpn::BufferAllocatedType< T >:
[legend]
Collaboration diagram for openvpn::BufferAllocatedType< T >:
[legend]

Public Member Functions

 BufferAllocatedType ()
 Default constructor.
 
 BufferAllocatedType (const size_t capacity, const unsigned int flags)
 Constructs a BufferAllocatedType with the specified capacity and flags.
 
 BufferAllocatedType (const T *data, const size_t size, const unsigned int flags)
 Constructs a BufferAllocatedType with the specified data, size, and flags.
 
 BufferAllocatedType (const BufferAllocatedType &other)
 Copy constructor.
 
template<typename T_ >
 BufferAllocatedType (const BufferType< T_ > &other, const unsigned int flags)
 Constructs a BufferAllocatedType from a BufferType object with the specified flags.
 
void operator= (const BufferAllocatedType &other)
 Assignment operator.
 
void init (const size_t capacity, const unsigned int flags)
 Initializes the buffer with the specified capacity and flags.
 
void init (const T *data, const size_t size, const unsigned int flags)
 Initializes the buffer with the specified data, size, and flags.
 
void realloc (const size_t newcap)
 Reallocates the buffer to the specified new capacity.
 
BufferAllocatedTyperealign (const size_t headroom)
 Realign the buffer with the specified headroom.
 
void reset (const size_t min_capacity, const unsigned int flags)
 Resets the buffer with the specified minimum capacity and flags.
 
void reset (const size_t headroom, const size_t min_capacity, const unsigned int flags)
 Resets the buffer with the specified headroom, minimum capacity, and flags.
 
template<typename T_ >
void move (BufferAllocatedType< T_ > &other)
 Moves the contents of another BufferAllocatedType object into this object.
 
template<typename T_ >
void swap (BufferAllocatedType< T_ > &other)
 Swaps the contents of this BufferAllocatedType object with another BufferAllocatedType object.
 
template<typename T_ >
 BufferAllocatedType (BufferAllocatedType< T_ > &&other) noexcept
 Move constructor.
 
BufferAllocatedTypeoperator= (BufferAllocatedType &&other) noexcept
 Move assignment operator.
 
void clear ()
 Clears the contents of the buffer.
 
void or_flags (const unsigned int flags)
 Sets the specified flags for the buffer.
 
void and_flags (const unsigned int flags)
 Clears the specified flags for the buffer.
 
 ~BufferAllocatedType ()
 Destructor.
 
 BufferAllocatedType (const size_t offset, const size_t size, const size_t capacity, const unsigned int flags)
 Private constructor.
 
void reset_impl (const size_t min_capacity, const unsigned int flags) override
 Resets the buffer implementation with the specified minimum capacity and flags.
 
void resize (const size_t new_capacity) override
 Resizes the buffer to the specified new capacity.
 
void realloc_ (const size_t newcap, size_t new_offset)
 Reallocates the buffer to the specified new capacity.
 
void free_data ()
 Frees the data associated with the buffer.
 
- Public Member Functions inherited from openvpn::BufferType< T >
 BufferType ()=default
 Default constructor for BufferType.
 
 BufferType (void *data, const size_t size, const bool filled)
 Constructor for BufferType that takes a void pointer, size, and a flag indicating if the buffer is filled.
 
 BufferType (T *data, const size_t size, const bool filled)
 Constructor for BufferType that takes a T pointer, size, and a flag indicating if the buffer is filled.
 
- Public Member Functions inherited from openvpn::ConstBufferType< T >
 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.
 

Private Attributes

unsigned int flags_
 

Friends

template<typename >
class BufferAllocatedType
 

Additional Inherited Members

- Public Types inherited from openvpn::ConstBufferType< T >
typedef T value_type
 
typedef T * type
 
typedef const T * const_type
 
typedef std::remove_const_t< T > NCT
 
- Protected Member Functions inherited from openvpn::BufferType< T >
 BufferType (T *data, const size_t offset, const size_t size, const size_t capacity)
 Protected constructor for BufferType that takes a T pointer, offset, size, and capacity.
 
- Protected Member Functions inherited from openvpn::ConstBufferType< T >
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.
 
 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.
 

Detailed Description

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

Definition at line 878 of file buffer.hpp.

Constructor & Destructor Documentation

◆ BufferAllocatedType() [1/7]

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

Default constructor.

Definition at line 1657 of file buffer.hpp.

◆ BufferAllocatedType() [2/7]

template<typename T >
openvpn::BufferAllocatedType< T >::BufferAllocatedType ( const size_t  capacity,
const unsigned int  flags 
)

Constructs a BufferAllocatedType with the specified capacity and flags.

Parameters
capacityThe initial capacity of the buffer.
flagsThe flags to set for the buffer.

Definition at line 1665 of file buffer.hpp.

◆ BufferAllocatedType() [3/7]

template<typename T >
openvpn::BufferAllocatedType< T >::BufferAllocatedType ( const T *  data,
const size_t  size,
const unsigned int  flags 
)

Constructs a BufferAllocatedType with the specified data, size, and flags.

Parameters
dataA pointer to the data to be copied into the buffer.
sizeThe size of the data to be copied.
flagsThe flags to set for the buffer.

Definition at line 1669 of file buffer.hpp.

◆ BufferAllocatedType() [4/7]

template<typename T >
openvpn::BufferAllocatedType< T >::BufferAllocatedType ( const BufferAllocatedType< T > &  other)

Copy constructor.

Parameters
otherThe BufferAllocatedType object to copy from.

Definition at line 1677 of file buffer.hpp.

◆ BufferAllocatedType() [5/7]

template<typename T >
template<typename T_ >
openvpn::BufferAllocatedType< T >::BufferAllocatedType ( const BufferType< T_ > &  other,
const unsigned int  flags 
)

Constructs a BufferAllocatedType from a BufferType object with the specified flags.

Template Parameters
T_The template parameter type of the BufferType object.
Parameters
otherThe BufferType object to copy from.
flagsThe flags to set for the new BufferAllocatedType object.

Definition at line 1686 of file buffer.hpp.

◆ BufferAllocatedType() [6/7]

template<typename T >
template<typename T_ >
openvpn::BufferAllocatedType< T >::BufferAllocatedType ( BufferAllocatedType< T_ > &&  other)
noexcept

Move constructor.

Template Parameters
T_The template parameter type of the other BufferAllocatedType object.
R_The template parameter type of the other BufferAllocatedType object.
Parameters
otherThe other BufferAllocatedType object to move from.

Definition at line 1773 of file buffer.hpp.

◆ ~BufferAllocatedType()

template<typename T >
openvpn::BufferAllocatedType< T >::~BufferAllocatedType ( )

Destructor.

Definition at line 1809 of file buffer.hpp.

◆ BufferAllocatedType() [7/7]

template<typename T >
openvpn::BufferAllocatedType< T >::BufferAllocatedType ( const size_t  offset,
const size_t  size,
const size_t  capacity,
const unsigned int  flags 
)

Private constructor.

Parameters
offsetThe offset of the buffer.
sizeThe size of the buffer.
capacityThe capacity of the buffer.
flagsThe flags for the buffer.

Definition at line 1649 of file buffer.hpp.

Member Function Documentation

◆ and_flags()

template<typename T >
void openvpn::BufferAllocatedType< T >::and_flags ( const unsigned int  flags)

Clears the specified flags for the buffer.

Parameters
flagsThe flags to clear.

Definition at line 1803 of file buffer.hpp.

◆ clear()

template<typename T >
void openvpn::BufferAllocatedType< T >::clear ( )

Clears the contents of the buffer.

Definition at line 1790 of file buffer.hpp.

Here is the caller graph for this function:

◆ free_data()

template<typename T >
void openvpn::BufferAllocatedType< T >::free_data ( )

Frees the data associated with the buffer.

Definition at line 1844 of file buffer.hpp.

◆ init() [1/2]

template<typename T >
void openvpn::BufferAllocatedType< T >::init ( const size_t  capacity,
const unsigned int  flags 
)

Initializes the buffer with the specified capacity and flags.

Parameters
capacityThe initial capacity of the buffer.
flagsThe flags to set for the buffer.

Definition at line 1707 of file buffer.hpp.

Here is the caller graph for this function:

◆ init() [2/2]

template<typename T >
void openvpn::BufferAllocatedType< T >::init ( const T *  data,
const size_t  size,
const unsigned int  flags 
)

Initializes the buffer with the specified data, size, and flags.

Parameters
dataA pointer to the data to be copied into the buffer.
sizeThe size of the data to be copied.
flagsThe flags to set for the buffer.

Definition at line 1714 of file buffer.hpp.

◆ move()

template<typename T >
template<typename T_ >
void openvpn::BufferAllocatedType< T >::move ( BufferAllocatedType< T_ > &  other)

Moves the contents of another BufferAllocatedType object into this object.

Template Parameters
T_The template parameter type of the other BufferAllocatedType object.
R_The template parameter type of the other BufferAllocatedType object.
Parameters
otherThe other BufferAllocatedType object to move from.

Definition at line 1756 of file buffer.hpp.

Here is the caller graph for this function:

◆ operator=() [1/2]

template<typename T >
BufferAllocatedType< T > & openvpn::BufferAllocatedType< T >::operator= ( BufferAllocatedType< T > &&  other)
noexcept

Move assignment operator.

Parameters
otherThe BufferAllocatedType object to move from.
Returns
A reference to this BufferAllocatedType object.

Definition at line 1780 of file buffer.hpp.

◆ operator=() [2/2]

template<typename T >
void openvpn::BufferAllocatedType< T >::operator= ( const BufferAllocatedType< T > &  other)

Assignment operator.

Parameters
otherThe BufferAllocatedType object to copy from.

Definition at line 1695 of file buffer.hpp.

◆ or_flags()

template<typename T >
void openvpn::BufferAllocatedType< T >::or_flags ( const unsigned int  flags)

Sets the specified flags for the buffer.

Parameters
flagsThe flags to set.

Definition at line 1797 of file buffer.hpp.

Here is the caller graph for this function:

◆ realign()

template<typename T >
BufferAllocatedType< T > & openvpn::BufferAllocatedType< T >::realign ( const size_t  headroom)

Realign the buffer with the specified headroom.

Parameters
headroomThe amount of headroom to reserve in the buffer.
Returns
BufferAllocatedType& A reference to the realigned buffer.
Note
May reallocate or throw an exception if the reallocation fails.
Exceptions
ifthe buffer is full and the reallocation fails.

Definition at line 1728 of file buffer.hpp.

Here is the caller graph for this function:

◆ realloc()

template<typename T >
void openvpn::BufferAllocatedType< T >::realloc ( const size_t  newcap)

Reallocates the buffer to the specified new capacity.

Parameters
newcapThe new capacity for the buffer.

Definition at line 1721 of file buffer.hpp.

Here is the caller graph for this function:

◆ realloc_()

template<typename T >
void openvpn::BufferAllocatedType< T >::realloc_ ( const size_t  newcap,
size_t  new_offset 
)

Reallocates the buffer to the specified new capacity.

Parameters
newcapThe new capacity for the buffer.
new_offsetThe new offset for the buffer.

Definition at line 1835 of file buffer.hpp.

◆ reset() [1/2]

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

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

Parameters
headroomThe additional capacity to allocate beyond the minimum capacity.
min_capacityThe minimum capacity for the buffer.
flagsThe flags to set for the buffer.

Definition at line 1748 of file buffer.hpp.

◆ reset() [2/2]

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

Resets the buffer with the specified minimum capacity and flags.

Parameters
min_capacityThe minimum capacity for the buffer.
flagsThe flags to set for the buffer.

Definition at line 1741 of file buffer.hpp.

Here is the caller graph for this function:

◆ reset_impl()

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

Resets the buffer implementation with the specified minimum capacity and flags.

Parameters
min_capacityThe minimum capacity for the buffer.
flagsThe flags to set for the buffer.

Reimplemented from openvpn::ConstBufferType< T >.

Definition at line 1816 of file buffer.hpp.

◆ resize()

template<typename T >
void openvpn::BufferAllocatedType< T >::resize ( const size_t  new_capacity)
overridevirtual

Resizes the buffer to the specified new capacity.

Parameters
new_capacityThe new capacity for the buffer.

Reimplemented from openvpn::ConstBufferType< T >.

Definition at line 1822 of file buffer.hpp.

◆ swap()

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

Swaps the contents of this BufferAllocatedType object with another BufferAllocatedType object.

Template Parameters
T_The template parameter type of the other BufferAllocatedType object.
R_The template parameter type of the other BufferAllocatedType object.
Parameters
otherThe other BufferAllocatedType object to swap with.

Definition at line 1765 of file buffer.hpp.

Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ BufferAllocatedType

template<typename T >
template<typename >
friend class BufferAllocatedType
friend

Definition at line 883 of file buffer.hpp.

Member Data Documentation

◆ flags_

template<typename T >
unsigned int openvpn::BufferAllocatedType< T >::flags_
private

Definition at line 1077 of file buffer.hpp.


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