Containers_T.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Containers_T.h
00006  *
00007  *  Containers_T.h,v 1.77 2006/01/25 19:56:00 jwillemsen Exp
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef ACE_CONTAINERS_T_H
00014 #define ACE_CONTAINERS_T_H
00015 
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "ace/config-all.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 // Need by ACE_DLList_Node.
00025 #include "ace/Containers.h"
00026 
00027 // Shared with "ace/Unbounded_Set.h"
00028 #include "ace/Node.h"
00029 
00030 // Backwards compatibility, please include "ace/Array_Base.h" directly.
00031 #include "ace/Array_Base.h"
00032 
00033 // Backwards compatibility, please include "ace/Unbounded_Set.h" directly.
00034 #include "ace/Unbounded_Set.h"
00035 
00036 // Backwards compatibility, please include "ace/Unbounded_Queue.h" directly.
00037 #include "ace/Unbounded_Queue.h"
00038 
00039 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00040 
00041 class ACE_Allocator;
00042 
00043 
00044 /**
00045  * @class ACE_Bounded_Stack
00046  *
00047  * @brief Implement a generic LIFO abstract data type.
00048  *
00049  * This implementation of a Stack uses a bounded array
00050  * that is allocated dynamically.  The Stack interface
00051  * provides the standard constant time push, pop, and top
00052  * operations.
00053  *
00054  * <b> Requirements and Performance Characteristics</b>
00055  *   - Internal Structure
00056  *       Dynamic array
00057  *   - Duplicates allowed?
00058  *       Yes
00059  *   - Random access allowed?
00060  *       No
00061  *   - Search speed
00062  *       N/A
00063  *   - Insert/replace speed
00064  *       N/A
00065  *   - Iterator still valid after change to container?
00066  *       N/A
00067  *   - Frees memory for removed elements?
00068  *       No
00069  *   - Items inserted by
00070  *       Value
00071  *   - Requirements for contained type
00072  *       -# Default constructor
00073  *       -# Copy constructor
00074  *       -# operator=
00075  *
00076  */
00077 template <class T>
00078 class ACE_Bounded_Stack
00079 {
00080 public:
00081   // = Initialization, assignment, and termination methods.
00082 
00083   /// Initialize a new empty stack with the provided size..
00084   /**
00085    * Initialize and allocate space for a new Bounded_Stack with the provided
00086    * size.
00087    */
00088   ACE_Bounded_Stack (size_t size);
00089 
00090   /// Initialize the stack to be a copy of the stack provided.
00091   /**
00092    * Initialize the stack to be an exact copy of the Bounded_Stack provided
00093    * as a parameter.
00094    */
00095   ACE_Bounded_Stack (const ACE_Bounded_Stack<T> &s);
00096 
00097   /// Assignment operator
00098   /**
00099    * Perform a deep copy operation using the Bounded_Stack parameter.  If the
00100    * capacity of the lhs isn't sufficient for the rhs, then the underlying data
00101    * structure will be reallocated to accomadate the larger number of elements.
00102    */
00103   void operator= (const ACE_Bounded_Stack<T> &s);
00104 
00105   /// Perform actions needed when stack goes out of scope.
00106   /**
00107    * Deallocate the memory used by the Bounded_Stack.
00108    */
00109   ~ACE_Bounded_Stack (void);
00110 
00111   // = Classic Stack operations.
00112 
00113   ///Add an element to the top of the stack.
00114   /**
00115    * Place a new item on top of the stack.  Returns -1 if the stack
00116    * is already full, 0 if the stack is not already full, and -1 if
00117    * failure occurs.
00118    */
00119   int push (const T &new_item);
00120 
00121   ///Remove an item from the top of stack.
00122   /**
00123    * Remove and return the top stack item.  Returns -1 if the stack is
00124    * already empty, 0 if the stack is not already empty, and -1 if
00125    * failure occurs.
00126    */
00127   int pop (T &item);
00128 
00129   ///Examine the contents of the top of stack.
00130   /**
00131    * Return top stack item without removing it.  Returns -1 if the
00132    * stack is already empty, 0 if the stack is not already empty, and
00133    * -1 if failure occurs.
00134    */
00135   int top (T &item) const;
00136 
00137   // = Check boundary conditions.
00138 
00139   /// Returns 1 if the container is empty, otherwise returns 0.
00140   /**
00141    * Performs constant time check to determine if the stack is empty.
00142    */
00143   int is_empty (void) const;
00144 
00145   /// Returns 1 if the container is full, otherwise returns 0.
00146   /**
00147    * Performs constant time check to determine if the stack is at capacity.
00148    */
00149   int is_full (void) const;
00150 
00151   /// The number of items in the stack.
00152   /**
00153    * Return the number of items currently in the stack.
00154    */
00155   size_t size (void) const;
00156 
00157   /// Dump the state of an object.
00158   void dump (void) const;
00159 
00160   /// Declare the dynamic allocation hooks.
00161   ACE_ALLOC_HOOK_DECLARE;
00162 
00163 private:
00164   /// Size of the dynamically allocated data.
00165   size_t size_;
00166 
00167   /// Keeps track of the current top of stack.
00168   size_t top_;
00169 
00170   /// Holds the stack's contents.
00171   T *stack_;
00172 };
00173 
00174 //----------------------------------------
00175 
00176 
00177 /**
00178  * @class ACE_Fixed_Stack
00179  *
00180  * @brief Implement a generic LIFO abstract data type.
00181  *
00182  * This implementation of a Stack uses a fixed array
00183  * with the size fixed at instantiation time.
00184  *
00185  * <b> Requirements and Performance Characteristics</b>
00186  *   - Internal Structure
00187  *       Fixed array
00188  *   - Duplicates allowed?
00189  *       Yes
00190  *   - Random access allowed?
00191  *       No
00192  *   - Search speed
00193  *       N/A
00194  *   - Insert/replace speed
00195  *       N/A
00196  *   - Iterator still valid after change to container?
00197  *       N/A
00198  *   - Frees memory for removed elements?
00199  *       No
00200  *   - Items inserted by
00201  *       Value
00202  *   - Requirements for contained type
00203  *       -# Default constructor
00204  *       -# Copy constructor
00205  *       -# operator=
00206  *
00207  */
00208 template <class T, size_t ACE_SIZE>
00209 class ACE_Fixed_Stack
00210 {
00211 public:
00212   // = Initialization, assignment, and termination methods.
00213   /// Initialize a new stack so that it is empty.
00214   /**
00215    * Initialize an empty stack.
00216    */
00217   ACE_Fixed_Stack (void);
00218 
00219   /// The copy constructor (performs initialization).
00220   /**
00221    * Initialize the stack and copy the provided stack into the current stack.
00222    */
00223   ACE_Fixed_Stack (const ACE_Fixed_Stack<T, ACE_SIZE> &s);
00224 
00225   /// Assignment operator (performs assignment).
00226   /**
00227    * Perform a deep copy of the provided stack.
00228    */
00229   void operator= (const ACE_Fixed_Stack<T, ACE_SIZE> &s);
00230 
00231   /// Perform actions needed when stack goes out of scope.
00232   /**
00233    * Destroy the stack.
00234    */
00235   ~ACE_Fixed_Stack (void);
00236 
00237   // = Classic Stack operations.
00238 
00239   ///Constant time placement of element on top of stack.
00240   /**
00241    * Place a new item on top of the stack.  Returns -1 if the stack
00242    * is already full, 0 if the stack is not already full, and -1 if
00243    * failure occurs.
00244    */
00245   int push (const T &new_item);
00246 
00247   ///Constant time removal of top of stack.
00248   /**
00249    * Remove and return the top stack item.  Returns -1 if the stack is
00250    * already empty, 0 if the stack is not already empty, and -1 if
00251    * failure occurs.
00252    */
00253   int pop (T &item);
00254 
00255   ///Constant time examination of top of stack.
00256   /**
00257    * Return top stack item without removing it.  Returns -1 if the
00258    * stack is already empty, 0 if the stack is not already empty, and
00259    * -1 if failure occurs.
00260    */
00261   int top (T &item) const;
00262 
00263   // = Check boundary conditions.
00264 
00265   /// Returns 1 if the container is empty, otherwise returns 0.
00266   /**
00267    * Performs constant time check to see if stack is empty.
00268    */
00269   int is_empty (void) const;
00270 
00271   /// Returns 1 if the container is full, otherwise returns 0.
00272   /**
00273    * Performs constant time check to see if stack is full.
00274    */
00275   int is_full (void) const;
00276 
00277   /// The number of items in the stack.
00278   /**
00279    * Constant time access to the current size of the stack.
00280    */
00281   size_t size (void) const;
00282 
00283   /// Dump the state of an object.
00284   void dump (void) const;
00285 
00286   /// Declare the dynamic allocation hooks.
00287   ACE_ALLOC_HOOK_DECLARE;
00288 
00289 private:
00290   /// Size of the allocated data.
00291   size_t size_;
00292 
00293   /// Keeps track of the current top of stack.
00294   size_t top_;
00295 
00296   /// Holds the stack's contents.
00297   T stack_[ACE_SIZE];
00298 };
00299 
00300 //----------------------------------------
00301 
00302 template<class T> class ACE_Ordered_MultiSet;
00303 template<class T> class ACE_Ordered_MultiSet_Iterator;
00304 
00305 /**
00306  * @class ACE_DNode
00307  *
00308  * @brief Implementation element in a bilinked list.
00309  */
00310 template<class T>
00311 class ACE_DNode
00312 {
00313   friend class ACE_Ordered_MultiSet<T>;
00314   friend class ACE_Ordered_MultiSet_Iterator<T>;
00315 
00316 public:
00317 
00318 # if ! defined (ACE_HAS_BROKEN_NOOP_DTORS)
00319   /// This isn't necessary, but it keeps some compilers happy.
00320   ~ACE_DNode (void);
00321 # endif /* ! defined (ACE_HAS_BROKEN_NOOP_DTORS) */
00322 
00323 private:
00324 
00325   // = Initialization methods
00326   ACE_DNode (const T &i, ACE_DNode<T> *n = 0, ACE_DNode<T> *p = 0);
00327 
00328   /// Pointer to next element in the list of {ACE_DNode}s.
00329   ACE_DNode<T> *next_;
00330 
00331   /// Pointer to previous element in the list of {ACE_DNode}s.
00332   ACE_DNode<T> *prev_;
00333 
00334   /// Current value of the item in this node.
00335   T item_;
00336 };
00337 
00338 
00339 
00340 /**
00341  * @class ACE_Unbounded_Stack
00342  *
00343  * @brief Implement a generic LIFO abstract data type.
00344  *
00345  * This implementation of an unbounded Stack uses a linked list.
00346  * If you use the {insert} or {remove} methods you should keep
00347  * in mind that duplicate entries aren't allowed.  In general,
00348  * therefore, you should avoid the use of these methods since
00349  * they aren't really part of the ADT stack.  The stack is implemented
00350  * as a doubly linked list.
00351  *
00352  * <b> Requirements and Performance Characteristics</b>
00353  *   - Internal Structure
00354  *       Double linked list
00355  *   - Duplicates allowed?
00356  *       No
00357  *   - Random access allowed?
00358  *       No
00359  *   - Search speed
00360  *       Linear
00361  *   - Insert/replace speed
00362  *       Linear
00363  *   - Iterator still valid after change to container?
00364  *       Yes
00365  *   - Frees memory for removed elements?
00366  *       Yes
00367  *   - Items inserted by
00368  *       Value
00369  *   - Requirements for contained type
00370  *       -# Default constructor
00371  *       -# Copy constructor
00372  *       -# operator=
00373  *
00374  */
00375 template <class T>
00376 class ACE_Unbounded_Stack
00377 {
00378 public:
00379   friend class ACE_Unbounded_Stack_Iterator<T>;
00380 
00381   // Trait definition.
00382   typedef ACE_Unbounded_Stack_Iterator<T> ITERATOR;
00383 
00384   // = Initialization, assignment, and termination methods.
00385   /// Initialize a new stack so that it is empty.  Use user defined
00386   /// allocation strategy if specified.
00387   /**
00388    * Initialize an empty stack using the user specified allocation strategy
00389    * if provided.
00390    */
00391   ACE_Unbounded_Stack (ACE_Allocator *the_allocator = 0);
00392 
00393   /// The copy constructor (performs initialization).
00394   /**
00395    * Initialize this stack to be an exact copy of {s}.
00396    */
00397   ACE_Unbounded_Stack (const ACE_Unbounded_Stack<T> &s);
00398 
00399   /// Assignment operator (performs assignment).
00400   /**
00401    * Perform a deep copy of the rhs into the lhs.
00402    */
00403   void operator= (const ACE_Unbounded_Stack<T> &s);
00404 
00405   /// Perform actions needed when stack goes out of scope.
00406   /**
00407    * Destroy the underlying list for the stack.
00408    */
00409   ~ACE_Unbounded_Stack (void);
00410 
00411   // = Classic Stack operations.
00412 
00413 
00414   ///Push an element onto the top of stack.
00415   /**
00416    * Place a new item on top of the stack.  Returns -1 if the stack
00417    * is already full, 0 if the stack is not already full, and -1 if
00418    * failure occurs.
00419    */
00420   int push (const T &new_item);
00421 
00422   ///Pop the top element of the stack.
00423   /**
00424    * Remove and return the top stack item.  Returns -1 if the stack is
00425    * already empty, 0 if the stack is not already empty, and -1 if
00426    * failure occurs.
00427    */
00428   int pop (T &item);
00429 
00430   ///Examine the top of the stack.
00431   /**
00432    * Return top stack item without removing it.  Returns -1 if the
00433    * stack is already empty, 0 if the stack is not already empty, and
00434    * -1 if failure occurs.
00435    */
00436   int top (T &item) const;
00437 
00438   // = Check boundary conditions.
00439 
00440   /// Returns 1 if the container is empty, otherwise returns 0.
00441   /**
00442    * Constant time check to see if the stack is empty.
00443    */
00444   int is_empty (void) const;
00445 
00446   /// Returns 1 if the container is full, otherwise returns 0.
00447   /**
00448    * Always resturns 0 since the stack is unbounded.
00449    */
00450   int is_full (void) const;
00451 
00452   // = Auxiliary methods (not strictly part of the Stack ADT).
00453 
00454   ///Linear Insert of an item.
00455   /**
00456    * Insert {new_item} into the Stack at the head (but doesn't allow
00457    * duplicates).  Returns -1 if failures occur, 1 if item is already
00458    * present (i.e., no duplicates are allowed), else 0.
00459    */
00460   int insert (const T &new_item);
00461 
00462   /// Remove @a item from the Stack.  Returns 0 if it removes the item,
00463   /// -1 if it can't find the item, and -1 if a failure occurs.
00464   /**
00465    * Linear remove operation.
00466    */
00467   int remove (const T &item);
00468 
00469   /// Finds if @a item occurs the set.  Returns 0 if finds, else -1.
00470   /**
00471    * Linear find operation.
00472    */
00473   int find (const T &item) const;
00474 
00475   /// The number of items in the stack.
00476   /**
00477    * Constant time access to the current stack size.
00478    */
00479   size_t size (void) const;
00480 
00481   /// Dump the state of an object.
00482   void dump (void) const;
00483 
00484   /// Declare the dynamic allocation hooks.
00485   ACE_ALLOC_HOOK_DECLARE;
00486 
00487 private:
00488   /// Delete all the nodes in the stack.
00489   void delete_all_nodes (void);
00490 
00491   /// Copy all nodes from {s} to {this}.
00492   void copy_all_nodes (const ACE_Unbounded_Stack<T> &s);
00493 
00494   /// Head of the linked list of Nodes.
00495   ACE_Node<T> *head_;
00496 
00497   /// Current size of the stack.
00498   size_t cur_size_;
00499 
00500   /// Allocation strategy of the stack.
00501   ACE_Allocator *allocator_;
00502 };
00503 
00504 /**
00505  * @class ACE_Unbounded_Stack_Iterator
00506  *
00507  * @brief Implement an iterator over an unbounded Stack.
00508  */
00509 template <class T>
00510 class ACE_Unbounded_Stack_Iterator
00511 {
00512 public:
00513   // = Initialization method.
00514   /// Move to the first element in the {stack}.
00515   ACE_Unbounded_Stack_Iterator (ACE_Unbounded_Stack<T> &stack);
00516 
00517   // = Iteration methods.
00518 
00519   /// Pass back the @a next_item that hasn't been seen in the Stack.
00520   /// Returns 0 when all items have been seen, else 1.
00521   int next (T *&next_item);
00522 
00523   /// Move forward by one element in the Stack.  Returns 0 when all the
00524   /// items in the Stack have been seen, else 1.
00525   int advance (void);
00526 
00527   /// Move to the first element in the Stack.  Returns 0 if the
00528   /// Stack is empty, else 1.
00529   int first (void);
00530 
00531   /// Returns 1 when all items have been seen, else 0.
00532   int done (void) const;
00533 
00534   /// Dump the state of an object.
00535   void dump (void) const;
00536 
00537   /// Declare the dynamic allocation hooks.
00538   ACE_ALLOC_HOOK_DECLARE;
00539 
00540 private:
00541   /// Pointer to the current node in the iteration.
00542   ACE_Node<T> *current_;
00543 
00544   /// Pointer to the Stack we're iterating over.
00545   ACE_Unbounded_Stack<T> &stack_;
00546 };
00547 
00548 template <class T>
00549 class ACE_Double_Linked_List;
00550 
00551 /**
00552  * @class ACE_Double_Linked_List_Iterator_Base
00553  *
00554  * @brief Implements a common base class for iterators for a double
00555  * linked list ADT
00556  */
00557 template <class T>
00558 class ACE_Double_Linked_List_Iterator_Base
00559 {
00560 public:
00561   // = Iteration methods.
00562 
00563   /// Passes back the {entry} under the iterator. Returns 0 if the
00564   /// iteration has completed, otherwise 1
00565   int next (T *&) const;
00566 
00567   /**
00568    * @deprecated Return the address of next (current) unvisited item in
00569    * the list. 0 if there is no more element available.
00570    */
00571   T *next (void) const;
00572 
00573   /// Returns 1 when all items have been seen, else 0.
00574   int done (void) const;
00575 
00576   /// STL-like iterator dereference operator: returns a reference
00577   /// to the node underneath the iterator.
00578   T & operator* (void) const ;
00579 
00580   /**
00581    * Retasks the iterator to iterate over a new
00582    * Double_Linked_List. This allows clients to reuse an iterator
00583    * without incurring the constructor overhead. If you do use this,
00584    * be aware that if there are more than one reference to this
00585    * iterator, the other "clients" may be very bothered when their
00586    * iterator changes.  @@ Here be dragons. Comments?
00587    */
00588   void reset (ACE_Double_Linked_List<T> &);
00589 
00590   /// Declare the dynamic allocation hooks.
00591   ACE_ALLOC_HOOK_DECLARE;
00592 
00593 protected:
00594   // = Initialization methods.
00595 
00596   /// Constructor
00597   ACE_Double_Linked_List_Iterator_Base (const ACE_Double_Linked_List<T> &);
00598 
00599   /// Copy constructor.
00600   ACE_Double_Linked_List_Iterator_Base (const
00601                                         ACE_Double_Linked_List_Iterator_Base<T>
00602                                         &iter);
00603 
00604   // = Iteration methods.
00605   /**
00606    * Move to the first element of the list. Returns 0 if the list is
00607    * empty, else 1.
00608    * @note the head of the ACE_DLList is actually a null entry, so the
00609    * first element is actually the 2n'd entry
00610    */
00611   int go_head (void);
00612 
00613   /// Move to the last element of the list. Returns 0 if the list is
00614   /// empty, else 1.
00615   int go_tail (void);
00616 
00617   /**
00618    * Check if we reach the end of the list.  Can also be used to get
00619    * the *current* element in the list.  Return the address of the
00620    * current item if there are still elements left , 0 if we run out
00621    * of element.
00622    */
00623   T *not_done (void) const ;
00624 
00625   /// Advance to the next element in the list.  Return the address of the
00626   /// next element if there are more, 0 otherwise.
00627   T *do_advance (void);
00628 
00629   /// Retreat to the previous element in the list.  Return the address
00630   /// of the previous element if there are more, 0 otherwise.
00631   T *do_retreat (void);
00632 
00633   /// Dump the state of an object.
00634   void dump_i (void) const;
00635 
00636   /// Remember where we are.
00637   T *current_;
00638 
00639   const ACE_Double_Linked_List<T> *dllist_;
00640 };
00641 
00642 /**
00643  * @class ACE_Double_Linked_List_Iterator
00644  *
00645  * @brief Implements an iterator for a double linked list ADT
00646  *
00647  * Iterate thru the double-linked list.  This class provides
00648  * an interface that let users access the internal element
00649  * addresses directly. Notice {class T} must declare
00650  * ACE_Double_Linked_List&lt;T&gt;,
00651  * ACE_Double_Linked_List_Iterator_Base &lt;T&gt; and
00652  * ACE_Double_Linked_List_Iterator as friend classes and class T
00653  * should also have data members T* next_ and T* prev_.
00654  */
00655 template <class T>
00656 class ACE_Double_Linked_List_Iterator : public ACE_Double_Linked_List_Iterator_Base <T>
00657 {
00658 public:
00659   // = Initialization method.
00660   ACE_Double_Linked_List_Iterator (const ACE_Double_Linked_List<T> &);
00661 
00662   /**
00663    * Retasks the iterator to iterate over a new
00664    * Double_Linked_List. This allows clients to reuse an iterator
00665    * without incurring the constructor overhead. If you do use this,
00666    * be aware that if there are more than one reference to this
00667    * iterator, the other "clients" may be very bothered when their
00668    * iterator changes.
00669    * @@ Here be dragons. Comments?
00670    */
00671   void reset (ACE_Double_Linked_List<T> &);
00672 
00673   /// Move to the first element in the list.  Returns 0 if the
00674   /// list is empty, else 1.
00675   int first (void);
00676 
00677   /// Move forward by one element in the list.  Returns 0 when all the
00678   /// items in the list have been seen, else 1.
00679   int advance (void);
00680 
00681   /**
00682    * Advance the iterator while removing the original item from the
00683    * list.  Return a pointer points to the original (removed) item.
00684    * If {dont_remove} equals 0, this function behaves like {advance}
00685    * but return 0 (NULL) instead.
00686    */
00687   T* advance_and_remove (int dont_remove);
00688 
00689   // = STL-style iteration methods
00690 
00691   /// Prefix advance.
00692   ACE_Double_Linked_List_Iterator<T> & operator++ (void);
00693 
00694   /// Postfix advance.
00695   ACE_Double_Linked_List_Iterator<T> operator++ (int);
00696 
00697   /// Prefix reverse.
00698   ACE_Double_Linked_List_Iterator<T> & operator-- (void);
00699 
00700   /// Postfix reverse.
00701   ACE_Double_Linked_List_Iterator<T> operator-- (int);
00702 
00703   /// Dump the state of an object.
00704   void dump (void) const;
00705 
00706   /// Declare the dynamic allocation hooks.
00707   ACE_ALLOC_HOOK_DECLARE;
00708 };
00709 
00710 /**
00711  * @class ACE_Double_Linked_List_Reverse_Iterator
00712  *
00713  * @brief Implements a reverse iterator for a double linked list ADT
00714  *
00715  * Iterate backwards over the double-linked list.  This class
00716  * provide an interface that let users access the internal
00717  * element addresses directly, which seems to break the
00718  * encapsulation.  Notice {class T} must declare
00719  * ACE_Double_Linked_List&lt;T&gt;,
00720  * ACE_Double_Linked_List_Iterator_Base &lt;T&gt; and
00721  * ACE_Double_Linked_List_Iterator as friend classes and class T
00722  * should also have data members T* next_ and T* prev_.
00723  */
00724 template <class T>
00725 class ACE_Double_Linked_List_Reverse_Iterator : public ACE_Double_Linked_List_Iterator_Base <T>
00726 {
00727 public:
00728   // = Initialization method.
00729   ACE_Double_Linked_List_Reverse_Iterator (ACE_Double_Linked_List<T> &);
00730 
00731   /**
00732    * Retasks the iterator to iterate over a new
00733    * Double_Linked_List. This allows clients to reuse an iterator
00734    * without incurring the constructor overhead. If you do use this,
00735    * be aware that if there are more than one reference to this
00736    * iterator, the other "clients" may be very bothered when their
00737    * iterator changes.
00738    * @@ Here be dragons. Comments?
00739    */
00740   void reset (ACE_Double_Linked_List<T> &);
00741 
00742   /// Move to the first element in the list.  Returns 0 if the
00743   /// list is empty, else 1.
00744   int first (void);
00745 
00746   /// Move forward by one element in the list.  Returns 0 when all the
00747   /// items in the list have been seen, else 1.
00748   int advance (void);
00749 
00750   /**
00751    * Advance the iterator while removing the original item from the
00752    * list.  Return a pointer points to the original (removed) item.
00753    * If {dont_remove} equals 0, this function behaves like {advance}
00754    * but return 0 (NULL) instead.
00755    */
00756   T* advance_and_remove (int dont_remove);
00757 
00758   // = STL-style iteration methods
00759 
00760   /// Prefix advance.
00761   ACE_Double_Linked_List_Reverse_Iterator<T> & operator++ (void);
00762 
00763   /// Postfix advance.
00764   ACE_Double_Linked_List_Reverse_Iterator<T> operator++ (int);
00765 
00766   /// Prefix reverse.
00767   ACE_Double_Linked_List_Reverse_Iterator<T> & operator-- (void);
00768 
00769   /// Postfix reverse.
00770   ACE_Double_Linked_List_Reverse_Iterator<T> operator-- (int);
00771 
00772   /// Dump the state of an object.
00773   void dump (void) const;
00774 
00775   /// Declare the dynamic allocation hooks.
00776   ACE_ALLOC_HOOK_DECLARE;
00777 };
00778 
00779 
00780 /**
00781  * @class ACE_Double_Linked_List
00782  *
00783  * @brief A double-linked list implementation.
00784  *
00785  * This implementation of an unbounded double-linked list uses a
00786  * circular linked list with a dummy node.  It is pretty much
00787  * like the {ACE_Unbounded_Queue} except that it allows removing
00788  * of a specific element from a specific location.
00789  * Notice that this class is an implementation of a very simple
00790  * data structure. This is *NOT* a container class.  You can use the
00791  * class to implement other contains classes but it is *NOT* a
00792  * general purpose container class.
00793  * The parameter class *MUST* have members T* prev and T* next
00794  * and users of this class are responsible to follow the general
00795  * rules of using double-linked lists to maintaining the list
00796  * integrity.
00797  * If you need a double linked container class, use the DLList
00798  * class which is a container but delegates to the Double_Linked_List
00799  * class.
00800  *
00801  * <b> Requirements and Performance Characteristics</b>
00802  *   - Internal Structure
00803  *       Double Linked List
00804  *   - Duplicates allowed?
00805  *       Yes
00806  *   - Random access allowed?
00807  *       No
00808  *   - Search speed
00809  *       N/A
00810  *   - Insert/replace speed
00811  *       Linear
00812  *   - Iterator still valid after change to container?
00813  *       Yes
00814  *   - Frees memory for removed elements?
00815  *       No
00816  *   - Items inserted by
00817  *       Value
00818  *   - Requirements for contained type
00819  *       -# Default constructor
00820  *       -# Copy constructor
00821  *       -# operator=
00822  *
00823  */
00824 template <class T>
00825 class ACE_Double_Linked_List
00826 {
00827 public:
00828   friend class ACE_Double_Linked_List_Iterator_Base<T>;
00829   friend class ACE_Double_Linked_List_Iterator<T>;
00830   friend class ACE_Double_Linked_List_Reverse_Iterator<T>;
00831 
00832   // Trait definition.
00833   typedef ACE_Double_Linked_List_Iterator<T> ITERATOR;
00834   typedef ACE_Double_Linked_List_Reverse_Iterator<T> REVERSE_ITERATOR;
00835 
00836   // = Initialization and termination methods.
00837   /// construction.  Use user specified allocation strategy
00838   /// if specified.
00839   /**
00840    * Initialize an empy list using the allocation strategy specified by the user.
00841    * If none is specified, then use default allocation strategy.
00842    */
00843   ACE_Double_Linked_List (ACE_Allocator *the_allocator = 0);
00844 
00845   /// Copy constructor.
00846   /**
00847    * Create a double linked list that is a copy of the provided
00848    * parameter.
00849    */
00850   ACE_Double_Linked_List (const ACE_Double_Linked_List<T> &);
00851 
00852   /// Assignment operator.
00853   /**
00854    * Perform a deep copy of the provided list by first deleting the nodes of the
00855    * lhs and then copying the nodes of the rhs.
00856    */
00857   void operator= (const ACE_Double_Linked_List<T> &);
00858 
00859   /// Destructor.
00860   /**
00861    * Clean up the memory allocated for the nodes of the list.
00862    */
00863   ~ACE_Double_Linked_List (void);
00864 
00865   // = Check boundary conditions.
00866 
00867   /// Returns 1 if the container is empty, 0 otherwise.
00868   /**
00869    * Performs constant time check to determine if the list is empty.
00870    */
00871   int is_empty (void) const;
00872 
00873   /// The list is unbounded, so this always returns 0.
00874   /**
00875    * Since the list is unbounded, the method simply returns 0.
00876    */
00877   int is_full (void) const;
00878 
00879   // = Classic queue operations.
00880 
00881   /// Adds <new_item> to the tail of the list. Returns the new item
00882   /// that was inserted.
00883   /**
00884    * Provides constant time insertion at the end of the list structure.
00885    */
00886   T *insert_tail (T *new_item);
00887 
00888   /// Adds <new_item> to the head of the list.Returns the new item that
00889   /// was inserted.
00890   /**
00891    * Provides constant time insertion at the head of the list.
00892    */
00893   T *insert_head (T *new_item);
00894 
00895   /// Removes the head of the list and returns a pointer to that item.
00896   /**
00897    * Removes and returns the first {item} in the list.  Returns
00898    * internal node's address on success, 0 if the queue was empty.
00899    * This method will *not* free the internal node.
00900    */
00901   T* delete_head (void);
00902 
00903   /// Removes the tail of the list and returns a pointer to that item.
00904   /**
00905    * Removes and returns the last {item} in the list.  Returns
00906    * internal nodes's address on success, 0 if the queue was
00907    * empty. This method will *not* free the internal node.
00908    */
00909   T *delete_tail (void);
00910 
00911   // = Additional utility methods.
00912 
00913   ///Empty the list.
00914   /**
00915    * Reset the {ACE_Double_Linked_List} to be empty.
00916    * Notice that since no one is interested in the items within,
00917    * This operation will delete all items.
00918    */
00919   void reset (void);
00920 
00921   /// Get the {slot}th element in the set.  Returns -1 if the element
00922   /// isn't in the range {0..{size} - 1}, else 0.
00923   /**
00924    * Iterates through the list to the desired index and assigns the provides pointer
00925    * with the address of the node occupying that index.
00926    */
00927   int get (T *&item, size_t slot = 0);
00928 
00929   /// The number of items in the queue.
00930   /**
00931    * Constant time call to return the current size of the list.
00932    */
00933   size_t size (void) const;
00934 
00935   /// Dump the state of an object.
00936   void dump (void) const;
00937 
00938   /// Use DNode address directly.
00939   /**
00940    * Constant time removal of an item from the list using it's address.
00941    */
00942   int remove (T *n);
00943 
00944   /// Declare the dynamic allocation hooks.
00945   ACE_ALLOC_HOOK_DECLARE;
00946 
00947 protected:
00948   /// Delete all the nodes in the list.
00949   /**
00950    * Removes and deallocates memory for all of the list nodes.
00951    */
00952   void delete_nodes (void);
00953 
00954   /// Copy nodes from {rhs} into this list.
00955   /**
00956    * Copy the elements of the provided list by allocated new nodes and assigning
00957    * them with the proper data.
00958    */
00959   void copy_nodes (const ACE_Double_Linked_List<T> &rhs);
00960 
00961   /// Setup header pointer.  Called after we create the head node in ctor.
00962   /**
00963    * Initialize the head pointer so that the list has a dummy node.
00964    */
00965   void init_head (void);
00966 
00967   ///Constant time insert a new item into the list structure.
00968   /**
00969    * Insert a @a new_item into the list.  It will be added before
00970    * or after @a old_item.  Default is to insert the new item *after*
00971    * {head_}.  Return 0 if succeed, -1 if error occured.
00972    */
00973   int insert_element (T *new_item,
00974                       int before = 0,
00975                       T *old_item = 0);
00976 
00977   ///Constant time delete an item from the list structure.
00978   /**
00979    * Remove @a item from the list.  Return 0 if succeed, -1 otherwise.
00980    * Notice that this function checks if item is {head_} and either its
00981    * {next_} or {prev_} is NULL.  The function resets item's {next_} and
00982    * {prev_} to 0 to prevent clobbering the double-linked list if a user
00983    * tries to remove the same node again.
00984    */
00985   int remove_element (T *item);
00986 
00987   /// Head of the circular double-linked list.
00988   T *head_;
00989 
00990   /// Size of this list.
00991   size_t size_;
00992 
00993   /// Allocation Strategy of the queue.
00994   ACE_Allocator *allocator_;
00995 };
00996 
00997 
00998 template <class T> class ACE_DLList;
00999 template <class T> class ACE_DLList_Iterator;
01000 template <class T> class ACE_DLList_Reverse_Iterator;
01001 
01002 typedef ACE_Double_Linked_List<ACE_DLList_Node> ACE_DLList_Base;
01003 
01004 //typedef ACE_Double_Linked_List_Iterator <ACE_DLList_Node>
01005 //        ACE_DLList_Iterator_Base;
01006 //typedef ACE_Double_Linked_List_Reverse_Iterator <ACE_DLList_Node>
01007 //        ACE_DLList_Reverse_Iterator_Base;
01008 //@@ These two typedefs (inherited from James Hu's original design)
01009 // have been removed because Sun CC 4.2 had problems with it. I guess
01010 // having the DLList_Iterators inheriting from a class which is
01011 // actually a typedef leads to problems. #define'ing rather than
01012 // typedef'ing worked, but as per Carlos's reccomendation, I'm just
01013 // replacing all references to the base classes with their actual
01014 // type.  Matt Braun (6/15/99)
01015 
01016 /**
01017  * @class ACE_DLList
01018  *
01019  * @brief A double-linked list container class.
01020  *
01021  * This implementation uses ACE_Double_Linked_List to perform
01022  * the logic behind this container class.  It delegates all of its
01023  * calls to ACE_Double_Linked_List.
01024  */
01025 template <class T>
01026 class ACE_DLList : public ACE_DLList_Base
01027 {
01028   friend class ACE_DLList_Node;
01029   friend class ACE_Double_Linked_List_Iterator<T>;
01030   friend class ACE_DLList_Iterator<T>;
01031   friend class ACE_DLList_Reverse_Iterator<T>;
01032 
01033 public:
01034 
01035   /// Delegates to ACE_Double_Linked_List.
01036   void operator= (const ACE_DLList<T> &l);
01037 
01038   // = Classic queue operations.
01039 
01040   /// Delegates to ACE_Double_Linked_List.
01041   T *insert_tail (T *new_item);
01042 
01043   /// Delegates to ACE_Double_Linked_List.
01044   T *insert_head (T *new_item);
01045 
01046   /// Delegates to ACE_Double_Linked_List.
01047   T *delete_head (void);
01048 
01049   /// Delegates to ACE_Double_Linked_List.
01050   T *delete_tail (void);
01051 
01052   // = Additional utility methods.
01053 
01054   /**
01055    * Delegates to {ACE_Double_Linked_List}, but where
01056    * {ACE_Double_Linked_List} returns the node as the item, this get
01057    * returns the contents of the node in item.
01058    */
01059   int get (T *&item, size_t slot = 0);
01060 
01061   /// Delegates to ACE_Double_Linked_List.
01062   void dump (void) const;
01063 
01064   /// Delegates to ACE_Double_Linked_List.
01065   int remove (ACE_DLList_Node *n);
01066 
01067   // = Initialization and termination methods.
01068 
01069   /// Delegates to ACE_Double_Linked_List.
01070   ACE_DLList (ACE_Allocator *the_allocator = 0);
01071 
01072   /// Delegates to ACE_Double_Linked_List.
01073   ACE_DLList (const ACE_DLList<T> &l);
01074 
01075   /// Deletes the list starting from the head.
01076   ~ACE_DLList (void);
01077 };
01078 
01079 /**
01080  * @class ACE_DLList_Iterator
01081  *
01082  * @brief A double-linked list container class iterator.
01083  *
01084  * This implementation uses ACE_Double_Linked_List_Iterator to
01085  * perform the logic behind this container class.  It delegates
01086  * all of its calls to ACE_Double_Linked_List_Iterator.
01087  */
01088 template <class T>
01089 class ACE_DLList_Iterator : public ACE_Double_Linked_List_Iterator <ACE_DLList_Node>
01090 {
01091 
01092   friend class ACE_DLList<T>;
01093   friend class ACE_DLList_Node;
01094 
01095 public:
01096 
01097   // = Initialization method.
01098   ACE_DLList_Iterator (ACE_DLList<T> &l);
01099 
01100   /**
01101    * Retasks the iterator to iterate over a new
01102    * Double_Linked_List. This allows clients to reuse an iterator
01103    * without incurring the constructor overhead. If you do use this,
01104    * be aware that if there are more than one reference to this
01105    * iterator, the other "clients" may be very bothered when their
01106    * iterator changes.
01107    * @@ Here be dragons. Comments?
01108    */
01109   void reset (ACE_DLList<T> &l);
01110 
01111   // = Iteration methods.
01112   /// Move forward by one element in the list.  Returns 0 when all the
01113   /// items in the list have been seen, else 1.
01114   int advance (void);
01115 
01116   /// Pass back the {next_item} that hasn't been seen in the list.
01117   /// Returns 0 when all items have been seen, else 1.
01118   int next (T *&);
01119 
01120   /**
01121    * @deprecated Delegates to ACE_Double_Linked_List_Iterator, except that
01122    * whereas the Double_Linked_List version of next returns the node, this next
01123    * returns the contents of the node
01124    */
01125   T *next (void) const;
01126 
01127   /**
01128    * Removes the current item (i.e., {next}) from the list.
01129    * Note that DLList iterators do not support {advance_and_remove}
01130    * directly (defined in its base class) and you will need to
01131    * release the element returned by it.
01132    */
01133   int remove (void);
01134 
01135   /// Delegates to ACE_Double_Linked_List_Iterator.
01136   void dump (void) const;
01137 
01138 private:
01139   ACE_DLList<T> *list_;
01140 };
01141 
01142 /**
01143  * @class ACE_DLList_Reverse_Iterator
01144  *
01145  * @brief A double-linked list container class iterator.
01146  *
01147  * This implementation uses ACE_Double_Linked_List_Iterator to
01148  * perform the logic behind this container class.  It delegates
01149  * all of its calls to ACE_Double_Linked_List_Iterator.
01150  */
01151 template <class T>
01152 class ACE_DLList_Reverse_Iterator : public ACE_Double_Linked_List_Reverse_Iterator <ACE_DLList_Node>
01153 {
01154 
01155   friend class ACE_DLList<T>;
01156   friend class ACE_DLList_Node;
01157 
01158 public:
01159 
01160   // = Initialization method.
01161   ACE_DLList_Reverse_Iterator (ACE_DLList<T> &l);
01162 
01163   /**
01164    * Retasks the iterator to iterate over a new
01165    * Double_Linked_List. This allows clients to reuse an iterator
01166    * without incurring the constructor overhead. If you do use this,
01167    * be aware that if there are more than one reference to this
01168    * iterator, the other "clients" may be very bothered when their
01169    * iterator changes.
01170    * @@ Here be dragons. Comments?
01171    */
01172   void reset (ACE_DLList<T> &l);
01173 
01174   // = Iteration methods.
01175   /// Move forward by one element in the list.  Returns 0 when all the
01176   /// items in the list have been seen, else 1.
01177   int advance (void);
01178 
01179   /// Pass back the {next_item} that hasn't been seen in the list.
01180   /// Returns 0 when all items have been seen, else 1.
01181   int next (T *&);
01182 
01183   /// @deprecated Delegates to ACE_Double_Linked_List_Iterator.
01184   T *next (void) const;
01185 
01186   /// Removes the current item (i.e., {next}) from the list.
01187   /// Note that DLList iterators do not support {advance_and_remove}
01188   /// directly (defined in its base class) and you will need to
01189   /// release the element returned by it.
01190   int remove (void);
01191 
01192   /// Delegates to ACE_Double_Linked_List_Iterator.
01193   void dump (void) const;
01194 
01195 private:
01196   ACE_DLList<T> *list_;
01197 };
01198 
01199 // Forward declaration.
01200 template <class T, size_t ACE_SIZE>
01201 class ACE_Fixed_Set;
01202 
01203 /**
01204  * @class ACE_Fixed_Set_Iterator_Base
01205  *
01206  * @brief Implements a common base class for iterators for a unordered set.
01207  */
01208 template <class T, size_t ACE_SIZE>
01209 class ACE_Fixed_Set_Iterator_Base
01210 {
01211 public:
01212   // = Iteration methods.
01213 
01214   /// Pass back the {next_item} that hasn't been seen in the Set.
01215   /// Returns 0 when all items have been seen, else 1.
01216   int next (T *&next_item);
01217 
01218   /// Move forward by one element in the set.  Returns 0 when all the
01219   /// items in the set have been seen, else 1.
01220   int advance (void);
01221 
01222   /// Move to the first element in the set.  Returns 0 if the
01223   /// set is empty, else 1.
01224   int first (void);
01225 
01226   /// Returns 1 when all items have been seen, else 0.
01227   int done (void) const;
01228 
01229   /// Declare the dynamic allocation hooks.
01230   ACE_ALLOC_HOOK_DECLARE;
01231 
01232 protected:
01233   // = Initialization method.
01234   ACE_Fixed_Set_Iterator_Base (ACE_Fixed_Set<T, ACE_SIZE> &s);
01235 
01236   /// Set we are iterating over.
01237   ACE_Fixed_Set<T, ACE_SIZE> &s_;
01238 
01239   /// How far we've advanced over the set.
01240   ssize_t next_;
01241 
01242   /// The number of non free items that the iterator had pointed at.
01243   size_t iterated_items_;
01244 
01245   /// Dump the state of an object.
01246   void dump_i (void) const;
01247 
01248   /// Pass back the {next_item} that hasn't been seen in the Set.
01249   /// Returns 0 when all items have been seen, else 1.
01250   int next_i (T *&next_item);
01251 };
01252 
01253 /**
01254  * @class ACE_Fixed_Set_Iterator
01255  *
01256  * @brief Iterates through an unordered set.
01257  *
01258  * This implementation of an unordered set uses a fixed array.
01259  * Allows deletions while iteration is occurring.
01260  */
01261 template <class T, size_t ACE_SIZE>
01262 class ACE_Fixed_Set_Iterator : public ACE_Fixed_Set_Iterator_Base <T, ACE_SIZE>
01263 {
01264 public:
01265   // = Initialization method.
01266   ACE_Fixed_Set_Iterator (ACE_Fixed_Set<T, ACE_SIZE> &s);
01267 
01268   // = Iteration methods.
01269 
01270   /// Pass back the {next_item} that hasn't been seen in the Set.
01271   /// Returns 0 when all items have been seen, else 1.
01272   int next (T *&next_item);
01273 
01274   /// Dump the state of an object.
01275   void dump (void) const;
01276 
01277   /// Remove the item where the itearetor is located at.
01278   /// Returns 1 if it removes a item, else 0.
01279   /// Pass back the removed {item}.
01280   int remove (T *&item);
01281 
01282   /// STL-like iterator dereference operator: returns a reference
01283   /// to the node underneath the iterator.
01284   T & operator* (void);
01285 
01286   /// Declare the dynamic allocation hooks.
01287   ACE_ALLOC_HOOK_DECLARE;
01288 };
01289 
01290 /**
01291  * @class ACE_Fixed_Set_Const_Iterator
01292  *
01293  * @brief Iterates through a const unordered set.
01294  *
01295  * This implementation of an unordered set uses a fixed array.
01296  */
01297 template <class T, size_t ACE_SIZE>
01298 class ACE_Fixed_Set_Const_Iterator : public ACE_Fixed_Set_Iterator_Base <T, ACE_SIZE>
01299 {
01300 public:
01301   // = Initialization method.
01302   ACE_Fixed_Set_Const_Iterator (const ACE_Fixed_Set<T, ACE_SIZE> &s);
01303 
01304   // = Iteration methods.
01305 
01306   /// Pass back the {next_item} that hasn't been seen in the Set.
01307   /// Returns 0 when all items have been seen, else 1.
01308   int next (const T *&next_item);
01309 
01310   /// Dump the state of an object.
01311   void dump (void) const;
01312 
01313   /// STL-like iterator dereference operator: returns a reference
01314   /// to the node underneath the iterator.
01315   const T & operator* (void) const ;
01316 
01317   /// Declare the dynamic allocation hooks.
01318   ACE_ALLOC_HOOK_DECLARE;
01319 };
01320 
01321 /**
01322  * @class ACE_Fixed_Set
01323  *
01324  * @brief Implement a simple unordered set of {T} with maximum {ACE_SIZE}.
01325  *
01326  * This implementation of an unordered set uses a fixed array.
01327  * It does not allow duplicate members.  The set provides linear insertion/deletion
01328  * operations.
01329  *
01330  * <b> Requirements and Performance Characteristics</b>
01331  *   - Internal Structure
01332  *       Fixed array
01333  *   - Duplicates allowed?
01334  *       No
01335  *   - Random access allowed?
01336  *       No
01337  *   - Search speed
01338  *       Linear
01339  *   - Insert/replace speed
01340  *       Linear
01341  *   - Iterator still valid after change to container?
01342  *       Yes
01343  *   - Frees memory for removed elements?
01344  *       No
01345  *   - Items inserted by
01346  *       Value
01347  *   - Requirements for contained type
01348  *       -# Default constructor
01349  *       -# Copy constructor
01350  *       -# operator=
01351  *       -# operator==
01352  *
01353  */
01354 template <class T, size_t ACE_SIZE>
01355 class ACE_Fixed_Set
01356 {
01357 public:
01358   friend class ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>;
01359   friend class ACE_Fixed_Set_Iterator<T, ACE_SIZE>;
01360   friend class ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>;
01361 
01362   // Trait definitions.
01363   typedef ACE_Fixed_Set_Iterator<T, ACE_SIZE> ITERATOR;
01364   typedef ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE> CONST_ITERATOR;
01365 
01366   // = Initialization and termination methods.
01367   /// Default Constructor.
01368   /**
01369    * Creates an empy set
01370    */
01371   ACE_Fixed_Set (void);
01372 
01373   /// Copy constructor.
01374   /**
01375    * Initializes a set to be a copy of the set parameter.
01376    */
01377   ACE_Fixed_Set (const ACE_Fixed_Set<T, ACE_SIZE> &);
01378 
01379   /// Assignment operator.
01380   /**
01381    * Deep copy of one set to another.
01382    */
01383   void operator= (const ACE_Fixed_Set<T, ACE_SIZE> &);
01384 
01385   /// Destructor.
01386   /**
01387    * Destroys a set.
01388    */
01389   ~ACE_Fixed_Set (void);
01390 
01391   // = Check boundary conditions.
01392 
01393   /// Returns 1 if the container is empty, otherwise returns 0.
01394   /**
01395    * Performs constant time check to determine if a set is empty.
01396    */
01397   int is_empty (void) const;
01398 
01399   /// Returns 1 if the container is full, otherwise returns 0.
01400   /**
01401    * Performs a constant time check to see if the set is full.
01402    */
01403   int is_full (void) const;
01404 
01405   // = Classic unordered set operations.
01406 
01407   ///Linear time insertion of an item unique to the set.
01408   /**
01409    * Insert @a new_item into the set (doesn't allow duplicates).
01410    * Returns -1 if failures occur, 1 if item is already present, else
01411    * 0.
01412    */
01413   int insert (const T &new_item);
01414 
01415   ///Linear time removal operation of an item.
01416   /**
01417    * Remove first occurrence of {item} from the set.  Returns 0 if
01418    * it removes the item, -1 if it can't find the item, and -1 if a
01419    * failure occurs.  Removal doesn't reclaim memory for the @a item.
01420    */
01421   int remove (const T &item);
01422 
01423   /// Finds if @a item occurs in the set.  Returns 0 if finds, else -1.
01424   /**
01425    * Performs a linear find operation for the specified @a item.
01426    */
01427   int find (const T &item) const;
01428 
01429   /// Size of the set.
01430   /**
01431    * Returns the current size of the set.
01432    */
01433   size_t size (void) const;
01434 
01435   /// Dump the state of an object.
01436   void dump (void) const;
01437 
01438   /// Declare the dynamic allocation hooks.
01439   ACE_ALLOC_HOOK_DECLARE;
01440 
01441 private:
01442   /// Holds the contents of the set.
01443   struct
01444   {
01445     /// Item in the set.
01446     T item_;
01447 
01448     /// Keeps track of whether this item is in use or not.
01449     int is_free_;
01450   } search_structure_[ACE_SIZE];
01451 
01452   /// Current size of the set.
01453   size_t cur_size_;
01454 
01455   /// Maximum size of the set.
01456   size_t max_size_;
01457 };
01458 
01459 // Forward declaration.
01460 template <class T>
01461 class ACE_Bounded_Set;
01462 
01463 /**
01464  * @class ACE_Bounded_Set_Iterator
01465  *
01466  * @brief Iterates through an unordered set.
01467  *
01468  * This implementation of an unordered set uses a Bounded array.
01469  * Allows deletions while iteration is occurring.
01470  */
01471 template <class T>
01472 class ACE_Bounded_Set_Iterator
01473 {
01474 public:
01475   // = Initialization method.
01476   ACE_Bounded_Set_Iterator (ACE_Bounded_Set<T> &s);
01477 
01478   // = Iteration methods.
01479 
01480   /// Pass back the {next_item} that hasn't been seen in the Set.
01481   /// Returns 0 when all items have been seen, else 1.
01482   int next (T *&next_item);
01483 
01484   /// Move forward by one element in the set.  Returns 0 when all the
01485   /// items in the set have been seen, else 1.
01486   int advance (void);
01487 
01488   /// Move to the first element in the set.  Returns 0 if the
01489   /// set is empty, else 1.
01490   int first (void);
01491 
01492   /// Returns 1 when all items have been seen, else 0.
01493   int done (void) const;
01494 
01495   /// Dump the state of an object.
01496   void dump (void) const;
01497 
01498   /// Declare the dynamic allocation hooks.
01499   ACE_ALLOC_HOOK_DECLARE;
01500 
01501 private:
01502   /// Set we are iterating over.
01503   ACE_Bounded_Set<T> &s_;
01504 
01505   /// How far we've advanced over the set.
01506   ssize_t next_;
01507 };
01508 
01509 
01510 /**
01511  * @class ACE_Bounded_Set
01512  *
01513  * @brief Implement a simple unordered set of {T} with maximum
01514  * set at creation time.
01515  *
01516  * This implementation of an unordered set uses a Bounded array.
01517  * This implementation does not allow duplicates.  It provides
01518  * linear insert/remove/find operations.  Insertion/removal does not
01519  * invalidate iterators, but caution should be taken to ensure
01520  * expected behavior.  Once initialized, the object has a maximum size
01521  * which can only be increased by the assignment of another larger Bounded_Set.
01522  *
01523  * <b> Requirements and Performance Characteristics</b>
01524  *   - Internal Structure
01525  *       Bounded array which can grow via assignment
01526  *   - Duplicates allowed?
01527  *       No
01528  *   - Random access allowed?
01529  *       No
01530  *   - Search speed
01531  *       Linear
01532  *   - Insert/replace speed
01533  *       Linear
01534  *   - Iterator still valid after change to container?
01535  *       Yes
01536  *   - Frees memory for removed elements?
01537  *       No
01538  *   - Items inserted by
01539  *       Value
01540  *   - Requirements for contained type
01541  *       -# Default constructor
01542  *       -# Copy constructor
01543  *       -# operator=
01544  *       -# operator==
01545  *
01546  */
01547 template <class T>
01548 class ACE_Bounded_Set
01549 {
01550 public:
01551   friend class ACE_Bounded_Set_Iterator<T>;
01552 
01553   // Trait definition.
01554   typedef ACE_Bounded_Set_Iterator<T> ITERATOR;
01555 
01556   enum
01557   {
01558     DEFAULT_SIZE = 10
01559   };
01560 
01561   // = Initialization and termination methods.
01562   /// Construct a Bounded_Set using the default size.
01563   /**
01564    * The default constructor initializes the Bounded_Set to a maximum size
01565    * specified by the DEFAULT_SIZE.
01566    */
01567   ACE_Bounded_Set (void);
01568 
01569   /// Construct a Bounded_Set with the provided sizeB.
01570   /**
01571    * Initialize the Bounded_Set to have a maximum size equal to the size
01572    * parameter specified.
01573    */
01574   ACE_Bounded_Set (size_t size);
01575 
01576   /// Construct a Bounded_Set that is a copy of the provides Bounded_Set.
01577   /**
01578    * Initialize the Bounded_Set to be a copy of the Bounded_Set parameter.
01579    */
01580   ACE_Bounded_Set (const ACE_Bounded_Set<T> &);
01581 
01582   /// Assignment operator.
01583   /**
01584    * The assignment will make a deep copy of the Bounded_Set provided.  If the
01585    * rhs has more elements than the capacity of the lhs, then the lhs will be
01586    * deleted and reallocated to accomadate the larger number of elements.
01587    */
01588   void operator= (const ACE_Bounded_Set<T> &);
01589 
01590   /// Destructor
01591   /**
01592    * Clean up the underlying dynamically allocated memory that is used by
01593    * the Bounded_Set.
01594    */
01595   ~ACE_Bounded_Set (void);
01596 
01597   // = Check boundary conditions.
01598 
01599   /// Returns 1 if the container is empty, otherwise returns 0.
01600   /**
01601    * A constant time check is performed to determine if the Bounded_Set is
01602    * empty.
01603    */
01604   int is_empty (void) const;
01605 
01606   /// Returns 1 if the container is full, otherwise returns 0.
01607   /**
01608    * Performs a constant time check to determine if the Bounded_Set is at
01609    * capacity.
01610    */
01611   int is_full (void) const;
01612 
01613   // = Classic unordered set operations.
01614 
01615   ///Inserts a new element unique to the set.
01616   /**
01617    * Insert @a new_item into the set (doesn't allow duplicates) in linear
01618    * time.
01619    * Returns -1 if failures occur, 1 if item is already present, else
01620    * 0.
01621    */
01622   int insert (const T &new_item);
01623 
01624   ///Finds the specified element and removes it from the set.
01625   /**
01626    * Remove first occurrence of @a item from the set.  Returns 0 if it
01627    * removes the item, -1 if it can't find the item, and -1 if a
01628    * failure occurs.  The linear remove operation does not reclaim the
01629    * memory associated with the removed item.
01630    */
01631   int remove (const T &item);
01632 
01633   /// Finds if @a item occurs in the set.  Returns 0 if finds, else -1.
01634   /**
01635    * find preforms a linear search for {item} and returns 0 on successful
01636    * find and -1 otherwise.
01637    */
01638   int find (const T &item) const;
01639 
01640   /// Size of the set.
01641   /**
01642    * Returns a size_t representing the current size of the set.
01643    */
01644   size_t size (void) const;
01645 
01646   /// Dump the state of an object.
01647   void dump (void) const;
01648 
01649   /// Declare the dynamic allocation hooks.
01650   ACE_ALLOC_HOOK_DECLARE;
01651 
01652 private:
01653   struct Search_Structure
01654   {
01655     /// Item in the set.
01656     T item_;
01657 
01658     /// Keeps track of whether this item is in use or not.
01659     int is_free_;
01660   };
01661 
01662   /// Holds the contents of the set.
01663   Search_Structure *search_structure_;
01664 
01665   /// Current size of the set.
01666   size_t cur_size_;
01667 
01668   /// Maximum size of the set.
01669   size_t max_size_;
01670 };
01671 
01672 /**
01673  * @class ACE_Ordered_MultiSet_Iterator
01674  *
01675  * @brief Implement a bidirectional iterator over an ordered multiset.
01676  * This class template requires that < operator semantics be
01677  * defined for the parameterized type {T}, but does not impose
01678  * any restriction on how that ordering operator is implemented.
01679  */
01680 template <class T>
01681 class ACE_Ordered_MultiSet_Iterator
01682 {
01683 public:
01684   friend class ACE_Ordered_MultiSet<T>;
01685 
01686   // = Initialization method.
01687   ACE_Ordered_MultiSet_Iterator (ACE_Ordered_MultiSet<T> &s);
01688 
01689   // = Iteration methods.
01690 
01691   /// Pass back the {next_item} that hasn't been seen in the ordered multiset.
01692   /// Returns 0 when all items have been seen, else 1.
01693   int next (T *&next_item) const;
01694 
01695   /// Repositions the iterator at the first item in the ordered multiset
01696   /// Returns 0 if the list is empty else 1.
01697   int first (void);
01698 
01699   /// Repositions the iterator at the last item in the ordered multiset
01700   /// Returns 0 if the list is empty else 1.
01701   int last (void);
01702 
01703   /// Move forward by one element in the set.  Returns 0 when all the
01704   /// items in the set have been seen, else 1.
01705   int advance (void);
01706 
01707   /// Move backward by one element in the set.  Returns 0 when all the
01708   /// items in the set have been seen, else 1.
01709   int retreat (void);
01710 
01711   /// Returns 1 when all items have been seen, else 0.
01712   int done (void) const;
01713 
01714   /// Dump the state of an object.
01715   void dump (void) const;
01716 
01717   /// Returns a reference to the internal element {this} is pointing to.
01718   T& operator* (void);
01719 
01720   /// Declare the dynamic allocation hooks.
01721   ACE_ALLOC_HOOK_DECLARE;
01722 
01723 private:
01724 
01725   /// Pointer to the current node in the iteration.
01726   ACE_DNode<T> *current_;
01727 
01728   /// Pointer to the set we're iterating over.
01729   ACE_Ordered_MultiSet<T> &set_;
01730 };
01731 
01732 
01733 /**
01734  * @class ACE_Ordered_MultiSet
01735  *
01736  * @brief Implement a simple ordered multiset of {T} of unbounded size
01737  * that allows duplicates.  This class template requires that <
01738  * operator semantics be defined for the parameterized type {T}, but
01739  * does not impose any restriction on how that ordering operator is
01740  * implemented.  The set is implemented as a linked list.
01741  *
01742  *
01743  * <b> Requirements and Performance Characteristics</b>
01744  *   - Internal Structure
01745  *       Double linked list
01746  *   - Duplicates allowed?
01747  *       Yes
01748  *   - Random access allowed?
01749  *       No
01750  *   - Search speed
01751  *       Linear
01752  *   - Insert/replace speed
01753  *       Linear
01754  *   - Iterator still valid after change to container?
01755  *       Yes
01756  *   - Frees memory for removed elements?
01757  *       Yes
01758  *   - Items inserted by
01759  *       Value
01760  *   - Requirements for contained type
01761  *       -# Default constructor
01762  *       -# Copy constructor
01763  *       -# operator=
01764  *       -# operator==
01765  *       -# operator<
01766  *
01767  *
01768  */
01769 template <class T>
01770 class ACE_Ordered_MultiSet
01771 {
01772 public:
01773   friend class ACE_Ordered_MultiSet_Iterator<T>;
01774 
01775   // Trait definition.
01776   typedef ACE_Ordered_MultiSet_Iterator<T> ITERATOR;
01777 
01778   // = Initialization and termination methods.
01779   /// Constructor.  Use user specified allocation strategy
01780   /// if specified.
01781   /**
01782    * Initialize the set using the allocation strategy specified.  If none, use the
01783    * default strategy.
01784    */
01785   ACE_Ordered_MultiSet (ACE_Allocator *the_allocator = 0);
01786 
01787   /// Copy constructor.
01788   /**
01789    * Initialize the set to be a copy of the provided set.
01790    */
01791   ACE_Ordered_MultiSet (const ACE_Ordered_MultiSet<T> &);
01792 
01793   /// Destructor.
01794   /**
01795    * Delete the nodes of the set.
01796    */
01797   ~ACE_Ordered_MultiSet (void);
01798 
01799   /// Assignment operator.
01800   /**
01801    * Delete the nodes in lhs, and copy the nodes from the rhs.
01802    */
01803   void operator= (const ACE_Ordered_MultiSet<T> &);
01804 
01805   // = Check boundary conditions.
01806 
01807   /// Returns 1 if the container is empty, otherwise returns 0.
01808   /**
01809    * Constant time check to determine if the set is empty.
01810    */
01811   int is_empty (void) const;
01812 
01813   /// Size of the set.
01814   /**
01815    * Constant time check to determine the size of the set.
01816    */
01817   size_t size (void) const;
01818 
01819   // = Classic unordered set operations.
01820 
01821   /// Insert @a new_item into the ordered multiset.
01822   /// Returns -1 if failures occur, else 0.
01823   /**
01824    * Linear time, order preserving insert into the set beginning at the head.
01825    */
01826   int insert (const T &new_item);
01827 
01828   ///Linear time insert beginning at the point specified by the provided iterator.
01829   /**
01830    * Insert @a new_item into the ordered multiset, starting its search at
01831    * the node pointed to by the iterator, and if insertion was successful,
01832    * updates the iterator to point to the newly inserted node.
01833    * Returns -1 if failures occur, else 0.
01834    */
01835   int insert (const T &new_item, ITERATOR &iter);
01836 
01837   /// Remove first occurrence of @a item from the set.  Returns 0 if
01838   /// it removes the item, -1 if it can't find the item.
01839   /**
01840    * Linear time search operation which removes the item from the set if found .
01841    */
01842   int remove (const T &item);
01843 
01844   ///Linear find operation.
01845   /**
01846    * Finds first occurrence of @a item in the multiset, using the iterator's
01847    * current position as a hint to improve performance. If find succeeds,
01848    * it positions the iterator at that node and returns 0, or if it cannot
01849    * locate the node, it leaves the iterator alone and just returns -1.
01850    */
01851   int find (const T &item, ITERATOR &iter) const;
01852 
01853   /// Reset the ACE_Ordered_MultiSet to be empty.
01854   /**
01855    * Delete the nodes inside the set.
01856    */
01857   void reset (void);
01858 
01859   /// Dump the state of an object.
01860   void dump (void) const;
01861 
01862   /// Declare the dynamic allocation hooks.
01863   ACE_ALLOC_HOOK_DECLARE;
01864 
01865 private:
01866 
01867   /**
01868    * Insert @a item, starting its search at the position given,
01869    * and if successful updates the passed pointer to point to
01870    * the newly inserted item's node.
01871    */
01872   int insert_from (const T &item, ACE_DNode<T> *start_position,
01873                    ACE_DNode<T> **new_position);
01874 
01875   /**
01876    * Looks for first occurance of @a item in the ordered set, using the
01877    * passed starting position as a hint: if there is such an instance, it
01878    * updates the new_position pointer to point to this node and returns 0;
01879    * if there is no such node, then if there is a node before where the
01880    * item would have been, it updates the new_position pointer to point
01881    * to this node and returns -1; if there is no such node, then if there
01882    * is a node after where the item would have been, it updates the
01883    * new_position pointer to point to this node (or 0 if there is no such
01884    * node) and returns 1;
01885    */
01886   int locate (const T &item, ACE_DNode<T> *start_position,
01887               ACE_DNode<T> *&new_position) const;
01888 
01889   /// Delete all the nodes in the Set.
01890   void delete_nodes (void);
01891 
01892   /// Copy nodes into this set.
01893   void copy_nodes (const ACE_Ordered_MultiSet<T> &);
01894 
01895   /// Head of the bilinked list of Nodes.
01896   ACE_DNode<T> *head_;
01897 
01898   /// Head of the bilinked list of Nodes.
01899   ACE_DNode<T> *tail_;
01900 
01901   /// Current size of the set.
01902   size_t cur_size_;
01903 
01904   /// Allocation strategy of the set.
01905   ACE_Allocator *allocator_;
01906 };
01907 
01908 // ****************************************************************
01909 
01910 /**
01911  * @class ACE_Array
01912  *
01913  * @brief A dynamic array class.
01914  *
01915  * This class extends ACE_Array_Base, adding comparison operators.
01916  *
01917  * <b> Requirements and Performance Characteristics</b>
01918  *   - Internal Structure
01919  *       Dynamic array
01920  *   - Duplicates allowed?
01921  *       Yes
01922  *   - Random access allowed?
01923  *       Yes
01924  *   - Search speed
01925  *       N/A
01926  *   - Insert/replace speed
01927  *       O(1)
01928  *   - Iterator still valid after change to container?
01929  *       - In general, yes.
01930  *       - If array size is changed during iteration, no.
01931  *   - Frees memory for removed elements?
01932  *       No
01933  *   - Items inserted by
01934  *       Value
01935  *   - Requirements for contained type
01936  *       -# Default constructor
01937  *       -# Copy constructor
01938  *       -# operator=
01939  *       -# operator!=
01940  *
01941  * @sa ACE_Array_Base. This class inherits its operations and requirements.
01942  */
01943 template <class T>
01944 class ACE_Array : public ACE_Array_Base<T>
01945 {
01946 public:
01947   // Define a "trait"
01948   typedef T TYPE;
01949 
01950   typedef ACE_Array_Iterator<T> ITERATOR;
01951 
01952   // = Exceptions.
01953 
01954   // = Initialization and termination methods.
01955 
01956   /// Dynamically create an uninitialized array.
01957   /**
01958    * Initialize an empty array of the specified size using the provided
01959    * allocation strategy.
01960    */
01961   ACE_Array (size_t size = 0,
01962              ACE_Allocator* alloc = 0);
01963 
01964   /// Dynamically initialize the entire array to the {default_value}.
01965   /**
01966    * Initialize an array the given size placing the default_value in each index.
01967    */
01968   ACE_Array (size_t size,
01969              const T &default_value,
01970              ACE_Allocator* alloc = 0);
01971 
01972   ///Copy constructor.
01973   /**
01974    * The copy constructor performs initialization by making an exact
01975    * copy of the contents of parameter {s}, i.e., *this == s will
01976    * return true.
01977    */
01978   ACE_Array (const ACE_Array<T> &s);
01979 
01980   ///Assignment operator
01981   /**
01982    * Assignment operator performs an assignment by making an exact
01983    * copy of the contents of parameter {s}, i.e., *this == s will
01984    * return true.  Note that if the {max_size_} of {array_} is >= than
01985    * {s.max_size_} we can copy it without reallocating.  However, if
01986    * {max_size_} is < {s.max_size_} we must delete the {array_},
01987    * reallocate a new {array_}, and then copy the contents of {s}.
01988    */
01989   void operator= (const ACE_Array<T> &s);
01990 
01991   // = Compare operators
01992 
01993   ///Equality comparison operator.
01994   /**
01995    * Compare this array with {s} for equality.  Two arrays are equal
01996    * if their {size}'s are equal and all the elements from 0 .. {size}
01997    * are equal.
01998    */
01999   bool operator== (const ACE_Array<T> &s) const;
02000 
02001   ///Inequality comparison operator.
02002   /**
02003    * Compare this array with {s} for inequality such that {*this} !=
02004    * {s} is always the complement of the boolean return value of
02005    * {*this} == {s}.
02006    */
02007   bool operator!= (const ACE_Array<T> &s) const;
02008 };
02009 
02010 ACE_END_VERSIONED_NAMESPACE_DECL
02011 
02012 #if defined (__ACE_INLINE__)
02013 #include "ace/Containers_T.inl"
02014 #endif /* __ACE_INLINE__ */
02015 
02016 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
02017 #include "ace/Containers_T.cpp"
02018 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
02019 
02020 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
02021 #pragma implementation ("Containers_T.cpp")
02022 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
02023 
02024 #include /**/ "ace/post.h"
02025 
02026 #endif /* ACE_CONTAINERS_T_H */

Generated on Thu Nov 9 09:41:49 2006 for ACE by doxygen 1.3.6