Containers_T.h

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

Generated on Tue Feb 2 17:18:39 2010 for ACE by  doxygen 1.4.7