randolf.ca  1.00
Randolf Richardson's C++ classes
Loading...
Searching...
No Matches
randolf::rring Class Reference

Ring buffer implementation for 8-bit bytes that's resizeable and threadsafe, and the methods are designed to be efficient in various ways, including by supporting the transfer of multiple bytes in variable quantities. More...

#include <rring>

+ Collaboration diagram for randolf::rring:

Public Member Functions

 rring () noexcept
 Instantiate an empty ring buffer (which can be re-sized or replaced later).
 
 rring (const size_t buffer_size)
 Instantiate an empty ring buffer (which can be re-sized later).
 
 ~rring () noexcept
 Free internal memory resources, after clearing buffer's memory (if the policy indicates that it needs to be cleared).
 
rringappend (const char *data, int len=-1)
 Add any number of characters that fit within the unused portion of the internal ring buffer.
 
rringappend (const char data)
 Add one character to the unused portion of the internal ring buffer.
 
rringappend (const std::vector< char > data, int len=-1)
 Add any number of characters that fit within the unused portion of the internal ring buffer.
 
rringappend (const std::vector< unsigned char > data, int len=-1)
 Add any number of characters that fit within the unused portion of the internal ring buffer.
 
char at (int index)
 Array-style access to the utilized portion of the ring buffer's contents, which yields the same result as that of the at() method.
 
char * c_str (char *data=nullptr) noexcept
 Return the contents of the ring buffer as an ASCIIZ string.
 
char * data () noexcept
 Returns a pointer to the underlying ring buffer's array. The beginning of the array is not the same as where the data actually begins (and ends) within the buffer.
 
rring_bamdata_bam (rring_bam *bam=nullptr) noexcept
 Returns the lengths and addresses of available memory. There may be only one block of memory, or two, depending on whether the available memory straddles the boundary of the ring buffer.
 
rringdata_bam_adjust (size_t head, size_t tail=0)
 Arbitrarily change the head and tail positions in the ring buffer. This is intended for use in conjunction with appending data directly to the ring buffer after the data_bam method.
 
rringdefragment (const bool full=true)
 Reorganizes the utilized memory in the ring buffer memory by moving the tail to the beginning. Defragmentation is completed using a custom-made algorithm that requires only a single pass.
 
size_t discard (int len=-1) noexcept
 Discard data from the ring buffer.
 
bool empty () noexcept
 Indicates whether the ring buffer is empty.
 
std::string get_ascii_map (int len=65, const std::string u="|", const std::string a=".") noexcept
 Obtains a one-line ASCII depiction of a map of the ring buffer's memory usage, wherein the utilized and available portions are represented by the | (pipe) and '.' (period) characters, respectively (these characters are configurable and can include multiple characters, which is particularly useful for text-mode console output in a Linux shell in which ANSI codes may be used to present these characters in different colours).
 
size_t get_available () noexcept
 Calculate the number of available entries in the ring buffer.
 
size_t get_head () noexcept
 Obtains the position of the head in the ring buffer.
 
size_t get_size () noexcept
 Obtains the total size of the ring buffer, including both its utilized and available portions.
 
size_t get_tail () noexcept
 Obtains the position of the tail in the ring buffer.
 
size_t get_utilized () noexcept
 Calculate the number of utilized entries in the ring buffer.
 
bool get_wipe_policy () noexcept
 Indicate whether internal buffer's memory will be cleared by the destructor before de-allocating it (default is true upon instantiation).
 
 operator char * () noexcept
 Convert the entire contents of this ring buffer to an ASCIIZ string in the form of a char* array.
 
 operator std::string () noexcept
 Convert the entire contents of this ring buffer to an std::string object.
 
 operator std::vector< char > () noexcept
 Convert the entire contents of this ring buffer to an std::vector<char> object.
 
char operator[] (int index)
 Array-style access to the utilized portion of the ring buffer's contents, which yields the same result as that of the at() method.
 
char peek ()
 Duplicate a single character from the utilized portion of the internal ring buffer, and return it as an char primitive.
 
char * peek_array (size_t len, char *data=nullptr)
 Duplicate the specified number of characters from the utilized portion of the internal ring buffer, and return them as a char* array.
 
std::string peek_string (int len=-1)
 Duplicate the specified number of characters from the utilized portion of the internal ring buffer, and return it as an std::string object.
 
std::vector< char > peek_vector (int len=-1)
 Duplicate the specified number of characters from the utilized portion of the internal ring buffer, and return it as an std::string object.
 
