MADARA  3.4.1
madara::utility::LQueue< T > Class Template Reference

Defines a generic "first-in/first-out" (FIFO) Abstract Data Type (ADT) using a circular linked list. More...

#include <LQueue.h>

Classes

class  Overflow
 Exception thrown by methods in this class when an overflow condition occurs. More...
 
class  Underflow
 Exception thrown by methods in this class when an underflow condition occurs. More...
 

Public Types

typedef LQueueConstIterator< T > const_iterator
 
typedef LQueueIterator< T > iterator
 
typedef T value_type
 

Public Member Functions

 LQueue (const LQueue< T > &rhs)
 Copy constructor. More...
 
 LQueue (size_t size_hint=0)
 Constructor. More...
 
 ~LQueue (void)
 Perform actions needed when queue goes out of scope. More...
 
iterator begin (void)
 Get an iterator that points to the beginning of the queue. More...
 
const_iterator begin (void) const
 Get a const iterator that points to the beginning of the queue. More...
 
dequeue (void)
 Remove and return the front item on the queue. More...
 
iterator end (void)
 Get an iterator that points to the end of the queue. More...
 
const_iterator end (void) const
 Get a const iterator that points to the end of the queue. More...
 
void enqueue (const T &new_item)
 Place a new_item at the tail of the queue. More...
 
front (void) const
 Returns the front queue item without removing it. More...
 
bool is_empty (void) const
 Returns 1 if the queue is empty, otherwise returns 0. More...
 
bool is_full (void) const
 Returns 1 if the queue is full, otherwise returns 0. More...
 
bool operator!= (const LQueue< T > &s) const
 Compare this queue with rhs for inequality such that *this>!=s is always the complement of the boolean return value of *this==s. More...
 
LQueue< T > & operator= (const LQueue< T > &rhs)
 Assignment operator. More...
 
bool operator== (const LQueue< T > &rhs) const
 Compare this queue with rhs for equality. More...
 
size_t size (void) const
 Returns the current number of elements in the queue. More...
 

Protected Member Functions

void copy_list (const LQueue< T > &rhs)
 
void delete_list (void)
 
void dequeue_i (void)
 Remove the front item on the queue. Does not throw exceptions. More...
 

Private Attributes

size_t count_
 Number of items that are currently in the queue. More...
 
LQueueNode< T > * tail_
 We only need to keep a single pointer for the circular linked list. More...
 

Friends

class LQueueConstIterator< T >
 
class LQueueIterator< T >
 

Detailed Description

template<class T>
class madara::utility::LQueue< T >

Defines a generic "first-in/first-out" (FIFO) Abstract Data Type (ADT) using a circular linked list.

This queue is a circular linked list where the tail_ pointer points to a dummy node which makes implementation much easier (particularly iterator traversal). When enqueuing an item, the dummy node contains the new item and points to a new dummy node. The head of the list is thsu always tail_->next_. Dequeuing an object gets rid of the head node and makes the dummy node point to the new head.

Definition at line 38 of file LQueue.h.

Member Typedef Documentation

◆ const_iterator

template<class T >
typedef LQueueConstIterator<T> madara::utility::LQueue< T >::const_iterator

Definition at line 110 of file LQueue.h.

◆ iterator

template<class T >
typedef LQueueIterator<T> madara::utility::LQueue< T >::iterator

Definition at line 109 of file LQueue.h.

◆ value_type

template<class T >
typedef T madara::utility::LQueue< T >::value_type

Definition at line 45 of file LQueue.h.

Constructor & Destructor Documentation

◆ LQueue() [1/2]

template<class T >
madara::utility::LQueue< T >::LQueue ( size_t  size_hint = 0)

Constructor.

Definition at line 185 of file LQueue.cpp.

◆ LQueue() [2/2]

template<class T >
madara::utility::LQueue< T >::LQueue ( const LQueue< T > &  rhs)

Copy constructor.

Definition at line 199 of file LQueue.cpp.

◆ ~LQueue()

template<class T >
madara::utility::LQueue< T >::~LQueue< T > ( void  )

Perform actions needed when queue goes out of scope.

Definition at line 253 of file LQueue.cpp.

Member Function Documentation

◆ begin() [1/2]

template<typename T >
madara::utility::LQueue< T >::iterator madara::utility::LQueue< T >::begin ( void  )

Get an iterator that points to the beginning of the queue.

