ACE_Unbounded_List< T > Class Template Reference

Implement a simple unordered set of of unbounded size. More...

#include <Naming_Service_Container.h>

Collaboration diagram for ACE_Unbounded_List< T >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ACE_Unbounded_List_Iterator<
T > 
ITERATOR
typedef ACE_Unbounded_List_Iterator<
T > 
iterator

Public Member Functions

 ACE_Unbounded_List (ACE_Allocator *alloc=0)
 ACE_Unbounded_List (const ACE_Unbounded_List< T > &)
 Copy constructor.

void operator= (const ACE_Unbounded_List< T > &)
 Assignment operator.

 ~ACE_Unbounded_List (void)
 Destructor.

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)
int remove (const T &item)
size_t size (void) const
 Size of the set.

void dump (void) const
 Dump the state of an object.

void reset (void)
 Reset the to be empty.

ACE_Unbounded_List_Iterator<
T > 
begin (void)
ACE_Unbounded_List_Iterator<
T > 
end (void)

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.


Private Member Functions

int insert_tail (const T &item)
void delete_nodes (void)
 Delete all the nodes in the List.

void copy_nodes (const ACE_Unbounded_List< T > &)
 Copy nodes into this set.


Private Attributes

ACE_NS_Node< T > * head_
 Head of the linked list of NS_Nodes.

size_t cur_size_
 Current size of the set.

ACE_Allocatorallocator_
 Allocation strategy of the set.


Friends

class ACE_Unbounded_List_Iterator< T >

Detailed Description

template<class T>
class ACE_Unbounded_List< T >

Implement a simple unordered set of of unbounded size.

This implementation of an unordered set uses a circular linked list with a dummy node. This implementation does not allow duplicates, but it maintains FIFO ordering of insertions.

Definition at line 139 of file Naming_Service_Container.h.


Member Typedef Documentation

template<class T>
typedef ACE_Unbounded_List_Iterator<T> ACE_Unbounded_List< T >::iterator
 

Definition at line 146 of file Naming_Service_Container.h.

template<class T>
typedef ACE_Unbounded_List_Iterator<T> ACE_Unbounded_List< T >::ITERATOR
 

Definition at line 145 of file Naming_Service_Container.h.


Constructor & Destructor Documentation

template<class T>
ACE_Unbounded_List< T >::ACE_Unbounded_List ACE_Allocator alloc = 0  ) 
 

Constructor. Use user specified allocation strategy if specified.

Definition at line 172 of file Naming_Service_Container.cpp.

References ACE_NEW_MALLOC, and ACE_Allocator::instance().

00173   : head_ (0),
00174     cur_size_ (0),
00175     allocator_ (alloc)
00176 {
00177   // ACE_TRACE ("ACE_Unbounded_List<T>::ACE_Unbounded_List");
00178 
00179   if (this->allocator_ == 0)
00180     this->allocator_ = ACE_Allocator::instance ();
00181 
00182   ACE_NEW_MALLOC (this->head_,
00183                   (ACE_NS_Node<T>*) this->allocator_->malloc (sizeof (ACE_NS_Node<T>)),
00184                   ACE_NS_Node<T>);
00185   // Make the list circular by pointing it back to itself.
00186   this->head_->next_ = this->head_;
00187 }

template<class T>
ACE_Unbounded_List< T >::ACE_Unbounded_List const ACE_Unbounded_List< T > &   ) 
 

Copy constructor.

Definition at line 190 of file Naming_Service_Container.cpp.

References ACE_NEW_MALLOC, ACE_TRACE, ACE_Unbounded_List< T >::copy_nodes(), and ACE_Allocator::instance().

00191   : head_ (0),
00192     cur_size_ (0),
00193     allocator_ (us.allocator_)
00194 {
00195   ACE_TRACE ("ACE_Unbounded_List<T>::ACE_Unbounded_List");
00196 
00197   if (this->allocator_ == 0)
00198     this->allocator_ = ACE_Allocator::instance ();
00199 
00200   ACE_NEW_MALLOC (this->head_,
00201                   (ACE_NS_Node<T>*) this->allocator_->malloc (sizeof (ACE_NS_Node<T>)),
00202                   ACE_NS_Node<T>);
00203   this->head_->next_ = this->head_;
00204   this->copy_nodes (us);
00205 }

template<class T>
ACE_Unbounded_List< T >::~ACE_Unbounded_List void   ) 
 

Destructor.

Definition at line 157 of file Naming_Service_Container.cpp.

References ACE_DES_FREE_TEMPLATE, and ACE_Unbounded_List< T >::delete_nodes().

00158 {
00159   // ACE_TRACE ("ACE_Unbounded_List<T>::~ACE_Unbounded_List");
00160 
00161   this->delete_nodes ();
00162 
00163   // Delete the dummy node.
00164   ACE_DES_FREE_TEMPLATE (head_,
00165                          this->allocator_->free,
00166                          ACE_NS_Node,
00167                          <T>);
00168   this->head_ = 0;
00169 }


