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

This class stores thread-safe queue within the knowledge base. More...

#include <Queue.h>

Public Member Functions

 Queue (const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Default constructor. More...
 
 Queue (const Queue &rhs)
 Copy constructor. More...
 
 Queue (const std::string &name, KnowledgeBase &knowledge, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Constructor. More...
 
 Queue (const std::string &name, KnowledgeBase &knowledge, int size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Default constructor. More...
 
 Queue (const std::string &name, Variables &knowledge, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Constructor. More...
 
 Queue (const std::string &name, Variables &knowledge, int size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Default constructor. More...
 
virtual ~Queue ()=default
 Destructor. More...
 
void clear (void)
 Clears the queue. More...
 
size_t count (void)
 Returns the number of records in the queue. More...
 
knowledge::KnowledgeRecord dequeue (bool wait=true)
 Dequeues a record from the front of the queue. More...
 
template<typename... Args>
bool emplace (Args &&... args)
 Enqueues a new record to the end of the queue. More...
 
bool enqueue (const knowledge::KnowledgeRecord &record)
 Enqueues a record to the end of the queue. More...
 
std::string get_name (void) const
 Returns the name of the variable. More...
 
knowledge::KnowledgeRecord inspect (size_t position)
 Retrieves a record at a position in the queue. More...
 
bool operator!= (const Queue &value) const
 Checks for inequality. More...
 
void operator= (const Queue &rhs)
 Assignment operator. More...
 
bool operator== (const Queue &value) const
 Checks for equality. More...
 
void resize (int size=-1)
 Resizes the queue. More...
 
void set_name (const std::string &var_name, KnowledgeBase &knowledge)
 Sets the variable name that this refers to. More...
 
void set_name (const std::string &var_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)
 Returns the maximum size of the queue. More...
 

Private Member Functions

knowledge::KnowledgeRecord::Integer increment (knowledge::KnowledgeRecord::Integer base, knowledge::KnowledgeRecord::Integer value)
 Increments the base by the value, using size as a boundary. More...
 

Private Attributes

ThreadSafeContextcontext_
 Variable context that we are modifying. More...
 
Integer count_
 Count of elements in queue. More...
 
Integer head_
 Head of the queue. More...
 
MADARA_LOCK_TYPE mutex_
 guard for access and changes More...
 
std::string name_
 Prefix of variable. More...
 
Vector queue_
 Underlying array of records. More...
 
KnowledgeUpdateSettings settings_
 Settings for modifications. More...
 
Integer tail_
 Tail of the queue. More...
 

Detailed Description

This class stores thread-safe queue within the knowledge base.

The Queue allows for O(1) enqueue/dequeue time. It also allows for O(1) inspection of arbitrary elements and features asynchronous and synchronous dequeues.

Definition at line 34 of file Queue.h.

Constructor & Destructor Documentation

◆ Queue() [1/6]

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

Default constructor.

Definition at line 10 of file Queue.inl.

◆ Queue() [2/6]

madara::knowledge::containers::Queue::Queue ( 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

Definition at line 16 of file Queue.inl.

◆ Queue() [3/6]

madara::knowledge::containers::Queue::Queue ( 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

Definition at line 29 of file Queue.inl.

◆ Queue() [4/6]

madara::knowledge::containers::Queue::Queue ( 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 queue
settingssettings for evaluating the vector

Definition at line 42 of file Queue.inl.

◆ Queue() [5/6]

madara::knowledge::containers::Queue::Queue ( 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 queue
settingssettings for evaluating the vector

Definition at line 54 of file Queue.inl.

◆ Queue() [6/6]

madara::knowledge::containers::Queue::Queue ( const Queue rhs)
inline

Copy constructor.

Definition at line 66 of file Queue.inl.

◆ ~Queue()

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

Destructor.

Member Function Documentation

◆ clear()

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

Clears the queue.

Definition at line 111 of file Queue.inl.

◆ count()

size_t madara::knowledge::containers::Queue::count ( void  )
inline

Returns the number of records in the queue.

Returns
the number of records in the queue

Definition at line 151 of file Queue.inl.

◆ dequeue()

madara::knowledge::KnowledgeRecord madara::knowledge::containers::Queue::dequeue ( bool  wait = true)

Dequeues a record from the front of the queue.

This method support both blocking and non-blocking dequeues. The default operation is to wait for an element to become available in the queue and only return a valid element. Setting wait to false enables an asynchronous call that returns immediately with either a valid record or an UNINITIALIZED record, the latter of which means there was nothing in queue.

Returns
a record from the front of the queue. Will return an uncreated record if queue was empty on asynchronous call. knowledge::KnowledgeRecord::status () can be checked for UNCREATED. Can also use knowledge::KnowledgeRecord::is_valid to check for valid data on return.

Definition at line 45 of file Queue.cpp.

◆ emplace()

template<typename... Args>
bool madara::knowledge::containers::Queue::emplace ( Args &&...  args)
inline

Enqueues a new record to the end of the queue.

Parameters
argsarguments to pass to KnowledgeRecord
Returns
true if the record was enqueued and false if full

Definition at line 106 of file Queue.inl.

◆ enqueue()

bool madara::knowledge::containers::Queue::enqueue ( const knowledge::KnowledgeRecord record)

Enqueues a record to the end of the queue.

Parameters
recordthe value to enqueue
Returns
true if the record was enqueued and false if full

Definition at line 6 of file Queue.cpp.

◆ get_name()

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

Returns the name of the variable.

Returns
name of the variable

Definition at line 140 of file Queue.inl.

◆ increment()

knowledge::KnowledgeRecord::Integer madara::knowledge::containers::Queue::increment ( knowledge::KnowledgeRecord::Integer  base,
knowledge::KnowledgeRecord::Integer  value 
)
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 216 of file Queue.h.

◆ inspect()

madara::knowledge::KnowledgeRecord madara::knowledge::containers::Queue::inspect ( size_t  position)
inline

Retrieves a record at a position in the queue.

Parameters
positionthe position of the record in the queue
Returns
the record at the position in the queue

Definition at line 124 of file Queue.inl.

◆ operator!=()

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

Checks for inequality.

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

Definition at line 99 of file Queue.inl.

◆ operator=()

void madara::knowledge::containers::Queue::operator= ( const Queue rhs)
inline

Assignment operator.

Parameters
rhsvalue to copy

Definition at line 77 of file Queue.inl.

◆ operator==()

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

Checks for equality.

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

Definition at line 93 of file Queue.inl.

◆ resize()

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

Resizes the queue.

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

Definition at line 156 of file Queue.inl.

◆ set_name() [1/2]

void madara::knowledge::containers::Queue::set_name ( const std::string &  var_name,
KnowledgeBase knowledge 
)

Sets the variable name that this refers to.

Parameters
var_namethe name of the variable in the knowledge base
knowledgethe knowledge base the variable is housed in

Definition at line 78 of file Queue.cpp.

◆ set_name() [2/2]

void madara::knowledge::containers::Queue::set_name ( const std::string &  var_name,
Variables knowledge 
)

Sets the variable name that this refers to.

Parameters
var_namethe name of the variable in the knowledge base
knowledgethe knowledge base the variable is housed in

Definition at line 95 of file Queue.cpp.

◆ set_quality()

void madara::knowledge::containers::Queue::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 185 of file Queue.inl.

◆ set_settings()

madara::knowledge::KnowledgeUpdateSettings madara::knowledge::containers::Queue::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 173 of file Queue.inl.

◆ size()

size_t madara::knowledge::containers::Queue::size ( void  )
inline

Returns the maximum size of the queue.

Returns
the size of the queue

Definition at line 146 of file Queue.inl.

Member Data Documentation

◆ context_

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

Variable context that we are modifying.

Definition at line 233 of file Queue.h.

◆ count_

Integer madara::knowledge::containers::Queue::count_
private

Count of elements in queue.

Definition at line 243 of file Queue.h.

◆ head_

Integer madara::knowledge::containers::Queue::head_
private

Head of the queue.

Definition at line 248 of file Queue.h.

◆ mutex_

MADARA_LOCK_TYPE madara::knowledge::containers::Queue::mutex_
mutableprivate

guard for access and changes

Mutex for local changes

Definition at line 228 of file Queue.h.

◆ name_

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

Prefix of variable.

Definition at line 238 of file Queue.h.

◆ queue_

Vector madara::knowledge::containers::Queue::queue_
private

Underlying array of records.

Definition at line 258 of file Queue.h.

◆ settings_

KnowledgeUpdateSettings madara::knowledge::containers::Queue::settings_
private

Settings for modifications.

Definition at line 263 of file Queue.h.

◆ tail_

Integer madara::knowledge::containers::Queue::tail_
private

Tail of the queue.

Definition at line 253 of file Queue.h.


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