diff options
author | coryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2001-03-26 21:18:51 +0000 |
---|---|---|
committer | coryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2001-03-26 21:18:51 +0000 |
commit | dc7b47e328ac184eed767b8287f918a46eb5d68e (patch) | |
tree | d2a03a59e7a8e39f4aeef13f0b7eb07b589b076c /ace/Containers_T.cpp | |
parent | 91a94f0f3fa63a897d5556805a23dee7a8bba7fb (diff) | |
download | ATCD-dc7b47e328ac184eed767b8287f918a46eb5d68e.tar.gz |
ChangeLogTag:Mon Mar 26 13:00:37 2001 Carlos O'Ryan <coryan@uci.edu>
Diffstat (limited to 'ace/Containers_T.cpp')
-rw-r--r-- | ace/Containers_T.cpp | 898 |
1 files changed, 2 insertions, 896 deletions
diff --git a/ace/Containers_T.cpp b/ace/Containers_T.cpp index 5326b8f1ad3..eeb47912ddf 100644 --- a/ace/Containers_T.cpp +++ b/ace/Containers_T.cpp @@ -3,7 +3,7 @@ #ifndef ACE_CONTAINERS_T_C #define ACE_CONTAINERS_T_C -#include "ace/Malloc.h" +#include "ace/Malloc_Base.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once @@ -329,355 +329,6 @@ ACE_Unbounded_Stack<T>::remove (const T &item) } } -template <class T> -ACE_Unbounded_Queue<T>::ACE_Unbounded_Queue (ACE_Allocator *alloc) - : head_ (0), - cur_size_ (0), - allocator_ (alloc) -{ - // ACE_TRACE ("ACE_Unbounded_Queue<T>::ACE_Unbounded_Queue (void)"); - - if (this->allocator_ == 0) - this->allocator_ = ACE_Allocator::instance (); - - ACE_NEW_MALLOC (this->head_, - (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)), - ACE_Node<T>); - // Make the list circular by pointing it back to itself. - this->head_->next_ = this->head_; -} - -template <class T> -ACE_Unbounded_Queue<T>::ACE_Unbounded_Queue (const ACE_Unbounded_Queue<T> &us) - : head_ (0), - cur_size_ (0), - allocator_ (us.allocator_) -{ - // ACE_TRACE ("ACE_Unbounded_Queue<T>::ACE_Unbounded_Queue"); - - if (this->allocator_ == 0) - this->allocator_ = ACE_Allocator::instance (); - - ACE_NEW_MALLOC (this->head_, - (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)), - ACE_Node<T>); - this->head_->next_ = this->head_; - this->copy_nodes (us); -} - -template <class T> void -ACE_Unbounded_Queue<T>::operator= (const ACE_Unbounded_Queue<T> &us) -{ - // ACE_TRACE ("ACE_Unbounded_Queue<T>::operator="); - - if (this != &us) - { - this->delete_nodes (); - this->copy_nodes (us); - } -} - -template <class T> ACE_Unbounded_Queue_Iterator<T> -ACE_Unbounded_Queue<T>::begin (void) -{ - // ACE_TRACE ("ACE_Unbounded_Queue<T>::begin"); - return ACE_Unbounded_Queue_Iterator<T> (*this); -} - -template <class T> ACE_Unbounded_Queue_Iterator<T> -ACE_Unbounded_Queue<T>::end (void) -{ - // ACE_TRACE ("ACE_Unbounded_Queue<T>::end"); - return ACE_Unbounded_Queue_Iterator<T> (*this, 1); -} - - -ACE_ALLOC_HOOK_DEFINE(ACE_Unbounded_Queue) - -template <class T> void -ACE_Unbounded_Queue<T>::dump (void) const -{ - // ACE_TRACE ("ACE_Unbounded_Queue<T>::dump"); - - ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); - ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nhead_ = %u"), this->head_)); - ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nhead_->next_ = %u"), this->head_->next_)); - ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ncur_size_ = %d\n"), this->cur_size_)); - - T *item = 0; -#if !defined (ACE_NLOGGING) - size_t count = 1; -#endif /* ! ACE_NLOGGING */ - - for (ACE_Unbounded_Queue_Iterator<T> iter (*(ACE_Unbounded_Queue<T> *) this); - iter.next (item) != 0; - iter.advance ()) - ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("count = %d\n"), count++)); - - ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); -} - -template <class T> void -ACE_Unbounded_Queue<T>::copy_nodes (const ACE_Unbounded_Queue<T> &us) -{ - for (ACE_Node<T> *curr = us.head_->next_; - curr != us.head_; - curr = curr->next_) - if (this->enqueue_tail (curr->item_) == -1) - // @@ What's the right thing to do here? - this->delete_nodes (); -} - -template <class T> void -ACE_Unbounded_Queue<T>::delete_nodes (void) -{ - for (ACE_Node<T> *curr = this->head_->next_; - // Keep looking until we've hit the dummy node. - curr != this->head_; - ) - { - ACE_Node<T> *temp = curr; - curr = curr->next_; - - ACE_DES_FREE_TEMPLATE (temp, - this->allocator_->free, - ACE_Node, - <T>); - this->cur_size_--; - // @@ Doesnt make sense to have this check since - // this will always be true. - // ACE_ASSERT (this->cur_size_ >= 0); - } - - // Reset the list to be a circular list with just a dummy node. - this->head_->next_ = this->head_; -} - -template <class T> -ACE_Unbounded_Queue<T>::~ACE_Unbounded_Queue (void) -{ - // ACE_TRACE ("ACE_Unbounded_Queue<T>::~ACE_Unbounded_Queue (void)"); - - this->delete_nodes (); - ACE_DES_FREE_TEMPLATE (head_, - this->allocator_->free, - ACE_Node, - <T>); - this->head_ = 0; -} - -template <class T> int -ACE_Unbounded_Queue<T>::enqueue_head (const T &new_item) -{ - // ACE_TRACE ("ACE_Unbounded_Queue<T>::enqueue_head"); - - ACE_Node<T> *temp; - - // Create a new node that points to the original head. - ACE_NEW_MALLOC_RETURN (temp, - (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)), - ACE_Node<T> (new_item, this->head_->next_), - -1); - // Link this pointer into the front of the list. Note that the - // "real" head of the queue is <head_->next_>, whereas <head_> is - // just a pointer to the dummy node. - this->head_->next_ = temp; - - this->cur_size_++; - return 0; -} - -template <class T> int -ACE_Unbounded_Queue<T>::enqueue_tail (const T &new_item) -{ - // ACE_TRACE ("ACE_Unbounded_Queue<T>::enqueue_tail"); - - ACE_Node<T> *temp; - - // Insert <item> into the old dummy node location. Note that this - // isn't actually the "head" item in the queue, it's a dummy node at - // the "tail" of the queue... - this->head_->item_ = new_item; - - // Create a new dummy node. - ACE_NEW_MALLOC_RETURN (temp, - (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)), - ACE_Node<T> (this->head_->next_), -1); - // Link this dummy pointer into the list. - this->head_->next_ = temp; - - // Point the head to the new dummy node. - this->head_ = temp; - - this->cur_size_++; - return 0; -} - -template <class T> int -ACE_Unbounded_Queue<T>::dequeue_head (T &item) -{ - // ACE_TRACE ("ACE_Unbounded_Queue<T>::dequeue_head"); - - // Check for empty queue. - if (this->is_empty ()) - return -1; - - ACE_Node<T> *temp = this->head_->next_; - - item = temp->item_; - this->head_->next_ = temp->next_; - ACE_DES_FREE_TEMPLATE (temp, - this->allocator_->free, - ACE_Node, - <T>); - --this->cur_size_; - return 0; -} - -template <class T> void -ACE_Unbounded_Queue<T>::reset (void) -{ - ACE_TRACE ("reset"); - - this->delete_nodes (); -} - -template <class T> int -ACE_Unbounded_Queue<T>::get (T *&item, size_t slot) const -{ - // ACE_TRACE ("ACE_Unbounded_Queue<T>::get"); - - ACE_Node<T> *curr = this->head_->next_; - - size_t i; - - for (i = 0; i < this->cur_size_; i++) - { - if (i == slot) - break; - - curr = curr->next_; - } - - if (i < this->cur_size_) - { - item = &curr->item_; - return 0; - } - else - return -1; -} - -template <class T> int -ACE_Unbounded_Queue<T>::set (const T &item, - size_t slot) -{ - // ACE_TRACE ("ACE_Unbounded_Queue<T>::set"); - - ACE_Node<T> *curr = this->head_->next_; - - size_t i; - - for (i = 0; - i < slot && i < this->cur_size_; - i++) - curr = curr->next_; - - if (i < this->cur_size_) - { - // We're in range, so everything's cool. - curr->item_ = item; - return 0; - } - else - { - // We need to expand the list. - - // A common case will be increasing the set size by 1. - // Therefore, we'll optimize for this case. - if (i == slot) - { - // Try to expand the size of the set by 1. - if (this->enqueue_tail (item) == -1) - return -1; - else - return 0; - } - else - { - T dummy; - - // We need to expand the list by multiple (dummy) items. - for (; i < slot; i++) - { - // This head points to the existing dummy node, which is - // about to be overwritten when we add the new dummy - // node. - curr = this->head_; - - // Try to expand the size of the set by 1, but don't - // store anything in the dummy node (yet). - if (this->enqueue_tail (dummy) == -1) - return -1; - } - - curr->item_ = item; - return 0; - } - } -} - -template <class T> void -ACE_Unbounded_Queue_Iterator<T>::dump (void) const -{ - // ACE_TRACE ("ACE_Unbounded_Queue_Iterator<T>::dump"); -} - -template <class T> -ACE_Unbounded_Queue_Iterator<T>::ACE_Unbounded_Queue_Iterator (ACE_Unbounded_Queue<T> &q, int end) - : current_ (end == 0 ? q.head_->next_ : q.head_ ), - queue_ (q) -{ - // ACE_TRACE ("ACE_Unbounded_Queue_Iterator<T>::ACE_Unbounded_Queue_Iterator"); -} - -template <class T> int -ACE_Unbounded_Queue_Iterator<T>::advance (void) -{ - // ACE_TRACE ("ACE_Unbounded_Queue_Iterator<T>::advance"); - this->current_ = this->current_->next_; - return this->current_ != this->queue_.head_; -} - -template <class T> int -ACE_Unbounded_Queue_Iterator<T>::first (void) -{ - // ACE_TRACE ("ACE_Unbounded_Queue_Iterator<T>::first"); - this->current_ = this->queue_.head_->next_; - return this->current_ != this->queue_.head_; -} - -template <class T> int -ACE_Unbounded_Queue_Iterator<T>::done (void) const -{ - ACE_TRACE ("ACE_Unbounded_Queue_Iterator<T>::done"); - - return this->current_ == this->queue_.head_; -} - -template <class T> int -ACE_Unbounded_Queue_Iterator<T>::next (T *&item) -{ - // ACE_TRACE ("ACE_Unbounded_Queue_Iterator<T>::next"); - if (this->current_ == this->queue_.head_) - return 0; - else - { - item = &this->current_->item_; - return 1; - } -} - //-------------------------------------------------- ACE_ALLOC_HOOK_DEFINE(ACE_Double_Linked_List_Iterator_Base) @@ -1665,38 +1316,6 @@ ACE_Bounded_Set_Iterator<T>::next (T *&item) return 0; } -ACE_ALLOC_HOOK_DEFINE(ACE_Node) - -# if ! defined (ACE_HAS_BROKEN_NOOP_DTORS) - template <class T> -ACE_Node<T>::~ACE_Node (void) -{ -} -# endif /* ! defined (ACE_HAS_BROKEN_NOOP_DTORS) */ - -template <class T> -ACE_Node<T>::ACE_Node (const T &i, ACE_Node<T> *n) - : next_ (n), - item_ (i) -{ - // ACE_TRACE ("ACE_Node<T>::ACE_Node"); -} - -template <class T> -ACE_Node<T>::ACE_Node (ACE_Node<T> *n, int) - : next_ (n) -{ - // ACE_TRACE ("ACE_Node<T>::ACE_Node"); -} - -template <class T> -ACE_Node<T>::ACE_Node (const ACE_Node<T> &s) - : next_ (s.next_), - item_ (s.item_) -{ - // ACE_TRACE ("ACE_Node<T>::ACE_Node"); -} - ACE_ALLOC_HOOK_DEFINE(ACE_DNode) template <class T> @@ -1712,338 +1331,7 @@ ACE_DNode<T>::~ACE_DNode (void) } # endif /* ! defined (ACE_HAS_BROKEN_NOOP_DTORS) */ -ACE_ALLOC_HOOK_DEFINE(ACE_Unbounded_Set) - - template <class T> size_t -ACE_Unbounded_Set<T>::size (void) const -{ - // ACE_TRACE ("ACE_Unbounded_Set<T>::size"); - return this->cur_size_; -} - -template <class T> int -ACE_Unbounded_Set<T>::insert_tail (const T &item) -{ - // ACE_TRACE ("ACE_Unbounded_Set<T>::insert_tail"); - ACE_Node<T> *temp; - - // Insert <item> into the old dummy node location. - this->head_->item_ = item; - - // Create a new dummy node. - ACE_NEW_MALLOC_RETURN (temp, - (ACE_Node<T>*) this->allocator_->malloc (sizeof (ACE_Node<T>)), - ACE_Node<T> (this->head_->next_), - -1); - // Link this pointer into the list. - this->head_->next_ = temp; - - // Point the head to the new dummy node. - this->head_ = temp; - - this->cur_size_++; - return 0; -} - -template <class T> void -ACE_Unbounded_Set<T>::reset (void) -{ - ACE_TRACE ("reset"); - - this->delete_nodes (); -} - -template <class T> void -ACE_Unbounded_Set<T>::dump (void) const -{ - ACE_TRACE ("ACE_Unbounded_Set<T>::dump"); - - ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); - ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nhead_ = %u"), this->head_)); - ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nhead_->next_ = %u"), this->head_->next_)); - ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ncur_size_ = %d\n"), this->cur_size_)); - - T *item = 0; -#if !defined (ACE_NLOGGING) - size_t count = 1; -#endif /* ! ACE_NLOGGING */ - - for (ACE_Unbounded_Set_Iterator<T> iter (*(ACE_Unbounded_Set<T> *) this); - iter.next (item) != 0; - iter.advance ()) - ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("count = %d\n"), count++)); - - ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); -} - -template <class T> void -ACE_Unbounded_Set<T>::copy_nodes (const ACE_Unbounded_Set<T> &us) -{ - for (ACE_Node<T> *curr = us.head_->next_; - curr != us.head_; - curr = curr->next_) - this->insert_tail (curr->item_); -} - -template <class T> void -ACE_Unbounded_Set<T>::delete_nodes (void) -{ - ACE_Node<T> *curr = this->head_->next_; - - // Keep looking until we've hit the dummy node. - - while (curr != this->head_) - { - ACE_Node<T> *temp = curr; - curr = curr->next_; - ACE_DES_FREE_TEMPLATE (temp, - this->allocator_->free, - ACE_Node, - <T>); - this->cur_size_--; - } - - // Reset the list to be a circular list with just a dummy node. - this->head_->next_ = this->head_; -} - -template <class T> -ACE_Unbounded_Set<T>::~ACE_Unbounded_Set (void) -{ - // ACE_TRACE ("ACE_Unbounded_Set<T>::~ACE_Unbounded_Set"); - - this->delete_nodes (); - - // Delete the dummy node. - ACE_DES_FREE_TEMPLATE (head_, - this->allocator_->free, - ACE_Node, - <T>); - this->head_ = 0; -} - -template <class T> -ACE_Unbounded_Set<T>::ACE_Unbounded_Set (ACE_Allocator *alloc) - : head_ (0), - cur_size_ (0), - allocator_ (alloc) -{ - // ACE_TRACE ("ACE_Unbounded_Set<T>::ACE_Unbounded_Set"); - - if (this->allocator_ == 0) - this->allocator_ = ACE_Allocator::instance (); - - ACE_NEW_MALLOC (this->head_, - (ACE_Node<T>*) this->allocator_->malloc (sizeof (ACE_Node<T>)), - ACE_Node<T>); - // Make the list circular by pointing it back to itself. - this->head_->next_ = this->head_; -} - -template <class T> -ACE_Unbounded_Set<T>::ACE_Unbounded_Set (const ACE_Unbounded_Set<T> &us) - : head_ (0), - cur_size_ (0), - allocator_ (us.allocator_) -{ - ACE_TRACE ("ACE_Unbounded_Set<T>::ACE_Unbounded_Set"); - - if (this->allocator_ == 0) - this->allocator_ = ACE_Allocator::instance (); - - ACE_NEW_MALLOC (this->head_, - (ACE_Node<T>*) this->allocator_->malloc (sizeof (ACE_Node<T>)), - ACE_Node<T>); - this->head_->next_ = this->head_; - this->copy_nodes (us); -} - -template <class T> void -ACE_Unbounded_Set<T>::operator= (const ACE_Unbounded_Set<T> &us) -{ - ACE_TRACE ("ACE_Unbounded_Set<T>::operator="); - - if (this != &us) - { - this->delete_nodes (); - this->copy_nodes (us); - } -} - -template <class T> int -ACE_Unbounded_Set<T>::find (const T &item) const -{ - // ACE_TRACE ("ACE_Unbounded_Set<T>::find"); - // Set <item> into the dummy node. - this->head_->item_ = item; - - ACE_Node<T> *temp = this->head_->next_; - - // Keep looping until we find the item. - while (!(temp->item_ == item)) - temp = temp->next_; - - // If we found the dummy node then it's not really there, otherwise, - // it is there. - return temp == this->head_ ? -1 : 0; -} - -template <class T> int -ACE_Unbounded_Set<T>::insert (const T &item) -{ - // ACE_TRACE ("ACE_Unbounded_Set<T>::insert"); - if (this->find (item) == 0) - return 1; - else - return this->insert_tail (item); -} - -template <class T> int -ACE_Unbounded_Set<T>::remove (const T &item) -{ - // ACE_TRACE ("ACE_Unbounded_Set<T>::remove"); - - // Insert the item to be founded into the dummy node. - this->head_->item_ = item; - - ACE_Node<T> *curr = this->head_; - - while (!(curr->next_->item_ == item)) - curr = curr->next_; - - if (curr->next_ == this->head_) - return -1; // Item was not found. - else - { - ACE_Node<T> *temp = curr->next_; - // Skip over the node that we're deleting. - curr->next_ = temp->next_; - this->cur_size_--; - ACE_DES_FREE_TEMPLATE (temp, - this->allocator_->free, - ACE_Node, - <T>); - return 0; - } -} - -template <class T> ACE_Unbounded_Set_Iterator<T> -ACE_Unbounded_Set<T>::begin (void) -{ - // ACE_TRACE ("ACE_Unbounded_Set<T>::begin"); - return ACE_Unbounded_Set_Iterator<T> (*this); -} - -template <class T> ACE_Unbounded_Set_Iterator<T> -ACE_Unbounded_Set<T>::end (void) -{ - // ACE_TRACE ("ACE_Unbounded_Set<T>::end"); - return ACE_Unbounded_Set_Iterator<T> (*this, 1); -} - - -ACE_ALLOC_HOOK_DEFINE(ACE_Unbounded_Set_Iterator) - - template <class T> void -ACE_Unbounded_Set_Iterator<T>::dump (void) const -{ - // ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::dump"); -} - -template <class T> -ACE_Unbounded_Set_Iterator<T>::ACE_Unbounded_Set_Iterator (ACE_Unbounded_Set<T> &s, int end) - : current_ (end == 0 ? s.head_->next_ : s.head_ ), - set_ (&s) -{ - // ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::ACE_Unbounded_Set_Iterator"); -} - -template <class T> int -ACE_Unbounded_Set_Iterator<T>::advance (void) -{ - // ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::advance"); - this->current_ = this->current_->next_; - return this->current_ != this->set_->head_; -} - -template <class T> int -ACE_Unbounded_Set_Iterator<T>::first (void) -{ - // ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::first"); - this->current_ = this->set_->head_->next_; - return this->current_ != this->set_->head_; -} - -template <class T> int -ACE_Unbounded_Set_Iterator<T>::done (void) const -{ - ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::done"); - - return this->current_ == this->set_->head_; -} - -template <class T> int -ACE_Unbounded_Set_Iterator<T>::next (T *&item) -{ - // ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::next"); - if (this->current_ == this->set_->head_) - return 0; - else - { - item = &this->current_->item_; - return 1; - } -} - -template <class T> ACE_Unbounded_Set_Iterator<T> -ACE_Unbounded_Set_Iterator<T>::operator++ (int) -{ - //ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::operator++ (int)"); - ACE_Unbounded_Set_Iterator<T> retv (*this); - - // postfix operator - - this->advance (); - return retv; -} - -template <class T> ACE_Unbounded_Set_Iterator<T>& -ACE_Unbounded_Set_Iterator<T>::operator++ (void) -{ - // ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::operator++ (void)"); - - // prefix operator - - this->advance (); - return *this; -} - -template <class T> T& -ACE_Unbounded_Set_Iterator<T>::operator* (void) -{ - //ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::operator*"); - T *retv = 0; - - int result = this->next (retv); - ACE_ASSERT (result != 0); - ACE_UNUSED_ARG (result); - - return *retv; -} - -template <class T> int -ACE_Unbounded_Set_Iterator<T>::operator== (const ACE_Unbounded_Set_Iterator<T> &rhs) const -{ - //ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::operator=="); - return (this->set_ == rhs.set_ && this->current_ == rhs.current_); -} - -template <class T> int -ACE_Unbounded_Set_Iterator<T>::operator!= (const ACE_Unbounded_Set_Iterator<T> &rhs) const -{ - //ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::operator!="); - return (this->set_ != rhs.set_ || this->current_ != rhs.current_); -} +// **************************************************************** template <class T> void ACE_Unbounded_Stack_Iterator<T>::dump (void) const @@ -2489,171 +1777,6 @@ ACE_DLList<T>::delete_tail (void) return temp2; } -// Dynamically initialize an array. - -template <class T> -ACE_Array_Base<T>::ACE_Array_Base (size_t size, - ACE_Allocator *alloc) - : max_size_ (size), - cur_size_ (size), - allocator_ (alloc) -{ - if (this->allocator_ == 0) - this->allocator_ = ACE_Allocator::instance (); - - if (size != 0) - { - ACE_ALLOCATOR (this->array_, - (T *) this->allocator_->malloc (size * sizeof (T))); - for (size_t i = 0; i < size; ++i) - new (&array_[i]) T; - } - else - this->array_ = 0; -} - -template <class T> -ACE_Array_Base<T>::ACE_Array_Base (size_t size, - const T &default_value, - ACE_Allocator *alloc) - : max_size_ (size), - cur_size_ (size), - allocator_ (alloc) -{ - if (this->allocator_ == 0) - this->allocator_ = ACE_Allocator::instance (); - - if (size != 0) - { - ACE_ALLOCATOR (this->array_, - (T *) this->allocator_->malloc (size * sizeof (T))); - for (size_t i = 0; i < size; ++i) - new (&array_[i]) T (default_value); - } - else - this->array_ = 0; -} - -// The copy constructor (performs initialization). - -template <class T> -ACE_Array_Base<T>::ACE_Array_Base (const ACE_Array_Base<T> &s) - : max_size_ (s.size ()), - cur_size_ (s.size ()), - allocator_ (s.allocator_) -{ - if (this->allocator_ == 0) - this->allocator_ = ACE_Allocator::instance (); - - ACE_ALLOCATOR (this->array_, - (T *) this->allocator_->malloc (s.size () * sizeof (T))); - for (size_t i = 0; i < this->size (); i++) - new (&this->array_[i]) T (s.array_[i]); -} - -// Assignment operator (performs assignment). - -template <class T> void -ACE_Array_Base<T>::operator= (const ACE_Array_Base<T> &s) -{ - // Check for "self-assignment". - - if (this != &s) - { - if (this->max_size_ < s.size ()) - { - ACE_DES_ARRAY_FREE (this->array_, - this->max_size_, - this->allocator_->free, - T); - ACE_ALLOCATOR (this->array_, - (T *) this->allocator_->malloc (s.size () * sizeof (T))); - this->max_size_ = s.size (); - } - else - { - ACE_DES_ARRAY_NOFREE (this->array_, - s.size (), - T); - } - - this->cur_size_ = s.size (); - - for (size_t i = 0; i < this->size (); i++) - new (&this->array_[i]) T (s.array_[i]); - } -} - -// Set an item in the array at location slot. - -template <class T> int -ACE_Array_Base<T>::set (const T &new_item, size_t slot) -{ - if (this->in_range (slot)) - { - this->array_[slot] = new_item; - return 0; - } - else - return -1; -} - -// Get an item in the array at location slot. - -template <class T> int -ACE_Array_Base<T>::get (T &item, size_t slot) const -{ - if (this->in_range (slot)) - { - // Copies the item. If you don't want to copy, use operator [] - // instead (but then you'll be responsible for range checking). - item = this->array_[slot]; - return 0; - } - else - return -1; -} - -template<class T> int -ACE_Array_Base<T>::max_size (size_t new_size) -{ - if (new_size > this->max_size_) - { - T *tmp; - - ACE_ALLOCATOR_RETURN (tmp, - (T *) this->allocator_->malloc (new_size * sizeof (T)), - -1); - for (size_t i = 0; i < this->cur_size_; ++i) - new (&tmp[i]) T (this->array_[i]); - - // Initialize the new portion of the array that exceeds the - // previously allocated section. - for (size_t j = this->cur_size_; j < new_size; j++) - new (&tmp[j]) T; - - ACE_DES_ARRAY_FREE (this->array_, - this->max_size_, - this->allocator_->free, - T); - this->array_ = tmp; - this->max_size_ = new_size; - this->cur_size_ = new_size; - } - - return 0; -} - -template<class T> int -ACE_Array_Base<T>::size (size_t new_size) -{ - int r = this->max_size (new_size); - if (r != 0) - return r; - this->cur_size_ = new_size; - return 0; -} - // **************************************************************** // Compare this array with <s> for equality. @@ -2676,21 +1799,4 @@ ACE_Array<T>::operator== (const ACE_Array<T> &s) const // **************************************************************** -template <class T> int -ACE_Array_Iterator<T>::next (T *&item) -{ - // ACE_TRACE ("ACE_Array_Iterator<T>::next"); - - if (this->done ()) - { - item = 0; - return 0; - } - else - { - item = &array_[current_]; - return 1; - } -} - #endif /* ACE_CONTAINERS_T_C */ |