Member Function Documentation

template<class T>
ACE_Unbounded_List_Iterator< T > ACE_Unbounded_List< T >::begin void   ) 
 

Definition at line 256 of file Naming_Service_Container.cpp.

00257 {
00258   // ACE_TRACE ("ACE_Unbounded_List<T>::begin");
00259   return ACE_Unbounded_List_Iterator<T> (*this);
00260 }

template<class T>
void ACE_Unbounded_List< T >::copy_nodes const ACE_Unbounded_List< T > &   )  [private]
 

Copy nodes into this set.

Definition at line 126 of file Naming_Service_Container.cpp.

References ACE_Unbounded_List< T >::head_, ACE_Unbounded_List< T >::insert_tail(), ACE_NS_Node< T >::item_, and ACE_NS_Node< T >::next_.

Referenced by ACE_Unbounded_List< T >::ACE_Unbounded_List(), and ACE_Unbounded_List< T >::operator=().

00127 {
00128   for (ACE_NS_Node<T> *curr = us.head_->next_;
00129        curr != us.head_;
00130        curr = curr->next_)
00131     this->insert_tail (curr->item_);
00132 }

template<class T>
void ACE_Unbounded_List< T >::delete_nodes void   )  [private]
 

Delete all the nodes in the List.

Definition at line 135 of file Naming_Service_Container.cpp.

References ACE_DES_FREE_TEMPLATE, and ACE_NS_Node< T >::next_.

Referenced by ACE_Unbounded_List< T >::operator=(), ACE_Unbounded_List< T >::reset(), and ACE_Unbounded_List< T >::~ACE_Unbounded_List().

00136 {
00137   ACE_NS_Node<T> *curr = this->head_->next_;
00138 
00139   // Keep looking until we've hit the dummy node.
00140 
00141   while (curr != this->head_)
00142     {
00143       ACE_NS_Node<T> *temp = curr;
00144       curr = curr->next_;
00145       ACE_DES_FREE_TEMPLATE (temp,
00146                              this->allocator_->free,
00147                              ACE_NS_Node,
00148                              <T>);
00149       this->cur_size_--;
00150     }
00151 
00152   // Reset the list to be a circular list with just a dummy node.
00153   this->head_->next_ = this->head_;
00154 }

template<class T>
void ACE_Unbounded_List< T >::dump void   )  const
 

Dump the state of an object.

Definition at line 103 of file Naming_Service_Container.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_TEXT, ACE_TRACE, ACE_Unbounded_List_Iterator< T >::advance(), LM_DEBUG, and ACE_Unbounded_List_Iterator< T >::next().

00104 {
00105   ACE_TRACE ("ACE_Unbounded_List<T>::dump");
00106 
00107   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00108   ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("\nhead_ = %u"), this->head_));
00109   ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("\nhead_->next_ = %u"), this->head_->next_));
00110   ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("\ncur_size_ = %d\n"), this->cur_size_));
00111 
00112   T *item = 0;
00113 #if !defined (ACE_NLOGGING)
00114   size_t count = 1;
00115 #endif /* ! ACE_NLOGGING */
00116 
00117   for (ACE_Unbounded_List_Iterator<T> iter (*(ACE_Unbounded_List<T> *) this);
00118        iter.next (item) != 0;
00119        iter.advance ())
00120     ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("count = %d\n"), count++));
00121 
00122   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00123 }

template<class T>
ACE_Unbounded_List_Iterator< T > ACE_Unbounded_List< T >::end void   ) 
 

Definition at line 263 of file Naming_Service_Container.cpp.

00264 {
00265   // ACE_TRACE ("ACE_Unbounded_List<T>::end");
00266   return ACE_Unbounded_List_Iterator<T> (*this, 1);
00267 }

template<class T>
int ACE_Unbounded_List< T >::insert const T &  new_item  ) 
 

Insert into the set (doesn't allow duplicates). Returns -1 if failures occur, 1 if item is already present, else 0.

Definition at line 220 of file Naming_Service_Container.cpp.

References ACE_TRACE, and ACE_Unbounded_List< T >::insert_tail().

00221 {
00222   ACE_TRACE ("ACE_Unbounded_List<T>::insert");
00223   return this->insert_tail (item);
00224 }

template<class T>
int ACE_Unbounded_List< T >::insert_tail const T &  item  )  [private]
 

