#include <Containers_T.h>
Collaboration diagram for ACE_Unbounded_Stack< T >:
Public Types | |
typedef ACE_Unbounded_Stack_Iterator< T > | ITERATOR |
Public Member Functions | |
ACE_Unbounded_Stack (ACE_Allocator *the_allocator=0) | |
ACE_Unbounded_Stack (const ACE_Unbounded_Stack< T > &s) | |
The copy constructor (performs initialization). | |
void | operator= (const ACE_Unbounded_Stack< T > &s) |
Assignment operator (performs assignment). | |
~ACE_Unbounded_Stack (void) | |
Perform actions needed when stack goes out of scope. | |
int | push (const T &new_item) |
Push an element onto the top of stack. | |
int | pop (T &item) |
Pop the top element of the stack. | |
int | top (T &item) const |
Examine the top of the stack. | |
int | is_empty (void) const |
Returns 1 if the container is empty, otherwise returns 0. | |
int | is_full (void) const |
Returns 1 if the container is full, otherwise returns 0. | |
int | insert (const T &new_item) |
Linear Insert of an item. | |
int | remove (const T &item) |
int | find (const T &item) const |
Finds if item occurs the set. Returns 0 if finds, else -1. | |
size_t | size (void) const |
The number of items in the stack. | |
void | dump (void) const |
Dump the state of an object. | |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. | |
Private Member Functions | |
void | delete_all_nodes (void) |
Delete all the nodes in the stack. | |
void | copy_all_nodes (const ACE_Unbounded_Stack< T > &s) |
Copy all nodes from {s} to {this}. | |
Private Attributes | |
ACE_Node< T > * | head_ |
Head of the linked list of Nodes. | |
size_t | cur_size_ |
Current size of the stack. | |
ACE_Allocator * | allocator_ |
Allocation strategy of the stack. | |
Friends | |
class | ACE_Unbounded_Stack_Iterator< T > |
This implementation of an unbounded Stack uses a linked list. If you use the {insert} or {remove} methods you should keep in mind that duplicate entries aren't allowed. In general, therefore, you should avoid the use of these methods since they aren't really part of the ADT stack. The stack is implemented as a doubly linked list.
Requirements and Performance Characteristics
Definition at line 376 of file Containers_T.h.
|
Definition at line 382 of file Containers_T.h. |
|
Initialize an empty stack using the user specified allocation strategy if provided. Definition at line 147 of file Containers_T.cpp. References ACE_NEW_MALLOC, ACE_Unbounded_Stack< T >::head_, and ACE_Allocator::instance().
00148 : head_ (0), 00149 cur_size_ (0), 00150 allocator_ (alloc) 00151 { 00152 // ACE_TRACE ("ACE_Unbounded_Stack<T>::ACE_Unbounded_Stack"); 00153 if (this->allocator_ == 0) 00154 this->allocator_ = ACE_Allocator::instance (); 00155 00156 ACE_NEW_MALLOC (this->head_, 00157 (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)), 00158 ACE_Node<T>); 00159 this->head_->next_ = this->head_; 00160 } |
|
The copy constructor (performs initialization). Initialize this stack to be an exact copy of {s}. Definition at line 204 of file Containers_T.cpp. References ACE_NEW_MALLOC, ACE_Unbounded_Stack< T >::copy_all_nodes(), ACE_Unbounded_Stack< T >::head_, and ACE_Allocator::instance().
00205 : head_ (0), 00206 cur_size_ (0), 00207 allocator_ (s.allocator_) 00208 { 00209 if (this->allocator_ == 0) 00210 this->allocator_ = ACE_Allocator::instance (); 00211 00212 ACE_NEW_MALLOC (this->head_, 00213 (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)), 00214 ACE_Node<T>); 00215 this->head_->next_ = this->head_; 00216 00217 // ACE_TRACE ("ACE_Unbounded_Stack<T>::ACE_Unbounded_Stack"); 00218 this->copy_all_nodes (s); 00219 } |
|
Perform actions needed when stack goes out of scope. Destroy the underlying list for the stack. Definition at line 234 of file Containers_T.cpp. References ACE_DES_FREE_TEMPLATE, ACE_Unbounded_Stack< T >::delete_all_nodes(), and ACE_Unbounded_Stack< T >::head_.
00235 { 00236 // ACE_TRACE ("ACE_Unbounded_Stack<T>::~ACE_Unbounded_Stack"); 00237 00238 this->delete_all_nodes (); 00239 ACE_DES_FREE_TEMPLATE (head_, 00240 this->allocator_->free, 00241 ACE_Node, 00242 <T>); 00243 } |
|
Copy all nodes from {s} to {this}.
Definition at line 182 of file Containers_T.cpp. References ACE_ASSERT, ACE_NEW_MALLOC, ACE_Unbounded_Stack< T >::cur_size_, ACE_Unbounded_Stack< T >::head_, ACE_Node< T >::item_, and ACE_Node< T >::next_. Referenced by ACE_Unbounded_Stack< T >::ACE_Unbounded_Stack(), and ACE_Unbounded_Stack< T >::operator=().
00183 { 00184 // ACE_TRACE ("ACE_Unbounded_Stack<T>::copy_all_nodes"); 00185 00186 ACE_ASSERT (this->head_ == this->head_->next_); 00187 00188 ACE_Node<T> *temp = this->head_; 00189 00190 for (ACE_Node<T> *s_temp = s.head_->next_; 00191 s_temp != s.head_; 00192 s_temp = s_temp->next_) 00193 { 00194 ACE_Node<T> *nptr = temp->next_; 00195 ACE_NEW_MALLOC (temp->next_, 00196 (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)), 00197 ACE_Node<T> (s_temp->item_, nptr)); 00198 temp = temp->next_; 00199 } 00200 this->cur_size_ = s.cur_size_; 00201 } |
|
Delete all the nodes in the stack.
Definition at line 163 of file Containers_T.cpp. References ACE_ASSERT, ACE_DES_FREE_TEMPLATE, ACE_Unbounded_Stack< T >::head_, ACE_Unbounded_Stack< T >::is_empty(), and ACE_Node< T >::next_. Referenced by ACE_Unbounded_Stack< T >::operator=(), and ACE_Unbounded_Stack< T >::~ACE_Unbounded_Stack().
00164 { 00165 // ACE_TRACE ("ACE_Unbounded_Stack<T>::delete_all_nodes"); 00166 00167 while (this->is_empty () == 0) 00168 { 00169 ACE_Node<T> *temp = this->head_->next_; 00170 this->head_->next_ = temp->next_; 00171 ACE_DES_FREE_TEMPLATE (temp, this->allocator_->free, 00172 ACE_Node, <T>); 00173 } 00174 00175 this->cur_size_ = 0; 00176 00177 ACE_ASSERT (this->head_ == this->head_->next_ 00178 && this->is_empty ()); 00179 } |
|
Dump the state of an object.
Definition at line 139 of file Containers_T.cpp.
00140 { 00141 #if defined (ACE_HAS_DUMP) 00142 // ACE_TRACE ("ACE_Unbounded_Stack<T>::dump"); 00143 #endif /* ACE_HAS_DUMP */ 00144 } |
|
Finds if item occurs the set. Returns 0 if finds, else -1. Linear find operation. Definition at line 284 of file Containers_T.cpp. References ACE_Unbounded_Stack< T >::head_, ACE_Node< T >::item_, and ACE_Node< T >::next_. Referenced by ACE_Unbounded_Stack< T >::insert().
00285 { 00286 // ACE_TRACE ("ACE_Unbounded_Stack<T>::find"); 00287 // Set <item> into the dummy node. 00288 this->head_->item_ = item; 00289 00290 ACE_Node<T> *temp = this->head_->next_; 00291 00292 // Keep looping until we find the item. 00293 while (!(temp->item_ == item)) 00294 temp = temp->next_; 00295 00296 // If we found the dummy node then it's not really there, otherwise, 00297 // it is there. 00298 return temp == this->head_ ? -1 : 0; 00299 } |
|
Linear Insert of an item. Insert {new_item} into the Stack at the head (but doesn't allow duplicates). Returns -1 if failures occur, 1 if item is already present (i.e., no duplicates are allowed), else 0. Definition at line 302 of file Containers_T.cpp. References ACE_Unbounded_Stack< T >::find(), and ACE_Unbounded_Stack< T >::push().
|
|
Returns 1 if the container is empty, otherwise returns 0. Constant time check to see if the stack is empty. Definition at line 128 of file Containers_T.inl. References ACE_Unbounded_Stack< T >::head_. Referenced by ACE_Token_Manager::check_deadlock(), ACE_Unbounded_Stack< T >::delete_all_nodes(), ACE_Unbounded_Stack< T >::pop(), and ACE_Unbounded_Stack< T >::top().
|
|
Returns 1 if the container is full, otherwise returns 0. Always resturns 0 since the stack is unbounded. Definition at line 148 of file Containers_T.inl. References ACE_TRACE.
00149 { 00150 ACE_TRACE ("ACE_Unbounded_Stack<T>::is_full"); 00151 return 0; // ??? 00152 } |
|
Assignment operator (performs assignment). Perform a deep copy of the rhs into the lhs. Definition at line 222 of file Containers_T.cpp. References ACE_Unbounded_Stack< T >::copy_all_nodes(), and ACE_Unbounded_Stack< T >::delete_all_nodes().
00223 { 00224 // ACE_TRACE ("ACE_Unbounded_Stack<T>::operator="); 00225 00226 if (this != &s) 00227 { 00228 this->delete_all_nodes (); 00229 this->copy_all_nodes (s); 00230 } 00231 } |
|
Pop the top element of the stack. Remove and return the top stack item. Returns -1 if the stack is already empty, 0 if the stack is not already empty, and -1 if failure occurs. Definition at line 262 of file Containers_T.cpp. References ACE_DES_FREE_TEMPLATE, ACE_Unbounded_Stack< T >::head_, ACE_Unbounded_Stack< T >::is_empty(), ACE_Node< T >::item_, and ACE_Node< T >::next_. Referenced by ACE_Token_Manager::check_deadlock().
00263 { 00264 // ACE_TRACE ("ACE_Unbounded_Stack<T>::pop"); 00265 00266 if (this->is_empty ()) 00267 return -1; 00268 else 00269 { 00270 ACE_Node<T> *temp = this->head_->next_; 00271 item = temp->item_; 00272 this->head_->next_ = temp->next_; 00273 00274 ACE_DES_FREE_TEMPLATE (temp, 00275 this->allocator_->free, 00276 ACE_Node, 00277 <T>); 00278 this->cur_size_--; 00279 return 0; 00280 } 00281 } |
|
Push an element onto the top of stack. Place a new item on top of the stack. Returns -1 if the stack is already full, 0 if the stack is not already full, and -1 if failure occurs. Definition at line 246 of file Containers_T.cpp. References ACE_NEW_MALLOC_RETURN, and ACE_Unbounded_Stack< T >::head_. Referenced by ACE_Unbounded_Stack< T >::insert().
00247 { 00248 // ACE_TRACE ("ACE_Unbounded_Stack<T>::push"); 00249 00250 ACE_Node<T> *temp = 0; 00251 00252 ACE_NEW_MALLOC_RETURN (temp, 00253 static_cast<ACE_Node<T> *> (this->allocator_->malloc (sizeof (ACE_Node<T>))), 00254 ACE_Node<T> (new_item, this->head_->next_), 00255 -1); 00256 this->head_->next_ = temp; 00257 this->cur_size_++; 00258 return 0; 00259 } |
|
Linear remove operation. Definition at line 313 of file Containers_T.cpp. References ACE_DES_FREE_TEMPLATE, ACE_Unbounded_Stack< T >::head_, and ACE_Node< T >::next_.
00314 { 00315 // ACE_TRACE ("ACE_Unbounded_Stack<T>::remove"); 00316 00317 // Insert the item to be founded into the dummy node. 00318 this->head_->item_ = item; 00319 00320 ACE_Node<T> *curr = this->head_; 00321 00322 while (!(curr->next_->item_ == item)) 00323 curr = curr->next_; 00324 00325 if (curr->next_ == this->head_) 00326 return -1; // Item was not found. 00327 else 00328 { 00329 ACE_Node<T> *temp = curr->next_; 00330 // Skip over the node that we're deleting. 00331 curr->next_ = temp->next_; 00332 this->cur_size_--; 00333 ACE_DES_FREE_TEMPLATE (temp, 00334 this->allocator_->free, 00335 ACE_Node, 00336 <T>); 00337 return 0; 00338 } 00339 } |
|
The number of items in the stack. Constant time access to the current stack size. Definition at line 155 of file Containers_T.inl.
00156 { 00157 return this->cur_size_; 00158 } |
|
Examine the top of the stack. Return top stack item without removing it. Returns -1 if the stack is already empty, 0 if the stack is not already empty, and -1 if failure occurs. Definition at line 135 of file Containers_T.inl. References ACE_TRACE, ACE_Unbounded_Stack< T >::head_, and ACE_Unbounded_Stack< T >::is_empty().
|
|
Definition at line 379 of file Containers_T.h. |
|
Declare the dynamic allocation hooks.
Definition at line 485 of file Containers_T.h. |
|
Allocation strategy of the stack.
Definition at line 501 of file Containers_T.h. |
|
Current size of the stack.
Definition at line 498 of file Containers_T.h. Referenced by ACE_Unbounded_Stack< T >::copy_all_nodes(). |
|
Head of the linked list of Nodes.
Definition at line 495 of file Containers_T.h. Referenced by ACE_Unbounded_Stack< T >::ACE_Unbounded_Stack(), ACE_Unbounded_Stack< T >::copy_all_nodes(), ACE_Unbounded_Stack< T >::delete_all_nodes(), ACE_Unbounded_Stack< T >::find(), ACE_Unbounded_Stack< T >::is_empty(), ACE_Unbounded_Stack< T >::pop(), ACE_Unbounded_Stack< T >::push(), ACE_Unbounded_Stack< T >::remove(), ACE_Unbounded_Stack< T >::top(), and ACE_Unbounded_Stack< T >::~ACE_Unbounded_Stack(). |