diff options
Diffstat (limited to 'ace/Containers.h')
-rw-r--r-- | ace/Containers.h | 240 |
1 files changed, 239 insertions, 1 deletions
diff --git a/ace/Containers.h b/ace/Containers.h index 9e08f3bb411..efb8c832afa 100644 --- a/ace/Containers.h +++ b/ace/Containers.h @@ -173,7 +173,7 @@ template <class T> class ACE_Unbounded_Stack_Iterator; template<class T> class ACE_Node // = TITLE - // Implementation element in a Queue + // Implementation element in a Queue. { friend class ACE_Unbounded_Queue<T>; friend class ACE_Unbounded_Queue_Iterator<T>; @@ -197,6 +197,64 @@ private: // Current value of the item in this node. }; +#if defined (NANBOR_EXP_CODES) +class ACE_DNode_Base + // = TITLE + // Implement the minimum stuff a node in a double + // linked list should have. + // + // = DESCRIPTION + // Basic functionalities an element in double linked + // lists. +{ + public: + ACE_DNode_Base (void); + // Default do nothing ctor. + + ACE_DNode_Base (ACE_DNode_Base *n, ACE_DNode_Base *p); + // Build and set ctor. + + void next (ACE_DNode_Base *n) = 0; + // Set <next_> ptr. + + ACE_DNode_Base *next (void) = 0; + // Get <next_> ptr. + + void prev (ACE_DNode_Base *p) = 0; + // Set <prev_> ptr. + + ACE_DNode_Base *prev (void) = 0; + // Get <prev_> ptr. + + protected: + ACE_DNode_Base *prev_; + // Pointer to previous element in the list. + + ACE_DNode_Base *next_; + // Pointer to next element in the list. +}; +#endif /* NANBOR_EXP_CODES */ + +#if defined (NANBOR_DISABLED_EXP_CODES) +template <class T> +class ACE_DNode : public ACE_Node<T> +// = TITLE +// Implementation element in a Double Linked List. +{ + friend class ACE_Double_Linked_List<T>; + friend class ACE_Double_Linked_List_Iterator<T>; +protected: + ACE_DNode (const T &i, ACE_DNode<T> *n, ACE_DNode<T> *p); + ACE_DNode (ACE_DNode<T> *n = 0, ACE_DNode<T> *p = 0); + ACE_DNode (const ACE_DNode<T> &i); + + ~ACE_DNode (void); + + ACE_DNode<T> *prev_; + // Pointer to prev element in the list of <ACE_DNode>s. +}; +#endif /* NANBOR_DISABLED_EXP_CODES */ + template <class T> class ACE_Unbounded_Stack // = TITLE @@ -450,6 +508,186 @@ protected: }; template <class T> +class ACE_Unbounded_Stack_Iterator + // = TITLE + // Implement an iterator over an unbounded Stack. +{ +public: + // = Initialization method. + ACE_Unbounded_Stack_Iterator (ACE_Unbounded_Stack<T> &); + + // = Iteration methods. + + int next (T *&next_item); + // Pass back the <next_item> that hasn't been seen in the Stack. + // Returns 0 when all items have been seen, else 1. + + int advance (void); + // Move forward by one element in the Stack. Returns 0 when all the + // items in the Stack have been seen, else 1. + + int done (void) const; + // Returns 1 when all items have been seen, else 0. + + void dump (void) const; + // Dump the state of an object. + + ACE_ALLOC_HOOK_DECLARE; + // Declare the dynamic allocation hooks. + +private: + ACE_Node<T> *current_; + // Pointer to the current node in the iteration. + + ACE_Unbounded_Stack<T> &stack_; + // Pointer to the Stack we're iterating over. +}; + +#if defined (NANBOR_DISABLED_EXP_CODES) +template <class T> +class ACE_Double_Linked_List; + +template <class T> +class ACE_Double_Linked_List_Iterator + // = TITLE + // Implement an iterator over a double-linked list. +{ +public: + // = Initialization method. + ACE_Double_Linked_List (ACE_Double_Linked_List<T> &); + + // = Iteration methods. + + int next (T *&next_item); + // Pass back the <next_item> that hasn't been seen in the queue. + // Returns 0 when all items have been seen, else 1. + + int advance (void); + // Move forward by one element in the set. Returns 0 when all the + // items in the queue have been seen, else 1. + + int done (void) const; + // Returns 1 when all items have been seen, else 0. + + void dump (void) const; + // Dump the state of an object. + + ACE_ALLOC_HOOK_DECLARE; + // Declare the dynamic allocation hooks. + +private: + ACE_DNode<T> *current_; + // Pointer to the current node in the iteration. + + ACE_Double_Linked_List<T> &list_; + // Pointer to the queue we're iterating over. +}; + +template <class T> +class ACE_Double_Linked_List + // = TITLE + // A double linked list implementation. + // + // = DESCRIPTION + // This implementation of an unbounded double linked list uses a circular + // linked list with a dummy node. It is pretty much like the ACE_Unbounded_Queue + // except that it allows removing of a specific element from a specific location. +{ + friend class ACE_Double_Linked_List_Iterator<T>; +public: + // = Initialization and termination methods. + ACE_Double_Linked_List (ACE_Allocator *alloc = 0); + // construction. Use user specified allocation strategy + // if specified. + + ACE_Double_Linked_List (const ACE_Double_Linked_list<T> &); + // Copy constructor. + + void operator= (const ACE_Double_linked_List<T> &); + // Assignment operator. + + ~ACE_Double_Linked_List (void); + // construction. + + // = Check boundary conditions. + + int is_empty (void) const; + // Returns 1 if the container is empty, otherwise returns 0. + + int is_full (void) const; + // Returns 1 if the container is full, otherwise returns 0. + + // = Classic queue operations. + + int enqueue_tail (const T &new_item); + // Adds <new_item> to the tail of the queue. Returns 0 on success, + // -1 on failure. + + int enqueue_head (const T &new_item); + // Adds <new_item> to the head of the queue. Returns 0 on success, + // -1 on failure. + + int dequeue_head (T &item); + // Removes and returns the first <item> on the queue. Returns 0 on + // success, -1 if the queue was empty. + + // = Additional utility methods. + + void reset (void); + // Reset the <ACE_Unbounded_Queue> to be empty. + + int get (T *&item, size_t index = 0) const; + // Get the <index>th element in the set. Returns -1 if the element + // isn't in the range <0..size() - 1>, else 0. + + int set (const T &item, size_t index); + // Set the <index>th element in the set. Will pad out the set with + // empty nodes if <index> is beyond the range <0..size() - 1>. + // Returns -1 on failure, 0 if <index> isn't initially in range, and + // 0 otherwise. + + size_t size (void) const; + // The number of items in the queue. + + void dump (void) const; + // Dump the state of an object. + + ACE_DNode<T> *find (const T &item); + // Locate the DNode address that contains the item. Return + // an address if succeed, 0 otherwise. + + int remove (const T &item); + // This function will iterate thru the double linked list and + // remove it from the list. return 0 if succeed, -1 otherwise. + + int remove (ACE_DNode<T> *n); + // Use DNode address directly. + + ACE_ALLOC_HOOK_DECLARE; + // Declare the dynamic allocation hooks. + +protected: + void add_node (ACE_DNode<T> *new_node, ACE_DNode<T> *target, int after = 1); + // Add an node before/after a current list element. + + void delete_nodes (void); + // Delete all the nodes in the queue. + + void copy_nodes (const ACE_Unbounded_Queue<T> &); + // Copy nodes into this queue. + + ACE_DNode<T> *head_; + // Pointer to the dummy node in the circular linked Queue. + + size_t cur_size_; + // Current size of the queue. + + ACE_Allocator *allocator_; + // Allocation Strategy of the queue. +}; +#endif /* NANBOR_DISABLED_EXP_CODES */ + +template <class T> class ACE_Unbounded_Set_Iterator // = TITLE // Implement an iterator over an unbounded set. |