Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
Queue< E > Class Template Reference

#include <sample3-inl.h>

Public Member Functions

 Queue ()
 
 ~Queue ()
 
void Clear ()
 
size_t Size () const
 
QueueNode< E > * Head ()
 
const QueueNode< E > * Head () const
 
QueueNode< E > * Last ()
 
const QueueNode< E > * Last () const
 
void Enqueue (const E &element)
 
E * Dequeue ()
 
template<typename F >
QueueMap (F function) const
 

Detailed Description

template<typename E>
class Queue< E >

Definition at line 74 of file sample3-inl.h.

Constructor & Destructor Documentation

◆ Queue()

template<typename E >
Queue< E >::Queue ( )
inline

Definition at line 77 of file sample3-inl.h.

77: head_(NULL), last_(NULL), size_(0) {}
Here is the caller graph for this function:

◆ ~Queue()

template<typename E >
Queue< E >::~Queue ( )
inline

Definition at line 80 of file sample3-inl.h.

80{ Clear(); }
void Clear()
Definition sample3-inl.h:83
Here is the call graph for this function:

Member Function Documentation

◆ Clear()

template<typename E >
void Queue< E >::Clear ( )
inline

Definition at line 83 of file sample3-inl.h.

83 {
84 if (size_ > 0) {
85 // 1. Deletes every node.
86 QueueNode<E>* node = head_;
87 QueueNode<E>* next = node->next();
88 for (; ;) {
89 delete node;
90 node = next;
91 if (node == NULL) break;
92 next = node->next();
93 }
94
95 // 2. Resets the member variables.
96 head_ = last_ = NULL;
97 size_ = 0;
98 }
99 }
QueueNode * next()
Definition sample3-inl.h:57
uint32_t next(octet_iterator &it, octet_iterator end)
Definition checked.h:137
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dequeue()

template<typename E >
E * Queue< E >::Dequeue ( )
inline

Definition at line 131 of file sample3-inl.h.

131 {
132 if (size_ == 0) {
133 return NULL;
134 }
135
136 const QueueNode<E>* const old_head = head_;
137 head_ = head_->next_;
138 size_--;
139 if (size_ == 0) {
140 last_ = NULL;
141 }
142
143 E* element = new E(old_head->element());
144 delete old_head;
145
146 return element;
147 }
const E & element() const
Definition sample3-inl.h:54
Here is the call graph for this function:

◆ Enqueue()

template<typename E >
void Queue< E >::Enqueue ( const E & element)
inline

Definition at line 116 of file sample3-inl.h.

116 {
117 QueueNode<E>* new_node = new QueueNode<E>(element);
118
119 if (size_ == 0) {
120 head_ = last_ = new_node;
121 size_ = 1;
122 } else {
123 last_->next_ = new_node;
124 last_ = new_node;
125 size_++;
126 }
127 }
Here is the caller graph for this function:

◆ Head() [1/2]

template<typename E >
QueueNode< E > * Queue< E >::Head ( )
inline

Definition at line 105 of file sample3-inl.h.

105{ return head_; }

◆ Head() [2/2]

template<typename E >
const QueueNode< E > * Queue< E >::Head ( ) const
inline

Definition at line 106 of file sample3-inl.h.

106{ return head_; }

◆ Last() [1/2]

template<typename E >
QueueNode< E > * Queue< E >::Last ( )
inline

Definition at line 109 of file sample3-inl.h.

109{ return last_; }

◆ Last() [2/2]

template<typename E >
const QueueNode< E > * Queue< E >::Last ( ) const
inline

Definition at line 110 of file sample3-inl.h.

110{ return last_; }

◆ Map()

template<typename E >
template<typename F >
Queue * Queue< E >::Map ( F function) const
inline

Definition at line 153 of file sample3-inl.h.

153 {
154 Queue* new_queue = new Queue();
155 for (const QueueNode<E>* node = head_; node != NULL; node = node->next_) {
156 new_queue->Enqueue(function(node->element()));
157 }
158
159 return new_queue;
160 }
void Enqueue(const E &element)
Here is the call graph for this function:

◆ Size()

template<typename E >
size_t Queue< E >::Size ( ) const
inline

Definition at line 102 of file sample3-inl.h.

102{ return size_; }

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