char remove ()
 Remove one character from the utilized portion of the internal ring buffer, and return it .
 
char * remove_array (size_t len, char *data=nullptr)
 Remove the specified number of characters from the utilized portion of the internal ring buffer, and return them as a char* array.
 
std::string remove_string (int len=-1)
 Remove the specified number of characters from the utilized portion of the internal ring buffer, and return it as an std::string object.
 
std::vector< char > remove_vector (int len=-1)
 Remove the specified number of characters from the utilized portion of the internal ring buffer, and return it as an std::string object.
 
rringset_head (int offset, bool type=true)
 Alter the position of the internal head position, without changing any of the the pre-existing data in the underlying ring buffer.
 
rringset_size (const size_t len)
 Configure the total size of the ring buffer. The new size cannot be smaller than the amount of data that's already present in the ring buffer (see the get_utilized method to find out how much data is present).
 
rringset_tail (int offset, bool type=true)
 Alter the position of the internal tail position, without changing any of the the pre-existing data in the underlying ring buffer.
 
rringset_wipe_policy (const bool policy_flag) noexcept
 Specify whether the internal buffer's memory will be cleared by the destructor before de-allocating it (default is true upon instantiation).
 

Friends

std::ostream & operator<< (std::ostream &o, rring &c) noexcept
 Support convenient streaming usage with std::cout, std::cerr, and friends.
 

Detailed Description

Ring buffer implementation for 8-bit bytes that's resizeable and threadsafe, and the methods are designed to be efficient in various ways, including by supporting the transfer of multiple bytes in variable quantities.

Data is stored internally as a char* array, but a few methods are provided to also support easy interoperability with std::vector objects since there are many scenarios where this can be helpful (and from the perspective of optimization, this eliminates the cumbersome need to utilize conversions between std::string and std::vector objects since, internally, we use direct access to/from std::vector objects).

Use case
Occasionally, ring buffers (a.k.a., circular buffers) are useful in specific situations because they provide better performance compared to other types of buffers, which either results in frequent allocations and deallocations of memory for transient-but-ordered portions of data or tracking sections of transient-but-ordered portions of data. A ring buffer relies on a single allocation of memory, along with a few variables for tracking top and bottom positions plus a few other internals to ensure smooth and accurate usage.

This class handles all of these details gracefully, and provides a thorough variety of clearly-documented methods that ensure consistency whilst handling the complexity of EoL sequences that may be 1 or 2 characters long and also differentiating between blank and NULL lines, all without causing significant increases in complexity in code.

Conventions
Lower-case letters "rb" are regularly used in partial example code to represent an instantiated rring object.

An ASCIIZ string is a C-string (char* array) that includes a terminating null (0) character at the end.

History
  • 2024-Nov-25 v1.00 Initial version
  • 2024-Dec-03 v1.00 Added rring_bam structure integration
  • 2024-Dec-03 v1.00 Added data_bam and related methods
Version
1.00
Author
Randolf Richardson

Constructor & Destructor Documentation

◆ rring() [1/2]

randolf::rring::rring ( )
inlinenoexcept

Instantiate an empty ring buffer (which can be re-sized or replaced later).

◆ rring() [2/2]

randolf::rring::rring ( const size_t buffer_size)
inline

Instantiate an empty ring buffer (which can be re-sized later).

Exceptions
std::bad_allocWhen malloc() fails to allocate memory
Parameters
buffer_sizeSize of buffer

◆ ~rring()

randolf::rring::~rring ( )
inlinenoexcept

Free internal memory resources, after clearing buffer's memory (if the policy indicates that it needs to be cleared).

Member Function Documentation

◆ append() [1/4]

rring * randolf::rring::append ( const char data)
inline

Add one character to the unused portion of the internal ring buffer.

Exceptions
std::overflow_errorIf the amount of data exceeds the available free space in the ring buffer
Returns
The same rring object so as to facilitate stacking
See also
c_str
peek
peek_vector
remove
remove_vector
Parameters
dataData to add

◆ append() [2/4]

rring * randolf::rring::append ( const char * data,
int len = -1 )
inline

Add any number of characters that fit within the unused portion of the internal ring buffer.

Exceptions
std::length_errorIf data length is -2 or below
std::overflow_errorIf the amount of data exceeds the available free space in the ring buffer
Returns
The same rring object so as to facilitate stacking
See also
c_str
peek
remove
Parameters
dataData to add
lenLength of data (-1 = treat data as an ASCIIZ string)