Definition at line 403 of file LQueue.cpp.

◆ begin() [2/2]

template<typename T >
madara::utility::LQueue< T >::const_iterator madara::utility::LQueue< T >::begin ( void  ) const

Get a const iterator that points to the beginning of the queue.

Definition at line 422 of file LQueue.cpp.

◆ copy_list()

template<class T >
void madara::utility::LQueue< T >::copy_list ( const LQueue< T > &  rhs)
protected

Definition at line 219 of file LQueue.cpp.

◆ delete_list()

template<class T >
void madara::utility::LQueue< T >::delete_list ( void  )
protected

Definition at line 241 of file LQueue.cpp.

◆ dequeue()

template<class T >
T madara::utility::LQueue< T >::dequeue ( void  )

Remove and return the front item on the queue.

Throws the Underflow exception if the queue is empty.

Definition at line 335 of file LQueue.cpp.

◆ dequeue_i()

template<class T >
void madara::utility::LQueue< T >::dequeue_i ( void  )
protected

Remove the front item on the queue. Does not throw exceptions.

Definition at line 355 of file LQueue.cpp.

◆ end() [1/2]

template<typename T >
madara::utility::LQueue< T >::iterator madara::utility::LQueue< T >::end ( void  )

Get an iterator that points to the end of the queue.

Definition at line 412 of file LQueue.cpp.

◆ end() [2/2]

template<typename T >
madara::utility::LQueue< T >::const_iterator madara::utility::LQueue< T >::end ( void  ) const

Get a const iterator that points to the end of the queue.

Definition at line 431 of file LQueue.cpp.

◆ enqueue()

template<class T >
void madara::utility::LQueue< T >::enqueue ( const T &  new_item)

Place a new_item at the tail of the queue.

Throws the Overflow exception if the queue is full, e.g., if memory is exhausted.

Definition at line 306 of file LQueue.cpp.

◆ front()

template<class T >
T madara::utility::LQueue< T >::front ( void  ) const

Returns the front queue item without removing it.

Throws the Underflow exception if the queue is empty.

Definition at line 374 of file LQueue.cpp.

◆ is_empty()

template<class T >
bool madara::utility::LQueue< T >::is_empty ( void  ) const

Returns 1 if the queue is empty, otherwise returns 0.

Definition at line 387 of file LQueue.cpp.

◆ is_full()

template<class T >
bool madara::utility::LQueue< T >::is_full ( void  ) const

Returns 1 if the queue is full, otherwise returns 0.

Definition at line 395 of file LQueue.cpp.

◆ operator!=()

template<class T >
bool madara::utility::LQueue< T >::operator!= ( const LQueue< T > &  s) const

Compare this queue with rhs for inequality such that *this>!=s is always the complement of the boolean return value of *this==s.

Definition at line 296 of file LQueue.cpp.

◆ operator=()

template<class T >
madara::utility::LQueue< T > & madara::utility::LQueue< T >::operator= ( const LQueue< T > &  rhs)

Assignment operator.

Definition at line 253 of file LQueue.cpp.

◆ operator==()

template<class T >
bool madara::utility::LQueue< T >::operator== ( const LQueue< T > &  rhs) const

Compare this queue with rhs for equality.

Returns true if the sizes of the two queues are equal and all the elements from 0 .. size() are equal, else false.

Definition at line 285 of file LQueue.cpp.

◆ size()

template<class T >
size_t madara::utility::LQueue< T >::size ( void  ) const

Returns the current number of elements in the queue.

Definition at line 177 of file LQueue.cpp.

Friends And Related Function Documentation

◆ LQueueConstIterator< T >

template<class T >
friend class LQueueConstIterator< T >
friend

Definition at line 1 of file LQueue.h.

◆ LQueueIterator< T >

template<class T >
friend class LQueueIterator< T >
friend

Definition at line 1 of file LQueue.h.

Member Data Documentation

◆ count_

template<class T >
size_t madara::utility::LQueue< T >::count_
private

Number of items that are currently in the queue.

Definition at line 142 of file LQueue.h.

◆ tail_

template<class T >
LQueueNode<T>* madara::utility::LQueue< T >::tail_
private

We only need to keep a single pointer for the circular linked list.

This points to the tail of the queue. Since the list is circular, the head of the queue is always tail_->next_.

Definition at line 139 of file LQueue.h.


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