Insert at the tail of the set (doesn't check for duplicates).

Definition at line 72 of file Naming_Service_Container.cpp.

References ACE_NEW_MALLOC_RETURN.

Referenced by ACE_Unbounded_List< T >::copy_nodes(), and ACE_Unbounded_List< T >::insert().

00073 {
00074   ACE_NS_Node<T> *temp;
00075 
00076   // Insert <item> into the old dummy node location.
00077   this->head_->item_ = item;
00078 
00079   // Create a new dummy node.
00080   ACE_NEW_MALLOC_RETURN (temp,
00081                          (ACE_NS_Node<T>*) this->allocator_->malloc (sizeof (ACE_NS_Node<T>)),
00082                          ACE_NS_Node<T> (this->head_->next_),
00083                          -1);
00084   // Link this pointer into the list.
00085   this->head_->next_ = temp;
00086 
00087   // Point the head to the new dummy node.
00088   this->head_ = temp;
00089 
00090   this->cur_size_++;
00091   return 0;
00092 }

template<class T>
int ACE_Unbounded_List< T >::is_empty void   )  const
 

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

Definition at line 376 of file Naming_Service_Container.cpp.

References ACE_TRACE.

00377 {
00378   ACE_TRACE ("ACE_Unbounded_List<T>::is_empty");
00379   return this->head_ == this->head_->next_;
00380 }

template<class T>
int ACE_Unbounded_List< T >::is_full void   )  const
 

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

Definition at line 383 of file Naming_Service_Container.cpp.

References ACE_TRACE.

00384 {
00385   ACE_TRACE ("ACE_Unbounded_List<T>::is_full");
00386   return 0; // We should implement a "node of last resort for this..."
00387 }

template<class T>
void ACE_Unbounded_List< T >::operator= const ACE_Unbounded_List< T > &   ) 
 

Assignment operator.

Definition at line 208 of file Naming_Service_Container.cpp.

References ACE_TRACE, ACE_Unbounded_List< T >::copy_nodes(), and ACE_Unbounded_List< T >::delete_nodes().

00209 {
00210   ACE_TRACE ("ACE_Unbounded_List<T>::operator=");
00211 
00212   if (this != &us)
00213     {
00214       this->delete_nodes ();
00215       this->copy_nodes (us);
00216     }
00217 }

template<class T>
int ACE_Unbounded_List< T >::remove const T &  item  ) 
 

Remove first occurrence of from the set. Returns 0 if it removes the item, -1 if it can't find the item, and -1 if a failure occurs.

Definition at line 227 of file Naming_Service_Container.cpp.

References ACE_DES_FREE_TEMPLATE, and ACE_NS_Node< T >::next_.

00228 {
00229   // ACE_TRACE ("ACE_Unbounded_List<T>::remove");
00230 
00231   // Insert the item to be founded into the dummy node.
00232   this->head_->item_ = item;
00233 
00234   ACE_NS_Node<T> *curr = this->head_;
00235 
00236   while (!(curr->next_->item_ == item))
00237     curr = curr->next_;
00238 
00239   if (curr->next_ == this->head_)
00240     return -1; // Item was not found.
00241   else
00242     {
00243       ACE_NS_Node<T> *temp = curr->next_;
00244       // Skip over the node that we're deleting.
00245       curr->next_ = temp->next_;
00246       this->cur_size_--;
00247       ACE_DES_FREE_TEMPLATE (temp,
00248                              this->allocator_->free,
00249                              ACE_NS_Node,
00250                              <T>);
00251       return 0;
00252     }
00253 }

template<class T>
void ACE_Unbounded_List< T >::reset void   ) 
 

Reset the to be empty.

Definition at line 95 of file Naming_Service_Container.cpp.

References ACE_TRACE, and ACE_Unbounded_List< T >::delete_nodes().

00096 {
00097   ACE_TRACE ("reset");
00098 
00099   this->delete_nodes ();
00100 }

template<class T>
size_t ACE_Unbounded_List< T >::size void   )  const
 

Size of the set.

Definition at line 65 of file Naming_Service_Container.cpp.

00066 {
00067   // ACE_TRACE ("ACE_Unbounded_List<T>::size");
00068   return this->cur_size_;
00069 }


Friends And Related Function Documentation

template<class T>
friend class ACE_Unbounded_List_Iterator< T > [friend]
 

Definition at line 142 of file Naming_Service_Container.h.


Member Data Documentation

template<class T>
ACE_Unbounded_List< T >::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 200 of file Naming_Service_Container.h.

template<class T>
ACE_Allocator* ACE_Unbounded_List< T >::allocator_ [private]
 

Allocation strategy of the set.

Definition at line 220 of file Naming_Service_Container.h.

template<class T>
size_t ACE_Unbounded_List< T >::cur_size_ [private]
 

Current size of the set.

Definition at line 217 of file Naming_Service_Container.h.

template<class T>
ACE_NS_Node<T>* ACE_Unbounded_List< T >::head_ [private]
 

Head of the linked list of NS_Nodes.

Definition at line 214 of file Naming_Service_Container.h.

Referenced by ACE_Unbounded_List< T >::copy_nodes().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 13:57:35 2006 for TAO_CosNaming by doxygen 1.3.6