◆ append() [3/4]

rring * randolf::rring::append ( const std::vector< char > data,
int len = -1 )
inline

Add any number of characters that fit within the unused portion of the internal ring buffer.

Exceptions
std::length_errorIf data length is -2 or below
std::overflow_errorIf the amount of data exceeds the available free space in the ring buffer
Returns
The same rring object so as to facilitate stacking
See also
c_str
peek
remove
Parameters
dataData to add
lenLength of data (-1 = treat data as an ASCIIZ string)

◆ append() [4/4]

rring * randolf::rring::append ( const std::vector< unsigned char > data,
int len = -1 )
inline

Add any number of characters that fit within the unused portion of the internal ring buffer.

Exceptions
std::length_errorIf data length is -2 or below
std::overflow_errorIf the amount of data exceeds the available free space in the ring buffer
Returns
The same rring object so as to facilitate stacking
See also
c_str
peek
remove
Parameters
dataData to add
lenLength of data (-1 = treat data as an ASCIIZ string)

◆ at()

char randolf::rring::at ( int index)
inline

Array-style access to the utilized portion of the ring buffer's contents, which yields the same result as that of the at() method.

The first element is at index 0.

Exceptions
std::out_of_rangeif the index is out-of-range
Returns
char
See also
operator[]
Parameters
indexIndex of character to access (0 = first element; negative index values are calculated in reverse, starting with -1 as the final position)

◆ c_str()

char * randolf::rring::c_str ( char * data = nullptr)
inlinenoexcept

Return the contents of the ring buffer as an ASCIIZ string.

Postcondition
The string returned will need to be free()'d after it's no longer needed.
#include <iostream> // std::cout, std::cerr, std::endl, etc.
#include <randolf/rring>
int main(int argc, char *argv[]) {
randolf::rring rb(1024);
rb.append("This is an example.");
char* c = rb.c_str();
std::cout << "\"" << c << "\"" << std::endl;
free(c);
return EXIT_SUCCESS;
} // -x- int main -x-
Ring buffer implementation for 8-bit bytes that's resizeable and threadsafe, and the methods are desi...
Definition rring:55
Warning
When using the data parameter in a multi-threaded scenario, the amount of the memory needed should be set to the maximum size of this ring buffer to prevent unintended under-allocation resulting from a simultaneous increase in utilized ring buffer memory (caused by set_size).
Exceptions
std::bad_allocWhen malloc() fails to allocate memory
Returns
ASCIIZ string
See also
append
peek
remove
remove_array
Parameters
dataWhere to store the ASCIIZ string (including terminating zero, so it is imperative that utilized() + 1 bytes be pre-allocated)
nullptr = allocate the needed memory using malloc()

◆ data()

char * randolf::rring::data ( )
inlinenoexceptADVANCED

Returns a pointer to the underlying ring buffer's array. The beginning of the array is not the same as where the data actually begins (and ends) within the buffer.

Warning
This is the live data, which should not be accessed or modified directly; use the data_bam() and data_bam_adjust() methods instead when there is a need to access or modify the backing array directly.
Returns
Pointer to buffer (not null terminated)
See also
get_available
get_utilized
set_size

◆ data_bam()

rring_bam * randolf::rring::data_bam ( rring_bam * bam = nullptr)
inlinenoexceptADVANCED

Returns the lengths and addresses of available memory. There may be only one block of memory, or two, depending on whether the available memory straddles the boundary of the ring buffer.

This is the nearest equivalent of the data() methods provided in classes such as std::string and std::vector, but with the nuance of supporting the underpinnings of this ring buffer wherein the utilized portions may be stored at both the end and beginning of the buffer memory.

