MADARA  3.4.1
madara::knowledge::containers::CircularBuffer Class Reference

This container stores a thread-safe circular buffer with O(1) access times. More...

#include <CircularBuffer.h>

Public Member Functions

 CircularBuffer (const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Default constructor. More...
 
 CircularBuffer (const std::string &name, KnowledgeBase &knowledge, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Constructor. More...
 
 CircularBuffer (const std::string &name, KnowledgeBase &knowledge, int size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Default constructor. More...
 
 CircularBuffer (const std::string &name, Variables &knowledge, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Constructor. More...
 
 CircularBuffer (const std::string &name, Variables &knowledge, int size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Default constructor. More...
 
virtual ~CircularBuffer ()=default
 Destructor. More...
 
void add (const knowledge::KnowledgeRecord &record)
 Adds a record to the end of the CircularBuffer. More...
 
void add (const std::vector< KnowledgeRecord > &records)
 Adds a list of records to the end of the CircularBuffer. More...
 
template<typename T >
void add (const std::vector< T > &values)
 Adds a list of user values to the end of the CircularBuffer. More...
 
template<typename T >
void add (const T &value)
 Adds a value to the end of the CircularBuffer. More...
 
void clear (void)
 Clears the CircularBuffer. More...
 
size_t count (void) const
 Returns the number of records in the CircularBuffer. More...
 
template<typename T >
void get (T &value) const
 Gets the most recently added user value. More...
 
knowledge::KnowledgeRecord get (void) const
 Gets the most recently added record. More...
 
std::vector< KnowledgeRecordget_earliest (size_t count) const
 Gets the oldest added records up to a specified count. More...
 
template<typename T >
void get_earliest (size_t count, std::vector< T > &values) const
 Gets the oldest added values up to a specified count. More...
 
std::vector< KnowledgeRecordget_latest (size_t count) const
 Gets the most recently added records up to a specified count. More...
 
template<typename T >
void get_latest (size_t count, std::vector< T > &values) const
 Gets the most recently added values up to a specified count. More...
 
std::string get_name (void) const
 Returns the name of the variable. More...
 
knowledge::KnowledgeRecord inspect (KnowledgeRecord::Integer position) const
 Retrieves a record at a position relative to last added. More...
 
std::vector< KnowledgeRecordinspect (KnowledgeRecord::Integer position, size_t count) const
 Retrieves a vector of records at a position relative to last added. More...
 
template<typename T >
void inspect (KnowledgeRecord::Integer position, size_t count, std::vector< T > &values) const
 Retrieves a vector of records at a position relative to last added. More...
 
template<typename T >
void inspect (KnowledgeRecord::Integer position, T &value) const
 Retrieves a record at a position relative to last added. More...
 
bool operator!= (const CircularBuffer &value) const
 Checks for inequality. More...
 
bool operator== (const CircularBuffer &value) const
 Checks for equality. More...
 
void resize (int size=-1)
 Resizes the CircularBuffer. More...
 
void set_index (KnowledgeRecord::Integer index)
 Sets the index into the circular buffer to an arbitrary position. More...
 
void set_name (const std::string &name, KnowledgeBase &knowledge)
 Sets the variable name that this refers to. More...
 
void set_name (const std::string &name, Variables &knowledge)
 Sets the variable name that this refers to. More...
 
void set_quality (uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
 Sets the quality of writing to the counter variables. More...
 
KnowledgeUpdateSettings set_settings (const KnowledgeUpdateSettings &settings)
 Sets the update settings for the variable. More...
 
size_t size (void) const
 Returns the maximum size of the CircularBuffer. More...
 

Private Member Functions

void check_all (const char *func) const
 
void check_context (const char *func) const
 
void check_name (const char *func) const
 
KnowledgeRecord::Integer increment (KnowledgeRecord::Integer base, KnowledgeRecord::Integer value) const
 Increments the base by the value, using size as a boundary. More...
 

Private Attributes

Vector buffer_
 Underlying array of records. More...
 
ThreadSafeContextcontext_
 guard for access and changes More...
 
Integer index_
 Index for latest item in circular buffer. More...
 
std::string name_
 Prefix of variable. More...
 
KnowledgeUpdateSettings settings_
 Settings for modifications. More...
 
VariableReference size_ref_
 Reference to the size field of the vector space. More...
 

Detailed Description

This container stores a thread-safe circular buffer with O(1) access times.

Definition at line 33 of file CircularBuffer.h.

Constructor & Destructor Documentation

◆ CircularBuffer() [1/5]

madara::knowledge::containers::CircularBuffer::CircularBuffer ( const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings())
inline

Default constructor.

Definition at line 20 of file CircularBuffer.inl.

◆ CircularBuffer() [2/5]

madara::knowledge::containers::CircularBuffer::CircularBuffer ( const std::string &  name,
KnowledgeBase knowledge,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings() 
)
inline

Constructor.

Parameters
namename of the integer in the knowledge base
knowledgethe knowledge base that will contain the vector
settingssettings for evaluating the vector
Exceptions
exceptions::NameExceptionbad name ("")

Definition at line 79 of file CircularBuffer.inl.

◆ CircularBuffer() [3/5]

madara::knowledge::containers::CircularBuffer::CircularBuffer ( const std::string &  name,
Variables knowledge,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings() 
)
inline

Constructor.

Parameters
namethe name of the map within the variable context
knowledgethe variable context
settingssettings to apply by default
Exceptions
exceptions::NameExceptionbad name ("")

Definition at line 89 of file CircularBuffer.inl.

◆ CircularBuffer() [4/5]

madara::knowledge::containers::CircularBuffer::CircularBuffer ( const std::string &  name,
KnowledgeBase knowledge,
int  size,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings() 
)
inline

Default constructor.

Parameters
namename of the integer in the knowledge base
knowledgethe knowledge base that will contain the vector
sizethe size of the CircularBuffer
settingssettings for evaluating the vector
Exceptions
exceptions::NameExceptionbad name ("")

Definition at line 99 of file CircularBuffer.inl.

◆ CircularBuffer() [5/5]

madara::knowledge::containers::CircularBuffer::CircularBuffer ( const std::string &  name,
Variables knowledge,
int  size,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings() 
)
inline

Default constructor.

Parameters
namename of the integer in the knowledge base
knowledgethe knowledge base that will contain the vector
sizethe size of the CircularBuffer
settingssettings for evaluating the vector
Exceptions
exceptions::NameExceptionbad name ("")

Definition at line 113 of file CircularBuffer.inl.

◆ ~CircularBuffer()

virtual madara::knowledge::containers::CircularBuffer::~CircularBuffer ( )
virtualdefault

Destructor.

Member Function Documentation

◆ add() [1/4]

void madara::knowledge::containers::CircularBuffer::add ( const knowledge::KnowledgeRecord record)
inline

Adds a record to the end of the CircularBuffer.

Parameters
recordthe value to add
Exceptions
exceptions::IndexExceptionif index is out of range/invalid

Definition at line 169 of file CircularBuffer.inl.

◆ add() [2/4]

void madara::knowledge::containers::CircularBuffer::add ( const std::vector< KnowledgeRecord > &  records)
inline

Adds a list of records to the end of the CircularBuffer.

Parameters
recordsthe values to add
Exceptions
exceptions::IndexExceptionif index is out of range/invalid

Definition at line 184 of file CircularBuffer.inl.

◆ add() [3/4]

template<typename T >
void madara::knowledge::containers::CircularBuffer::add ( const std::vector< T > &  values)

Adds a list of user values to the end of the CircularBuffer.

Parameters
valuesthe values to add
Exceptions
exceptions::IndexExceptionif index is out of range/invalid

◆ add() [4/4]

template<typename T >
void madara::knowledge::containers::CircularBuffer::add ( const T &  value)

Adds a value to the end of the CircularBuffer.

Parameters
valuethe value to add
Exceptions
exceptions::IndexExceptionif index is out of range/invalid

◆ check_all()

void madara::knowledge::containers::CircularBuffer::check_all ( const char *  func) const
inlineprivate

Definition at line 44 of file CircularBuffer.inl.

◆ check_context()

void madara::knowledge::containers::CircularBuffer::check_context ( const char *  func) const
inlineprivate

Definition at line 34 of file CircularBuffer.inl.

◆ check_name()

void madara::knowledge::containers::CircularBuffer::check_name ( const char *  func) const
inlineprivate

Definition at line 25 of file CircularBuffer.inl.

◆ clear()

void madara::knowledge::containers::CircularBuffer::clear ( void  )
inline

Clears the CircularBuffer.

Exceptions
exceptions::ContextExceptionif name or context haven't been set appropriately

Definition at line 137 of file CircularBuffer.inl.

◆ count()

size_t madara::knowledge::containers::CircularBuffer::count ( void  ) const
inline

Returns the number of records in the CircularBuffer.

Returns
the number of records in the CircularBuffer
Exceptions
exceptions::ContextExceptionif name or context haven't been set appropriately

Definition at line 291 of file CircularBuffer.inl.

◆ get() [1/2]

template<typename T >
void madara::knowledge::containers::CircularBuffer::get ( T &  value) const

Gets the most recently added user value.

Returns
the last added user value
Exceptions
exceptions::IndexExceptionif index is out of range/invalid

◆ get() [2/2]

madara::knowledge::KnowledgeRecord madara::knowledge::containers::CircularBuffer::get ( void  ) const
inline

Gets the most recently added record.

Returns
the last added record
Exceptions
exceptions::IndexExceptionif index is out of range/invalid

Definition at line 204 of file CircularBuffer.inl.

◆ get_earliest() [1/2]

std::vector< KnowledgeRecord > madara::knowledge::containers::CircularBuffer::get_earliest ( size_t  count) const
inline

Gets the oldest added records up to a specified count.

Parameters
countthe maximum number of records to return
Returns
the added records
Exceptions
exceptions::IndexExceptionif index is unreachable

Definition at line 403 of file CircularBuffer.inl.

◆ get_earliest() [2/2]

template<typename T >
void madara::knowledge::containers::CircularBuffer::get_earliest ( size_t  count,
std::vector< T > &  values 
) const

Gets the oldest added values up to a specified count.

Parameters
countthe maximum number of records to return
valuesthe added values
Exceptions
exceptions::IndexExceptionif index is unreachable

◆ get_latest() [1/2]

std::vector< KnowledgeRecord > madara::knowledge::containers::CircularBuffer::get_latest ( size_t  count) const
inline

Gets the most recently added records up to a specified count.

Parameters
countthe maximum number of records to return
Returns
the last added records
Exceptions
exceptions::IndexExceptionif index is unreachable

Definition at line 382 of file CircularBuffer.inl.

◆ get_latest() [2/2]

template<typename T >
void madara::knowledge::containers::CircularBuffer::get_latest ( size_t  count,
std::vector< T > &  values 
) const

Gets the most recently added values up to a specified count.

Parameters
countthe maximum number of records to return
valuesthe resulting values
Exceptions
exceptions::IndexExceptionif index is unreachable

◆ get_name()

std::string madara::knowledge::containers::CircularBuffer::get_name ( void  ) const
inline

Returns the name of the variable.

Returns
name of the variable

Definition at line 281 of file CircularBuffer.inl.

◆ increment()

madara::knowledge::KnowledgeRecord::Integer madara::knowledge::containers::CircularBuffer::increment ( KnowledgeRecord::Integer  base,
KnowledgeRecord::Integer  value 
) const
inlineprivate

Increments the base by the value, using size as a boundary.

Parameters
basethe base value to increment
valuethe value to increment base by
Returns
the resulting index

Definition at line 147 of file CircularBuffer.inl.

◆ inspect() [1/4]

madara::knowledge::KnowledgeRecord madara::knowledge::containers::CircularBuffer::inspect ( KnowledgeRecord::Integer  position) const
inline

Retrieves a record at a position relative to last added.

Parameters
positionthe relative position of the requested record from the latest added record. Can be negative
Returns
the record at the position in the CircularBuffer
Exceptions
exceptions::ContextExceptionif name or context haven't been set appropriately
exceptions::IndexExceptionif index is out of range/invalid

Definition at line 219 of file CircularBuffer.inl.

◆ inspect() [2/4]

std::vector< KnowledgeRecord > madara::knowledge::containers::CircularBuffer::inspect ( KnowledgeRecord::Integer  position,
size_t  count 
) const
inline

Retrieves a vector of records at a position relative to last added.

Parameters
positionthe relative position of the requested record from the latest added record. Can be negative
countthe maximum number of records to return
Returns
the record at the position in the CircularBufferConsumer
Exceptions
exceptions::ContextExceptionif name or context haven't been set appropriately
exceptions::IndexExceptionif index is out of range/invalid

Definition at line 246 of file CircularBuffer.inl.

◆ inspect() [3/4]

template<typename T >
void madara::knowledge::containers::CircularBuffer::inspect ( KnowledgeRecord::Integer  position,
size_t  count,
std::vector< T > &  values 
) const

Retrieves a vector of records at a position relative to last added.

Parameters
positionthe relative position of the requested record from the latest added record. Can be negative
countthe maximum number of records to return
valuesthe values at the position in the CircularBufferConsumer
Exceptions
exceptions::ContextExceptionif name or context haven't been set appropriately
exceptions::IndexExceptionif index is out of range/invalid

◆ inspect() [4/4]

template<typename T >
void madara::knowledge::containers::CircularBuffer::inspect ( KnowledgeRecord::Integer  position,
T &  value 
) const

Retrieves a record at a position relative to last added.

Parameters
positionthe relative position of the requested record from the latest added record. Can be negative
valuethe value at the position in the CircularBuffer
Exceptions
exceptions::ContextExceptionif name or context haven't been set appropriately
exceptions::IndexExceptionif index is out of range/invalid

◆ operator!=()

bool madara::knowledge::containers::CircularBuffer::operator!= ( const CircularBuffer value) const
inline

Checks for inequality.

Parameters
valuethe value to compare to
Returns
true if inequal, false otherwise

Definition at line 132 of file CircularBuffer.inl.

◆ operator==()

bool madara::knowledge::containers::CircularBuffer::operator== ( const CircularBuffer value) const
inline

Checks for equality.

Parameters
valuethe value to compare to
Returns
true if equal, false otherwise

Definition at line 127 of file CircularBuffer.inl.

◆ resize()

void madara::knowledge::containers::CircularBuffer::resize ( int  size = -1)
inline

Resizes the CircularBuffer.

Parameters
sizethe size of the CircularBuffer. -1 means use the size that exists in the knowledge base already.

Definition at line 300 of file CircularBuffer.inl.

◆ set_index()

void madara::knowledge::containers::CircularBuffer::set_index ( KnowledgeRecord::Integer  index)
inline

Sets the index into the circular buffer to an arbitrary position.

Parameters
indexthe new index to use

Definition at line 376 of file CircularBuffer.inl.

◆ set_name() [1/2]

void madara::knowledge::containers::CircularBuffer::set_name ( const std::string &  name,
KnowledgeBase knowledge 
)
inline

Sets the variable name that this refers to.

Parameters
namethe name of the variable in the knowledge base
knowledgethe knowledge base the variable is housed in
Exceptions
exceptions::NameExceptionbad name ("")

Definition at line 330 of file CircularBuffer.inl.

◆ set_name() [2/2]

void madara::knowledge::containers::CircularBuffer::set_name ( const std::string &  name,
Variables knowledge 
)
inline

Sets the variable name that this refers to.

Parameters
namethe name of the variable in the knowledge base
knowledgethe knowledge base the variable is housed in
Exceptions
exceptions::NameExceptionbad name ("")

Definition at line 353 of file CircularBuffer.inl.

◆ set_quality()

void madara::knowledge::containers::CircularBuffer::set_quality ( uint32_t  quality,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings(          false) 
)
inline

Sets the quality of writing to the counter variables.

Parameters
qualityquality of writing to this location
settingssettings for referring to knowledge variables

Definition at line 321 of file CircularBuffer.inl.

◆ set_settings()

madara::knowledge::KnowledgeUpdateSettings madara::knowledge::containers::CircularBuffer::set_settings ( const KnowledgeUpdateSettings settings)
inline

Sets the update settings for the variable.

Parameters
settingsthe new settings to use
Returns
the old update settings

Definition at line 311 of file CircularBuffer.inl.

◆ size()

size_t madara::knowledge::containers::CircularBuffer::size ( void  ) const
inline

Returns the maximum size of the CircularBuffer.

Returns
the size of the CircularBuffer

Definition at line 286 of file CircularBuffer.inl.

Member Data Documentation

◆ buffer_

Vector madara::knowledge::containers::CircularBuffer::buffer_
private

Underlying array of records.

Definition at line 335 of file CircularBuffer.h.

◆ context_

ThreadSafeContext* madara::knowledge::containers::CircularBuffer::context_
mutableprivate

guard for access and changes

Variable context that we are modifying

Definition at line 320 of file CircularBuffer.h.

◆ index_

Integer madara::knowledge::containers::CircularBuffer::index_
private

Index for latest item in circular buffer.

Definition at line 330 of file CircularBuffer.h.

◆ name_

std::string madara::knowledge::containers::CircularBuffer::name_
private

Prefix of variable.

Definition at line 325 of file CircularBuffer.h.

◆ settings_

KnowledgeUpdateSettings madara::knowledge::containers::CircularBuffer::settings_
private

Settings for modifications.

Definition at line 345 of file CircularBuffer.h.

◆ size_ref_

VariableReference madara::knowledge::containers::CircularBuffer::size_ref_
private

Reference to the size field of the vector space.

Definition at line 340 of file CircularBuffer.h.


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