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

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

#include <Queue.h>

Collaboration diagram for madara::knowledge::containers::Queue:

Public Member Functions

 Queue (const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Default constructor. More...
 
 Queue (const std::string &name, KnowledgeBase &knowledge, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Constructor. More...
 
 Queue (const std::string &name, Variables &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, int size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Default constructor. More...
 
 Queue (const Queue &rhs)
 Copy 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

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

Default constructor.

Definition at line 6 of file Queue.inl.

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 12 of file Queue.inl.

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 26 of file Queue.inl.

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 40 of file Queue.inl.

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.

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

Copy constructor.

Definition at line 69 of file Queue.inl.

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

Destructor.

Member Function Documentation

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

Clears the queue.

Definition at line 121 of file Queue.inl.

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 165 of file Queue.inl.

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 46 of file Queue.cpp.

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 115 of file Queue.inl.

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 7 of file Queue.cpp.

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

Returns the name of the variable.

Returns
name of the variable

Definition at line 152 of file Queue.inl.

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 230 of file Queue.h.

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 134 of file Queue.inl.

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 107 of file Queue.inl.

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

Assignment operator.

Parameters
rhsvalue to copy

Definition at line 82 of file Queue.inl.

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 100 of file Queue.inl.

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

Resizes the queue.

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

Definition at line 171 of file Queue.inl.

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 80 of file Queue.cpp.

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 99 of file Queue.cpp.

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

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 201 of file Queue.inl.

madara::knowledge::KnowledgeUpdateSettings madara::knowledge::containers::Queue::set_settings ( const KnowledgeUpdateSettings settings)

Sets the update settings for the variable.

Parameters
settingsthe new settings to use
Returns
the old update settings

Definition at line 188 of file Queue.inl.

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 159 of file Queue.inl.

Member Data Documentation

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

Variable context that we are modifying.

Definition at line 249 of file Queue.h.

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

Count of elements in queue.

Definition at line 259 of file Queue.h.

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

Head of the queue.

Definition at line 264 of file Queue.h.

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

guard for access and changes

Mutex for local changes

Definition at line 244 of file Queue.h.

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

Prefix of variable.

Definition at line 254 of file Queue.h.

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

Underlying array of records.

Definition at line 274 of file Queue.h.

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

Settings for modifications.

Definition at line 279 of file Queue.h.

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

Tail of the queue.

Definition at line 269 of file Queue.h.


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