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

Extended StaticQueue to peek items without poping them out of the queue. More...

#include <PeekableStaticQueue.h>

Inherits AVRCpp::Collection::StaticQueue< DataType, SizeType, queue_capacity >< DataType, SizeType, queue_capacity >.

List of all members.

Public Member Functions

 PeekableStaticQueue ()
void PeekReset ()
 Moves peek cursor to point the next item to pop.
bool Peek (DataType &value)
 Lets to get the value of item referenced by peek pointer (cursor).
bool Pop (DataType &value=0)
 Pops item out of the queue.
bool CanPeekNext (void)
 Moves peek cursor to point the next queue item.
bool CanPeek (void)
 Returns whether the queue can be peeked at the current peek position.
void PopAllPeeked ()
 Pops all items before peek cursor.
bool Push (const DataType &value)
 Push item to 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
}; 

Private Attributes

SizeType peek_pointer


Detailed Description

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

Extended StaticQueue to peek items without poping them out of the queue.

Attention:
It is not tested yet. Do not trust this code.

Definition at line 49 of file PeekableStaticQueue.h.


Constructor & Destructor Documentation

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


Member Function Documentation

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

Moves peek cursor to point the next item to pop.

Definition at line 65 of file PeekableStaticQueue.h.

00066         {
00067                 peek_pointer = this->read_pointer;
00068                 
00069         } // PeekReset

template<typename DataType, typename SizeType, SizeType queue_capacity>
bool AVRCpp::Collection::PeekableStaticQueue< DataType, SizeType, queue_capacity >::Peek ( DataType &  value  )  [inline]

Lets to get the value of item referenced by peek pointer (cursor).

By default peek cursor is pointed to the next item to pop. You can move the peek pointer by calling CanPeekNext. It is possible to iterate through all queue items by the help of Peek, CanPeek and CanPeekNext memberfunctions:

         PeekableStaticQueue<uint16_t, uint8_t, 100> queue;
         uint16_t v;
         
         queue.Push(5);
         queue.Push(10);
         queue.Push(2);
         
         if (queue.CanPeek() )
                do
                {
                        queue.Peek(v);
                        
                        if (v == 2)
                        {
                                queue.PopAllPeeked()
                                break;
                        }
                        
                } while (queue.CanPeekNext() )

Definition at line 99 of file PeekableStaticQueue.h.

00100         {
00101                 // If queue empty then exit
00102                 if (this->IsEmpty()) return false;
00103                 
00104                 // Read item and increase read pointer
00105                 value = this->data[this->peek_pointer];
00106                 
00107                 // Queue can't be full now
00108                 this->is_full = 0;
00109                 
00110                 return true;
00111                 
00112         } // Peek

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

Pops item out of the queue.

Moves peek cursor to point the next item to pop.

Returns:
true on success, false in case queue is empty.

Reimplemented from AVRCpp::Collection::StaticQueue< DataType, SizeType, queue_capacity >.

Definition at line 118 of file PeekableStaticQueue.h.

00119         {
00120                 bool result = ((StaticQueue<DataType, SizeType, queue_capacity> *)this)->Pop(value);
00121                 
00122                 peek_pointer = this->read_pointer;
00123                 
00124                 return result;
00125                 
00126         } // Pop

template<typename DataType, typename SizeType, SizeType queue_capacity>
bool AVRCpp::Collection::PeekableStaticQueue< DataType, SizeType, queue_capacity >::CanPeekNext ( void   )  [inline]

Moves peek cursor to point the next queue item.

Returns:
true on success, false if there is any queue item to peek

Definition at line 132 of file PeekableStaticQueue.h.

00133         {
00134                 if (CanPeek() )
00135                 {
00136                         peek_pointer++;
00137                         peek_pointer %= queue_capacity;
00138                         
00139                         return CanPeek();
00140                 }
00141                 
00142                 return false;
00143                 
00144         } // CanPeekNext

template<typename DataType, typename SizeType, SizeType queue_capacity>
bool AVRCpp::Collection::PeekableStaticQueue< DataType, SizeType, queue_capacity >::CanPeek ( void   )  [inline]

Returns whether the queue can be peeked at the current peek position.

Definition at line 149 of file PeekableStaticQueue.h.

00150         {
00151                 return this->peek_pointer != this->write_pointer;
00152                 
00153         } // CanPeek

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

Pops all items before peek cursor.

Definition at line 158 of file PeekableStaticQueue.h.

00159         {
00160                 this->read_pointer = peek_pointer;
00161                 
00162         } // FlushPeeked

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

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>
SizeType AVRCpp::Collection::StaticQueue< DataType, SizeType, queue_capacity >::GetCapacity ( void   )  [inline, inherited]

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, inherited]

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

template<typename DataType, typename SizeType, SizeType queue_capacity>
SizeType AVRCpp::Collection::PeekableStaticQueue< DataType, SizeType, queue_capacity >::peek_pointer [private]

Definition at line 53 of file PeekableStaticQueue.h.

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