// Containers.cpp // $Id$ #if !defined (ACE_CONTAINERS_C) #define ACE_CONTAINERS_C #define ACE_BUILD_DLL #include "ace/Containers.h" #if !defined (__ACE_INLINE__) #include "ace/Containers.i" #endif /* __ACE_INLINE__ */ ACE_ALLOC_HOOK_DEFINE(ACE_Bounded_Stack) template void ACE_Bounded_Stack::dump (void) const { ACE_TRACE ("ACE_Bounded_Stack::dump"); } template ACE_Bounded_Stack::ACE_Bounded_Stack (size_t size) : top_ (0), size_ (size) { ACE_NEW (this->stack_, T[size]); ACE_TRACE ("ACE_Bounded_Stack::ACE_Bounded_Stack"); } template ACE_Bounded_Stack::ACE_Bounded_Stack (const ACE_Bounded_Stack &s) : top_ (s.top_), size_ (s.size_) { ACE_NEW (this->stack_, T[s.size_]); ACE_TRACE ("ACE_Bounded_Stack::ACE_Bounded_Stack"); for (size_t i = 0; i < this->top_; i++) this->stack_[i] = s.stack_[i]; } template void ACE_Bounded_Stack::operator= (const ACE_Bounded_Stack &s) { ACE_TRACE ("ACE_Bounded_Stack::operator="); if (&s != this) { if (this->size_ < s.size_) { delete [] this->stack_; ACE_NEW (this->stack_, T[s.size_]); } this->top_ = s.top_; for (size_t i = 0; i < this->top_; i++) this->stack_[i] = s.stack_[i]; } } template ACE_Bounded_Stack::~ACE_Bounded_Stack (void) { ACE_TRACE ("ACE_Bounded_Stack::~ACE_Bounded_Stack"); delete [] this->stack_; } // ---------------------------------------- ACE_ALLOC_HOOK_DEFINE(ACE_Fixed_Stack) template void ACE_Fixed_Stack::dump (void) const { ACE_TRACE ("ACE_Fixed_Stack::dump"); } template ACE_Fixed_Stack::ACE_Fixed_Stack (void) : top_ (0), size_ (SIZE) { ACE_TRACE ("ACE_Fixed_Stack::ACE_Fixed_Stack"); } template ACE_Fixed_Stack::ACE_Fixed_Stack (const ACE_Fixed_Stack &s) : top_ (s.top_), size_ (s.size_) { ACE_TRACE ("ACE_Fixed_Stack::ACE_Fixed_Stack"); for (size_t i = 0; i < this->top_; i++) this->stack_[i] = s.stack_[i]; } template void ACE_Fixed_Stack::operator= (const ACE_Fixed_Stack &s) { ACE_TRACE ("ACE_Fixed_Stack::operator="); if (&s != this) { this->top_ = s.top_; for (size_t i = 0; i < this->top_; i++) this->stack_[i] = s.stack_[i]; } } template ACE_Fixed_Stack::~ACE_Fixed_Stack (void) { ACE_TRACE ("ACE_Fixed_Stack::~ACE_Fixed_Stack"); delete [] this->stack_; } //---------------------------------------- ACE_ALLOC_HOOK_DEFINE(ACE_Unbounded_Stack) template void ACE_Unbounded_Stack::dump (void) const { ACE_TRACE ("ACE_Unbounded_Stack::dump"); } template ACE_Unbounded_Stack::ACE_Unbounded_Stack (void) : head_ (0), cur_size_ (0) { ACE_NEW (this->head_, ACE_Node); this->head_->next_ = this->head_; ACE_TRACE ("ACE_Unbounded_Stack::ACE_Unbounded_Stack"); } template void ACE_Unbounded_Stack::delete_all_nodes (void) { ACE_TRACE ("ACE_Unbounded_Stack::delete_all_nodes"); while (this->is_empty () == 0) { ACE_Node *temp = this->head_->next_; this->head_->next_ = temp->next_; delete temp; } ACE_ASSERT (this->head_ == this->head_->next_ && this->is_empty ()); } template void ACE_Unbounded_Stack::copy_all_nodes (const ACE_Unbounded_Stack &s) { ACE_TRACE ("ACE_Unbounded_Stack::copy_all_nodes"); ACE_ASSERT (this->head_ == this->head_->next_); ACE_Node *temp = this->head_; for (ACE_Node *s_temp = s.head_->next_; s_temp != s.head_; s_temp = s_temp->next_) { ACE_NEW (temp->next_, ACE_Node (s_temp->item_, temp->next_)); temp = temp->next_; } } template ACE_Unbounded_Stack::ACE_Unbounded_Stack (const ACE_Unbounded_Stack &s) : head_ (0) { ACE_NEW (this->head_, ACE_Node); this->head_->next_ = this->head_; ACE_TRACE ("ACE_Unbounded_Stack::ACE_Unbounded_Stack"); this->copy_all_nodes (s); } template void ACE_Unbounded_Stack::operator= (const ACE_Unbounded_Stack &s) { ACE_TRACE ("ACE_Unbounded_Stack::operator="); if (this != &s) { this->delete_all_nodes (); this->copy_all_nodes (s); } } template ACE_Unbounded_Stack::~ACE_Unbounded_Stack (void) { ACE_TRACE ("ACE_Unbounded_Stack::~ACE_Unbounded_Stack"); this->delete_all_nodes (); delete this->head_; } template int ACE_Unbounded_Stack::push (const T &new_item) { ACE_TRACE ("ACE_Unbounded_Stack::push"); ACE_Node *temp = 0; ACE_NEW_RETURN (temp, ACE_Node (new_item, this->head_->next_), -1); this->head_->next_ = temp; return 0; } template int ACE_Unbounded_Stack::pop (T &item) { ACE_TRACE ("ACE_Unbounded_Stack::pop"); if (this->is_empty ()) return -1; else { ACE_Node *temp = this->head_->next_; item = temp->item_; this->head_->next_ = temp->next_; delete temp; return 0; } } template int ACE_Unbounded_Stack::find (const T &item) const { // ACE_TRACE ("ACE_Unbounded_Stack::find"); // Set into the dummy node. this->head_->item_ = item; ACE_Node *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 int ACE_Unbounded_Stack::insert (const T &item) { // ACE_TRACE ("ACE_Unbounded_Stack::insert"); if (this->find (item) == 0) return 1; else return this->push (item); } template int ACE_Unbounded_Stack::remove (const T &item) { // ACE_TRACE ("ACE_Unbounded_Stack::remove"); // Insert the item to be founded into the dummy node. this->head_->item_ = item; ACE_Node *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 *temp = curr->next_; // Skip over the node that we're deleting. curr->next_ = temp->next_; this->cur_size_--; delete temp; return 0; } } template ACE_Unbounded_Queue::ACE_Unbounded_Queue (void) : head_ (0), cur_size_ (0) { ACE_TRACE ("ACE_Unbounded_Queue::ACE_Unbounded_Queue (void)"); ACE_NEW (this->head_, ACE_Node); // Make the list circular by pointing it back to itself. this->head_->next_ = this->head_; } template ACE_Unbounded_Queue::ACE_Unbounded_Queue (const ACE_Unbounded_Queue &us) : head_ (0), cur_size_ (0) { ACE_TRACE ("ACE_Unbounded_Queue::ACE_Unbounded_Queue"); ACE_NEW (this->head_, ACE_Node); this->head_->next_ = this->head_; this->copy_nodes (us); } template void ACE_Unbounded_Queue::operator= (const ACE_Unbounded_Queue &us) { ACE_TRACE ("ACE_Unbounded_Queue::operator="); if (this != &us) { this->delete_nodes (); this->copy_nodes (us); } } ACE_ALLOC_HOOK_DEFINE(ACE_Unbounded_Queue) template void ACE_Unbounded_Queue::dump (void) const { ACE_TRACE ("ACE_Unbounded_Queue::dump"); ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); ACE_DEBUG ((LM_DEBUG, "\nhead_ = %u", this->head_)); ACE_DEBUG ((LM_DEBUG, "\nhead_->next_ = %u", this->head_->next_)); ACE_DEBUG ((LM_DEBUG, "\ncur_size_ = %d\n", this->cur_size_)); T *item = 0; size_t count = 1; for (ACE_Unbounded_Queue_Iterator iter (*(ACE_Unbounded_Queue *) this); iter.next (item) != 0; iter.advance ()) ACE_DEBUG ((LM_DEBUG, "count = %d\n", count++)); ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); } template void ACE_Unbounded_Queue::copy_nodes (const ACE_Unbounded_Queue &us) { for (ACE_Node *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 void ACE_Unbounded_Queue::delete_nodes (void) { ACE_Node *curr = this->head_->next_; // Keep looking until we've hit the dummy node. while (curr != this->head_) { ACE_Node *temp = curr; curr = curr->next_; delete temp; this->cur_size_--; } // Reset the list to be a circular list with just a dummy node. this->head_->next_ = this->head_; } template ACE_Unbounded_Queue::~ACE_Unbounded_Queue (void) { ACE_TRACE ("ACE_Unbounded_Queue::~ACE_Unbounded_Queue (void)"); this->delete_nodes (); delete this->head_; this->head_ = 0; } template int ACE_Unbounded_Queue::enqueue_head (const T &new_item) { ACE_TRACE ("ACE_Unbounded_Queue::enqueue_tail"); ACE_Node *temp; // Create a new node that points to the original head. ACE_NEW_RETURN (temp, ACE_Node (new_item, this->head_->next_), -1); // Link this pointer into the front of the list. this->head_->next_ = temp; this->cur_size_++; return 0; } template int ACE_Unbounded_Queue::enqueue_tail (const T &new_item) { ACE_TRACE ("ACE_Unbounded_Queue::enqueue_head"); ACE_Node *temp; // Insert into the old dummy node location. this->head_->item_ = new_item; // Create a new dummy node. ACE_NEW_RETURN (temp, ACE_Node (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 int ACE_Unbounded_Queue::dequeue_head (T &item) { ACE_TRACE ("ACE_Unbounded_Queue::dequeue_head"); // Check for empty queue. if (this->is_empty ()) return -1; ACE_Node *temp = this->head_->next_; item = temp->item_; this->head_->next_ = temp->next_; delete temp; --this->cur_size_; return 0; } template void ACE_Unbounded_Queue::reset (void) { ACE_TRACE ("reset"); this->delete_nodes (); } template int ACE_Unbounded_Queue::get (T *&item, size_t index) const { ACE_TRACE ("ACE_Unbounded_Queue::get"); ACE_Node *curr = this->head_->next_; size_t i; for (i = 0; i < this->cur_size_; i++) { if (i == index) break; curr = curr->next_; } if (i < this->cur_size_) { item = &curr->item_; return 0; } else return -1; } template int ACE_Unbounded_Queue::set (const T &item, size_t index) { ACE_TRACE ("ACE_Unbounded_Queue::set"); ACE_Node *curr = this->head_->next_; size_t i; for (i = 0; i < index && 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 == index) { // 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 < index; 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 void ACE_Unbounded_Queue_Iterator::dump (void) const { // ACE_TRACE ("ACE_Unbounded_Queue_Iterator::dump"); } template ACE_Unbounded_Queue_Iterator::ACE_Unbounded_Queue_Iterator (ACE_Unbounded_Queue &q) : current_ (q.head_->next_), queue_ (q) { // ACE_TRACE ("ACE_Unbounded_Queue_Iterator::ACE_Unbounded_Queue_Iterator"); } template int ACE_Unbounded_Queue_Iterator::advance (void) { // ACE_TRACE ("ACE_Unbounded_Queue_Iterator::advance"); this->current_ = this->current_->next_; return this->current_ != this->queue_.head_; } template int ACE_Unbounded_Queue_Iterator::done (void) const { ACE_TRACE ("ACE_Unbounded_Queue_Iterator::done"); return this->current_ == this->queue_.head_; } template int ACE_Unbounded_Queue_Iterator::next (T *&item) { // ACE_TRACE ("ACE_Unbounded_Queue_Iterator::next"); if (this->current_ == this->queue_.head_) return 0; else { item = &this->current_->item_; return 1; } } ACE_ALLOC_HOOK_DEFINE(ACE_Fixed_Set) template size_t ACE_Fixed_Set::size (void) const { return this->cur_size_; } template size_t ACE_Bounded_Set::size (void) const { ACE_TRACE ("ACE_Bounded_Set::size"); return this->cur_size_; } template size_t ACE_Unbounded_Set::size (void) const { // ACE_TRACE ("ACE_Unbounded_Set::size"); return this->cur_size_; } template void ACE_Fixed_Set::dump (void) const { ACE_TRACE ("ACE_Fixed_Set::dump"); } template ACE_Fixed_Set::~ACE_Fixed_Set (void) { ACE_TRACE ("ACE_Fixed_Set::~ACE_Fixed_Set"); this->cur_size_ = 0; } template ACE_Fixed_Set::ACE_Fixed_Set (const ACE_Fixed_Set &fs) : cur_size_ (fs.cur_size_) { ACE_TRACE ("ACE_Fixed_Set::ACE_Fixed_Set"); for (size_t i = 0; i < this->cur_size_; i++) this->search_structure_[i] = fs.search_structure_[i]; } template void ACE_Fixed_Set::operator= (const ACE_Fixed_Set &fs) { ACE_TRACE ("ACE_Fixed_Set::operator="); if (this != &fs) { this->cur_size_ = fs.cur_size_; for (size_t i = 0; i < this->cur_size_; i++) this->search_structure_[i] = fs.search_structure_[i]; } } template ACE_Fixed_Set::ACE_Fixed_Set (void) : cur_size_ (0), max_size_ (SIZE) { ACE_TRACE ("ACE_Fixed_Set::ACE_Fixed_Set"); for (size_t i = 0; i < this->max_size_; i++) this->search_structure_[i].is_free_ = 1; } template int ACE_Fixed_Set::find (const T &item) const { ACE_TRACE ("ACE_Fixed_Set::find"); for (size_t i = 0; i < this->cur_size_; i++) if (this->search_structure_[i].item_ == item && this->search_structure_[i].is_free_ == 0) return 0; return -1; } template int ACE_Fixed_Set::insert (const T &item) { ACE_TRACE ("ACE_Fixed_Set::insert"); int first_free = -1; // Keep track of first free slot. size_t i; for (i = 0; i < this->cur_size_; i++) // First, make sure we don't allow duplicates. if (this->search_structure_[i].item_ == item && this->search_structure_[i].is_free_ == 0) return 1; else if (this->search_structure_[i].is_free_ && first_free == -1) first_free = i; // If we found a free spot let's reuse it. if (first_free > -1) { this->search_structure_[first_free].item_ = item; this->search_structure_[first_free].is_free_ = 0; return 0; } // Insert at the end of the active portion. else if (i < this->max_size_) { this->search_structure_[i].item_ = item; this->search_structure_[i].is_free_ = 0; this->cur_size_++; return 0; } else /* No more room! */ { errno = ENOMEM; return -1; } } template int ACE_Fixed_Set::remove (const T &item) { ACE_TRACE ("ACE_Fixed_Set::remove"); for (size_t i = 0; i < this->cur_size_; i++) if (this->search_structure_[i].item_ == item) { // Mark this entry as being free. this->search_structure_[i].is_free_ = 1; // If we just unbound the highest entry, then we need to // figure out where the next highest active entry is. if (i + 1 == this->cur_size_) { while (i > 0 && this->search_structure_[--i].is_free_) continue; if (i == 0 && this->search_structure_[i].is_free_) this->cur_size_ = 0; else this->cur_size_ = i + 1; } return 0; } return -1; } ACE_ALLOC_HOOK_DEFINE(ACE_Fixed_Set_Iterator) template void ACE_Fixed_Set_Iterator::dump (void) const { ACE_TRACE ("ACE_Fixed_Set_Iterator::dump"); } template ACE_Fixed_Set_Iterator::ACE_Fixed_Set_Iterator (ACE_Fixed_Set &s) : s_ (s), next_ (-1) { ACE_TRACE ("ACE_Fixed_Set_Iterator::ACE_Fixed_Set_Iterator"); this->advance (); } template int ACE_Fixed_Set_Iterator::advance (void) { ACE_TRACE ("ACE_Fixed_Set_Iterator::advance"); for (++this->next_; size_t (this->next_) < this->s_.cur_size_ && this->s_.search_structure_[this->next_].is_free_; ++this->next_) continue; return size_t (this->next_) < this->s_.cur_size_; } template int ACE_Fixed_Set_Iterator::done (void) const { ACE_TRACE ("ACE_Fixed_Set_Iterator::done"); return size_t (this->next_) >= this->s_.cur_size_; } template int ACE_Fixed_Set_Iterator::next (T *&item) { ACE_TRACE ("ACE_Fixed_Set_Iterator::next"); if (size_t (this->next_) < this->s_.cur_size_) { item = &this->s_.search_structure_[this->next_].item_; return 1; } else return 0; } ACE_ALLOC_HOOK_DEFINE(ACE_Bounded_Set) template void ACE_Bounded_Set::dump (void) const { ACE_TRACE ("ACE_Bounded_Set::dump"); } template ACE_Bounded_Set::~ACE_Bounded_Set (void) { ACE_TRACE ("ACE_Bounded_Set::~ACE_Bounded_Set"); delete [] this->search_structure_; } template ACE_Bounded_Set::ACE_Bounded_Set (void) : cur_size_ (0), max_size_ (size_t (ACE_Bounded_Set::DEFAULT_SIZE)) { ACE_TRACE ("ACE_Bounded_Set::ACE_Bounded_Set"); ACE_NEW (this->search_structure_, ACE_Bounded_Set::Search_Structure[this->max_size_]); for (size_t i = 0; i < this->max_size_; i++) this->search_structure_[i].is_free_ = 1; } template ACE_Bounded_Set::ACE_Bounded_Set (const ACE_Bounded_Set &bs) : cur_size_ (bs.cur_size_), max_size_ (bs.max_size_) { ACE_TRACE ("ACE_Bounded_Set::ACE_Bounded_Set"); ACE_NEW (this->search_structure_, ACE_Bounded_Set::Search_Structure[this->max_size_]); for (size_t i = 0; i < this->cur_size_; i++) this->search_structure_[i] = bs.search_structure_[i]; } template void ACE_Bounded_Set::operator= (const ACE_Bounded_Set &bs) { ACE_TRACE ("ACE_Bounded_Set::operator="); if (this != &bs) { if (this->max_size_ < bs.cur_size_) { delete [] this->search_structure_; ACE_NEW (this->search_structure_, ACE_Bounded_Set::Search_Structure[bs.cur_size_]); this->max_size_ = bs.cur_size_; } this->cur_size_ = bs.cur_size_; for (size_t i = 0; i < this->cur_size_; i++) this->search_structure_[i] = bs.search_structure_[i]; } } template ACE_Bounded_Set::ACE_Bounded_Set (size_t size) : cur_size_ (0), max_size_ (size) { ACE_TRACE ("ACE_Bounded_Set::ACE_Bounded_Set"); ACE_NEW (this->search_structure_, ACE_Bounded_Set::Search_Structure[size]); for (size_t i = 0; i < this->max_size_; i++) this->search_structure_[i].is_free_ = 1; } template int ACE_Bounded_Set::find (const T &item) const { ACE_TRACE ("ACE_Bounded_Set::find"); for (size_t i = 0; i < this->cur_size_; i++) if (this->search_structure_[i].item_ == item && this->search_structure_[i].is_free_ == 0) return 0; return -1; } template int ACE_Bounded_Set::insert (const T &item) { ACE_TRACE ("ACE_Bounded_Set::insert"); int first_free = -1; // Keep track of first free slot. size_t i; for (i = 0; i < this->cur_size_; i++) // First, make sure we don't allow duplicates. if (this->search_structure_[i].item_ == item && this->search_structure_[i].is_free_ == 0) return 1; else if (this->search_structure_[i].is_free_ && first_free == -1) first_free = i; if (first_free > -1) // If we found a free spot let's reuse it. { this->search_structure_[first_free].item_ = item; this->search_structure_[first_free].is_free_ = 0; return 0; } else if (i < this->max_size_) // Insert at the end of the active portion. { this->search_structure_[i].item_ = item; this->search_structure_[i].is_free_ = 0; this->cur_size_++; return 0; } else /* No more room! */ { errno = ENOMEM; return -1; } } template int ACE_Bounded_Set::remove (const T &item) { ACE_TRACE ("ACE_Bounded_Set::remove"); for (size_t i = 0; i < this->cur_size_; i++) if (this->search_structure_[i].item_ == item) { // Mark this entry as being free. this->search_structure_[i].is_free_ = 1; // If we just unbound the highest entry, then we need to // figure out where the next highest active entry is. if (i + 1 == this->cur_size_) { while (i > 0 && this->search_structure_[--i].is_free_) continue; if (i == 0 && this->search_structure_[i].is_free_) this->cur_size_ = 0; else this->cur_size_ = i + 1; } return 0; } return -1; } ACE_ALLOC_HOOK_DEFINE(ACE_Bounded_Set_Iterator) template void ACE_Bounded_Set_Iterator::dump (void) const { ACE_TRACE ("ACE_Bounded_Set_Iterator::dump"); } template ACE_Bounded_Set_Iterator::ACE_Bounded_Set_Iterator (ACE_Bounded_Set &s) : s_ (s), next_ (-1) { ACE_TRACE ("ACE_Bounded_Set_Iterator::ACE_Bounded_Set_Iterator"); this->advance (); } template int ACE_Bounded_Set_Iterator::advance (void) { ACE_TRACE ("ACE_Bounded_Set_Iterator::advance"); for (++this->next_; size_t (this->next_) < this->s_.cur_size_ && this->s_.search_structure_[this->next_].is_free_; ++this->next_) continue; return size_t (this->next_) < this->s_.cur_size_; } template int ACE_Bounded_Set_Iterator::done (void) const { ACE_TRACE ("ACE_Bounded_Set_Iterator::done"); return size_t (this->next_) >= this->s_.cur_size_; } template int ACE_Bounded_Set_Iterator::next (T *&item) { ACE_TRACE ("ACE_Bounded_Set_Iterator::next"); if (size_t (this->next_) < this->s_.cur_size_) { item = &this->s_.search_structure_[this->next_].item_; return 1; } else return 0; } ACE_ALLOC_HOOK_DEFINE(ACE_Node) template ACE_Node::~ACE_Node (void) { } template ACE_Node::ACE_Node (const T &i, ACE_Node *n) : next_ (n), item_ (i) { // ACE_TRACE ("ACE_Node::ACE_Node"); } template ACE_Node::ACE_Node (ACE_Node *n, int /* MS_SUCKS */) : next_ (n) { // ACE_TRACE ("ACE_Node::ACE_Node"); } template ACE_Node::ACE_Node (const ACE_Node &s) : next_ (s.next_), item_ (s.item_) { // ACE_TRACE ("ACE_Node::ACE_Node"); } ACE_ALLOC_HOOK_DEFINE(ACE_Unbounded_Set) template int ACE_Unbounded_Set::insert_tail (const T &item) { // ACE_TRACE ("ACE_Unbounded_Queue::insert_tail"); ACE_Node *temp; // Insert into the old dummy node location. this->head_->item_ = item; // Create a new dummy node. ACE_NEW_RETURN (temp, ACE_Node (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 void ACE_Unbounded_Set::dump (void) const { ACE_TRACE ("ACE_Unbounded_Set::dump"); ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); ACE_DEBUG ((LM_DEBUG, "\nhead_ = %u", this->head_)); ACE_DEBUG ((LM_DEBUG, "\nhead_->next_ = %u", this->head_->next_)); ACE_DEBUG ((LM_DEBUG, "\ncur_size_ = %d\n", this->cur_size_)); T *item = 0; size_t count = 1; for (ACE_Unbounded_Set_Iterator iter (*(ACE_Unbounded_Set *) this); iter.next (item) != 0; iter.advance ()) ACE_DEBUG ((LM_DEBUG, "count = %d\n", count++)); ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); } template void ACE_Unbounded_Set::copy_nodes (const ACE_Unbounded_Set &us) { for (ACE_Node *curr = us.head_->next_; curr != us.head_; curr = curr->next_) this->insert_tail (curr->item_); } template void ACE_Unbounded_Set::delete_nodes (void) { ACE_Node *curr = this->head_->next_; // Keep looking until we've hit the dummy node. while (curr != this->head_) { ACE_Node *temp = curr; curr = curr->next_; delete temp; this->cur_size_--; } // Reset the list to be a circular list with just a dummy node. this->head_->next_ = this->head_; } template ACE_Unbounded_Set::~ACE_Unbounded_Set (void) { // ACE_TRACE ("ACE_Unbounded_Set::~ACE_Unbounded_Set"); this->delete_nodes (); // Delete the dummy node. delete this->head_; this->head_ = 0; } template ACE_Unbounded_Set::ACE_Unbounded_Set (void) : head_ (0), cur_size_ (0) { // ACE_TRACE ("ACE_Unbounded_Set::ACE_Unbounded_Set"); ACE_NEW (this->head_, ACE_Node); // Make the list circular by pointing it back to itself. this->head_->next_ = this->head_; } template ACE_Unbounded_Set::ACE_Unbounded_Set (const ACE_Unbounded_Set &us) : head_ (0), cur_size_ (0) { ACE_TRACE ("ACE_Unbounded_Set::ACE_Unbounded_Set"); ACE_NEW (this->head_, ACE_Node); this->head_->next_ = this->head_; this->copy_nodes (us); } template void ACE_Unbounded_Set::operator= (const ACE_Unbounded_Set &us) { ACE_TRACE ("ACE_Unbounded_Set::operator="); if (this != &us) { this->delete_nodes (); this->copy_nodes (us); } } template int ACE_Unbounded_Set::find (const T &item) const { // ACE_TRACE ("ACE_Unbounded_Stack::find"); // Set into the dummy node. this->head_->item_ = item; ACE_Node *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 int ACE_Unbounded_Set::insert (const T &item) { // ACE_TRACE ("ACE_Unbounded_Set::insert"); if (this->find (item) == 0) return 1; else return this->insert_tail (item); } template int ACE_Unbounded_Set::remove (const T &item) { // ACE_TRACE ("ACE_Unbounded_Set::remove"); // Insert the item to be founded into the dummy node. this->head_->item_ = item; ACE_Node *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 *temp = curr->next_; // Skip over the node that we're deleting. curr->next_ = temp->next_; this->cur_size_--; delete temp; return 0; } } ACE_ALLOC_HOOK_DEFINE(ACE_Unbounded_Set_Iterator) template void ACE_Unbounded_Set_Iterator::dump (void) const { // ACE_TRACE ("ACE_Unbounded_Set_Iterator::dump"); } template ACE_Unbounded_Set_Iterator::ACE_Unbounded_Set_Iterator (ACE_Unbounded_Set &s) : current_ (s.head_->next_), set_ (s) { // ACE_TRACE ("ACE_Unbounded_Set_Iterator::ACE_Unbounded_Set_Iterator"); } template int ACE_Unbounded_Set_Iterator::advance (void) { // ACE_TRACE ("ACE_Unbounded_Set_Iterator::advance"); this->current_ = this->current_->next_; return this->current_ != this->set_.head_; } template int ACE_Unbounded_Set_Iterator::done (void) const { ACE_TRACE ("ACE_Unbounded_Set_Iterator::done"); return this->current_ == this->set_.head_; } template int ACE_Unbounded_Set_Iterator::next (T *&item) { // ACE_TRACE ("ACE_Unbounded_Set_Iterator::next"); if (this->current_ == this->set_.head_) return 0; else { item = &this->current_->item_; return 1; } } template void ACE_Unbounded_Stack_Iterator::dump (void) const { // ACE_TRACE ("ACE_Unbounded_Stack_Iterator::dump"); } template ACE_Unbounded_Stack_Iterator::ACE_Unbounded_Stack_Iterator (ACE_Unbounded_Stack &q) : current_ (q.head_->next_), stack_ (q) { // ACE_TRACE ("ACE_Unbounded_Stack_Iterator::ACE_Unbounded_Stack_Iterator"); } template int ACE_Unbounded_Stack_Iterator::advance (void) { // ACE_TRACE ("ACE_Unbounded_Stack_Iterator::advance"); this->current_ = this->current_->next_; return this->current_ != this->stack_.head_; } template int ACE_Unbounded_Stack_Iterator::done (void) const { ACE_TRACE ("ACE_Unbounded_Stack_Iterator::done"); return this->current_ == this->stack_.head_; } template int ACE_Unbounded_Stack_Iterator::next (T *&item) { // ACE_TRACE ("ACE_Unbounded_Stack_Iterator::next"); if (this->current_ == this->stack_.head_) return 0; else { item = &this->current_->item_; return 1; } } #endif /* ACE_CONTAINERS_C */