AVRCpp::Collection::StaticQueue< DataType, SizeType, queue_capacity > Class Template Reference

#include <StaticQueue.h>

Inherits AVRCpp::Collection::BaseQueue< DataType, SizeType, DataType[queue_capacity]>.

Inherited by AVRCpp::Collection::PeekableStaticQueue< DataType, SizeType, queue_capacity >.

List of all members.

Public Member Functions

 StaticQueue ()
 Constructor.
bool Push (const DataType &value)
 Push item to the queue.
bool Pop (DataType &value=0)
 Pop item out of the queue.
SizeType GetCapacity (void)
 Return queue capacity.
volatile SizeType GetSize (void)
 Return queue size.
void Clear ()
 Clears this queue.
bool IsEmpty (void)
 Returns whether the queue is empty or not.
bool IsFull (void)
 Returns whether the queue is full or not.
DataType & Front ()
 Returns reference of first item.
DataType & Back ()
 Returns reference of last item.

Public Attributes

volatile uint8_t is_full

Protected Attributes

DataType data
volatile SizeType write_pointer
volatile SizeType read_pointer
struct {
   volatile uint8_t   is_full: 1
}; 


Detailed Description

template<typename DataType, typename SizeType, SizeType queue_capacity>
class AVRCpp::Collection::StaticQueue< DataType, SizeType, queue_capacity >

Definition at line 54 of file StaticQueue.h.


Constructor & Destructor Documentation

template<typename DataType, typename SizeType, SizeType queue_capacity>
AVRCpp::Collection::StaticQueue< DataType, SizeType, queue_capacity >::StaticQueue (  )  [inline]

Constructor.

Definition at line 61 of file StaticQueue.h.

00062                 {
00063                         BaseQueue<DataType, SizeType, DataType[queue_capacity]>();
00064                 }


Member Function Documentation

template<typename DataType, typename SizeType, SizeType queue_capacity>
bool AVRCpp::Collection::StaticQueue< DataType, SizeType, queue_capacity >::Push ( const DataType &  value  )  [inline]

Push item to the queue.

Definition at line 69 of file StaticQueue.h.

00070                 {
00071                         // If queue full then exit
00072                         if (this->is_full) return false;
00073 
00074                         // Write item and increase write pointer
00075                         this->data[this->write_pointer++] = value;
00076                         this->write_pointer %= queue_capacity;
00077 
00078                         // If new write pointer matches read pointer then mark queue as full
00079                         if (this->write_pointer == this->read_pointer) this->is_full = 1;
00080 
00081                         return true;
00082                 }

template<typename DataType, typename SizeType, SizeType queue_capacity>
bool AVRCpp::Collection::StaticQueue< DataType, SizeType, queue_capacity >::Pop ( DataType &  value = 0  )  [inline]

Pop item out of the queue.

Reimplemented in AVRCpp::Collection::PeekableStaticQueue< DataType, SizeType, queue_capacity >.

Definition at line 87 of file StaticQueue.h.

00088                 {
00089                         // If queue empty then exit
00090                         if (this->IsEmpty()) return false;
00091 
00092                         // Read item and increase read pointer
00093                         value = this->data[this->read_pointer++];
00094                         this->read_pointer %= queue_capacity;
00095                         
00096                         // Queue can't be full now
00097                         this->is_full = 0;
00098                         
00099                         return true;
00100                 }

template<typename DataType, typename SizeType, SizeType queue_capacity>
SizeType AVRCpp::Collection::StaticQueue< DataType, SizeType, queue_capacity >::GetCapacity ( void   )  [inline]

Return queue capacity.

Definition at line 105 of file StaticQueue.h.

00106                 {
00107                         return queue_capacity;
00108                 }

template<typename DataType, typename SizeType, SizeType queue_capacity>
volatile SizeType AVRCpp::Collection::StaticQueue< DataType, SizeType, queue_capacity >::GetSize ( void   )  [inline]

Return queue size.

Definition at line 113 of file StaticQueue.h.

00114                 {
00115                         // If queue marked full then return total size
00116                         if (this->is_full) return queue_capacity;
00117 
00118                         // This functions relies on assumption that read pointer never passes write pointer!
00119                         // Described situation cannot be evoked by user, only by software bug
00120                         if (this->read_pointer <= this->write_pointer)
00121                                 return (this->write_pointer - this->read_pointer);
00122                         else
00123                                 return ((queue_capacity - this->read_pointer) + this->write_pointer);
00124                 }

void AVRCpp::Collection::BaseQueue< DataType , SizeType , DataType >::Clear (  )  [inline, inherited]

Clears this queue.

Definition at line 69 of file BaseQueue.h.

00070                 {
00071                         this->write_pointer     = 0;
00072                         this->read_pointer  = 0;
00073                         this->is_full           = 0;
00074                 }

bool AVRCpp::Collection::BaseQueue< DataType , SizeType , DataType >::IsEmpty ( void   )  [inline, inherited]

Returns whether the queue is empty or not.

Definition at line 87 of file BaseQueue.h.

00088                 {
00089                         return ((this->read_pointer == this->write_pointer) && (this->is_full == 0));
00090                 }

bool AVRCpp::Collection::BaseQueue< DataType , SizeType , DataType >::IsFull ( void   )  [inline, inherited]

Returns whether the queue is full or not.

Definition at line 95 of file BaseQueue.h.

00096                 {
00097                         return this->is_full;
00098                 }

DataType & AVRCpp::Collection::BaseQueue< DataType , SizeType , DataType >::Front (  )  [inline, inherited]

Returns reference of first item.

NB! For speed purposes does not check constraints!

Definition at line 104 of file BaseQueue.h.

00105                 {
00106                         return this->data[this->read_pointer];
00107                 }

DataType & AVRCpp::Collection::BaseQueue< DataType , SizeType , DataType >::Back (  )  [inline, inherited]

Returns reference of last item.

NB! For speed purposes does not check constraints!

Definition at line 113 of file BaseQueue.h.

00114                 {
00115                         return this->data[this->write_pointer];
00116                 }


Member Data Documentation

DataType AVRCpp::Collection::BaseQueue< DataType , SizeType , DataType >::data [protected, inherited]

Definition at line 55 of file BaseQueue.h.

volatile SizeType AVRCpp::Collection::BaseQueue< DataType , SizeType , DataType >::write_pointer [protected, inherited]

Definition at line 56 of file BaseQueue.h.

volatile SizeType AVRCpp::Collection::BaseQueue< DataType , SizeType , DataType >::read_pointer [protected, inherited]

Definition at line 57 of file BaseQueue.h.

volatile uint8_t AVRCpp::Collection::BaseQueue< DataType , SizeType , DataType >::is_full [inherited]

Definition at line 61 of file BaseQueue.h.

struct { ... } [protected, inherited]


The documentation for this class was generated from the following file:
Generated on Sat Sep 15 23:41:48 2007 for AVR C++ Lib (common) by  doxygen 1.5.2
SourceForge.net Logo MTÜ TTÜ Robotiklubi