Note
The intention of this method is to provide an opportunity to directly update the contents of the ring buffer's data section in an efficient manner (e.g., such as by reading file or socket data directly into memory without having to perform separate data copying operations, etc.).
Warning
Upon updating a portion of the available-data block, the head will also need to be updated accordingly, for which the data_bam_adjust method is provided.
Exceptions
std::bad_allocWhen malloc() fails to allocate memory
Returns
Pointer to rring_bam structure
See also
data_bam_adjust
get_available
rring_bam
Parameters
bamPointer to rring_bam structure (that's already been allocated)
nullptr (default) = allocate memory for this structure with malloc (which will need to be free'd when it's no longer needed)

◆ data_bam_adjust()

rring * randolf::rring::data_bam_adjust ( size_t head,
size_t tail = 0 )
inlineADVANCED

Arbitrarily change the head and tail positions in the ring buffer. This is intended for use in conjunction with appending data directly to the ring buffer after the data_bam method.

Exceptions
std::overflow_errorIf either adjustment would result in causing an overflow
Returns
The same rring object so as to facilitate stacking
See also
data_bam
get_available
set_head
set_tail
Parameters
headNew internal head position
tailNew internal tail position

◆ defragment()

rring * randolf::rring::defragment ( const bool full = true)
inline

Reorganizes the utilized memory in the ring buffer memory by moving the tail to the beginning. Defragmentation is completed using a custom-made algorithm that requires only a single pass.

See also
data_bam
get_ascii_map
resize
Parameters
fullWhether to defrag when the utilized block isn't straddling the internal memory buffer boundary
TRUE = always defragment (default)
FALSE = only defragment if utilized block straddles memory boundary (this favours reducing processor overhead if all that's wanted is to have one block of memory to contend with in the BAM, hence it's also what the resize() method uses for better performance overall because resizing most likely occurs when the need for CPU cycles are more critical, so we're doing our part by reducing our CPU load)

◆ discard()

size_t randolf::rring::discard ( int len = -1)
inlinenoexcept

Discard data from the ring buffer.

Returns
Number of bytes of data that was discarded
See also
remove
Parameters
lenNumber of bytes to discard
-1 = all utilized data that remains will be discarded (default)

◆ empty()

bool randolf::rring::empty ( )
inlinenoexcept

Indicates whether the ring buffer is empty.

Returns
TRUE = empty@nFALSE = not empty
See also
get_available
get_utilized
set_size

◆ get_ascii_map()

std::string randolf::rring::get_ascii_map ( int len = 65,
const std::string u = "|",
const std::string a = "." )
inlinenoexcept

Obtains a one-line ASCII depiction of a map of the ring buffer's memory usage, wherein the utilized and available portions are represented by the | (pipe) and '.' (period) characters, respectively (these characters are configurable and can include multiple characters, which is particularly useful for text-mode console output in a Linux shell in which ANSI codes may be used to present these characters in different colours).

Exceptions
std::length_errorIf length is -2 or below
Returns
One-line ASCII depiction of ring buffer's memory map
See also
get_available
get_head
get_tail
get_utilized
Parameters
lenDesired size of ASCII map
-1 = Use size of ring buffer
uCharacter(s) representing utilized entries
aCharacter(s) representing available entries

◆ get_available()

size_t randolf::rring::get_available ( )
inlinenoexcept

Calculate the number of available entries in the ring buffer.

Returns
Number of entries available
See also
get_utilized

◆ get_head()

size_t randolf::rring::get_head ( )
inlinenoexceptADVANCED

Obtains the position of the head in the ring buffer.

Returns
Position of head in ring buffer
See also
get_available
get_tail
get_utilized
set_head
set_tail

◆ get_size()

size_t randolf::rring::get_size ( )
inlinenoexceptADVANCED

Obtains the total size of the ring buffer, including both its utilized and available portions.

Returns
Total size of ring buffer
See also
empty
get_available
get_utilized
set_size

◆ get_tail()

size_t randolf::rring::get_tail ( )
inlinenoexceptADVANCED

Obtains the position of the tail in the ring buffer.

Returns
Position of tail in ring buffer
See also
get_available
get_head
get_utilized
set_head
set_tail

◆ get_utilized()

size_t randolf::rring::get_utilized ( )
inlinenoexcept

Calculate the number of utilized entries in the ring buffer.

Returns
Number of entries utilized
See also
get_available

◆ get_wipe_policy()

bool randolf::rring::get_wipe_policy ( )
inlinenoexceptADVANCED

Indicate whether internal buffer's memory will be cleared by the destructor before de-allocating it (default is true upon instantiation).

Note
This is an important security feature for when the ring buffer may have been storing private data because it prevents the leaking of private data to other process that coincidentally gain access to the same memory area (e.g., by way of future calls to malloc()).
Returns
Post-wipe policy (TRUE = clear / FALSE = don't clear)
See also
set_wipe_policy

◆ peek()

char randolf::rring::peek ( )
inline

Duplicate a single character from the utilized portion of the internal ring buffer, and return it as an char primitive.

Exceptions
std::overflow_errorIf the amount of data exceeds the amount of data in the ring buffer
Returns
Data from ring buffer
See also
append
c_str
peek_vector
remove
remove_vector

◆ peek_array()

char * randolf::rring::peek_array ( size_t len,
char * data = nullptr )
inline

Duplicate the specified number of characters from the utilized portion of the internal ring buffer, and return them as a char* array.

Postcondition
The string returned will need to be free()'d after it's no longer needed.
Exceptions
std::bad_allocWhen malloc() fails to allocate memory
std::overflow_errorIf the amount of data exceeds the amount of data in the ring buffer
Returns
Data from ring buffer
See also
append
c_str
remove
remove_array
peek_string
peek_vector
Parameters
lenAmount of data to duplicate
dataWhere to store the data
nullptr = allocate the needed memory using malloc()

◆ peek_string()

std::string randolf::rring::peek_string ( int len = -1)
inline

Duplicate the specified number of characters from the utilized portion of the internal ring buffer, and return it as an std::string object.

Exceptions
std::length_errorIf data length is -2 or below
std::overflow_errorIf the amount of data exceeds the amount of data in the ring buffer
Returns
Data from ring buffer
See also
append
c_str
peek_vector
remove
remove_vector
Parameters
lenAmount of data to duplicate
-1 = all data

◆ peek_vector()

std::vector< char > randolf::rring::peek_vector ( int len = -1)
inline

Duplicate the specified number of characters from the utilized portion of the internal ring buffer, and return it as an std::string object.

Exceptions
std::length_errorIf data length is -2 or below
std::overflow_errorIf the amount of data exceeds the amount of data in the ring buffer
Returns
Data from ring buffer
See also
append
c_str
peek
remove
remove_vector
Parameters
lenAmount of data to duplicate
-1 = all data

◆ remove()

char randolf::rring::remove ( )
inline

Remove one character from the utilized portion of the internal ring buffer, and return it .

Exceptions
std::overflow_errorIf the amount of data exceeds the amount of data in the ring buffer
Returns
Data from ring buffer
See also
append
c_str
peek
remove_array
remove_string
remove_vector

◆ remove_array()

char * randolf::rring::remove_array ( size_t len,
char * data = nullptr )
inline

Remove the specified number of characters from the utilized portion of the internal ring buffer, and return them as a char* array.

Postcondition
The string returned will need to be free()'d after it's no longer needed.
Exceptions
std::bad_allocWhen malloc() fails to allocate memory
std::overflow_errorIf the amount of data exceeds the amount of data in the ring buffer
Returns
Data from ring buffer
See also
append
c_str
peek
remove
remove_string
remove_vector
Parameters
lenAmount of data to remove
dataWhere to store the data
nullptr = allocate the needed memory using malloc()

◆ remove_string()

std::string randolf::rring::remove_string ( int len = -1)
inline

Remove the specified number of characters from the utilized portion of the internal ring buffer, and return it as an std::string object.

Exceptions
std::length_errorIf data length is -2 or below
std::overflow_errorIf the amount of data exceeds the amount of data in the ring buffer
Returns
Data from ring buffer
See also
append
c_str
peek
remove
remove_string
remove_vector
Parameters
lenAmount of data to remove
-1 = all data

◆ remove_vector()

std::vector< char > randolf::rring::remove_vector ( int len = -1)
inline

Remove the specified number of characters from the utilized portion of the internal ring buffer, and return it as an std::string object.

Exceptions
std::length_errorIf data length is -2 or below
std::overflow_errorIf the amount of data exceeds the amount of data in the ring buffer
Returns
Data from ring buffer
See also
append
c_str
peek
remove
remove_array
remove_string
Parameters
lenAmount of data to remove
-1 = all data

◆ set_head()

rring * randolf::rring::set_head ( int offset,
bool type = true )
inlineADVANCED

Alter the position of the internal head position, without changing any of the the pre-existing data in the underlying ring buffer.

Exceptions
std::overflow_errorIf the new position falls beyond the internal tail position (or, in other words, it exceeds the available free space in the ring buffer)
Returns
The same rring object so as to facilitate stacking
See also
get_available
get_head
get_tail
get_utilized
set_tail
Parameters
offsetPosition adjustment (may be positive or negative)
typeType of adjustment
TRUE = absolute (default)
FALSE = relative

◆ set_size()

rring * randolf::rring::set_size ( const size_t len)
inline

Configure the total size of the ring buffer. The new size cannot be smaller than the amount of data that's already present in the ring buffer (see the get_utilized method to find out how much data is present).

Exceptions
std::overflow_errorIf the new size exceeds the amount of data that's already present in the ring buffer
Returns
The same rring object so as to facilitate stacking
See also
get_available
get_size
get_utilized
Parameters
lenNew size of ring buffer

◆ set_tail()

rring * randolf::rring::set_tail ( int offset,
bool type = true )
inlineADVANCED

Alter the position of the internal tail position, without changing any of the the pre-existing data in the underlying ring buffer.

Exceptions
std::overflow_errorIf the new position falls beyond the internal head position (or, in other words, it exceeds the available free space in the ring buffer)
Returns
The same rring object so as to facilitate stacking
See also
get_available
get_head
get_tail
get_utilized
set_head
Parameters
offsetPosition adjustment (may be positive or negative)
typeType of adjustment
TRUE = absolute (default)
FALSE = relative

◆ set_wipe_policy()

rring * randolf::rring::set_wipe_policy ( const bool policy_flag)
inlinenoexceptADVANCED

Specify whether the internal buffer's memory will be cleared by the destructor before de-allocating it (default is true upon instantiation).

Note
This is an important security feature for when the ring buffer may have been storing private data because it prevents the leaking of private data to other process that coincidentally gain access to the same memory area (e.g., by way of future calls to malloc()).
Returns
The same rring object so as to facilitate stacking
See also
get_wipe_policy
Parameters
policy_flagTRUE = clear buffer memory in destructor
FALSE = don't clear buffer memory in destructor

◆ operator char *()

randolf::rring::operator char * ( )
inlinenoexcept

Convert the entire contents of this ring buffer to an ASCIIZ string in the form of a char* array.

Postcondition
The string returned will need to be free()'d after it's no longer needed.
#include <iostream> // std::cout, std::cerr, std::endl, etc.
#include <randolf/rring>
int main(int argc, char *argv[]) {
randolf::rring rb(1024);
rb.append("This is an example.");
char* c = rb;
std::cout << "\"" << c << "\"" << std::endl;
free(c);
return EXIT_SUCCESS;
} // -x- int main -x-
Exceptions
std::bad_allocWhen malloc() fails to allocate memory
Returns
Contents of this ring buffer as an ASCII string as a char* array.
See also
c_str

◆ operator std::string()

randolf::rring::operator std::string ( )
inlinenoexcept

Convert the entire contents of this ring buffer to an std::string object.

#include <iostream> // std::cout, std::cerr, std::endl, etc.
#include <string> // std::string
#include <randolf/rring>
int main(int argc, char *argv[]) {
randolf::rring rb(1024);
rb.append("This is an example.");
std::string s = rb;
std::cout << "\"" << s << "\"" << std::endl;
return EXIT_SUCCESS;
} // -x- int main -x-
Returns
Contents of this ring buffer as an std::string object
See also
peek_string

◆ operator std::vector< char >()

randolf::rring::operator std::vector< char > ( )
inlinenoexcept

Convert the entire contents of this ring buffer to an std::vector<char> object.

#include <iostream> // std::cout, std::cerr, std::endl, etc.
#include <string> // std::string
#include <vector> // std::vector
#include <randolf/rring>
int main(int argc, char *argv[]) {
randolf::rring rb(1024);
rb.append("This is an example.");
std::vector<char> v = rb;
std::cout << "\"" << std::string(v.begin(), v.end()) << "\"" << std::endl;
return EXIT_SUCCESS;
} // -x- int main -x-
Returns
Contents of this ring buffer as an std::vector<char> object
See also
peek_vector

◆ operator[]()

char randolf::rring::operator[] ( int index)
inline

Array-style access to the utilized portion of the ring buffer's contents, which yields the same result as that of the at() method.

The first element is at index 0.

Exceptions
std::out_of_rangeif the index is out-of-range
Returns
char
See also
at
Parameters
indexIndex of character to access (0 = first element; negative index values are calculated in reverse, starting with -1 as the final position)

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & o,
rring & c )
friend

Support convenient streaming usage with std::cout, std::cerr, and friends.

#include <iostream> // std::cout, std::cerr, std::endl, etc.
#include <string> // std::string
#include <randolf/rring>
int main(int argc, char *argv[]) {
randolf::rring rb(1024);
rb.append("This is an example.");
std::cout << "\"" << rb << "\"" << std::endl;
return EXIT_SUCCESS;
} // -x- int main -x-
Returns
Contents of this ring buffer as an ASCIIZ string (a.k.a., C-string)
See also
c_str
Parameters
oOutput stream (provided automatically by std::cout and std::cerr)
cObject class (matched by compiler)

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