From 01950efe74ac03f228c428b4726f7afcca5d36f0 Mon Sep 17 00:00:00 2001 From: schmidt Date: Mon, 5 May 1997 22:34:06 +0000 Subject: *** empty log message *** --- ChangeLog-97a | 55 +- README | 2 +- ace/Containers.cpp | 1182 ++++++++++++++++++++ ace/Containers.h | 707 ++++++++++++ ace/Containers.i | 105 ++ ace/Local_Name_Space.cpp | 4 +- ace/Local_Name_Space.h | 2 +- ace/Local_Tokens.cpp | 2 +- ace/Local_Tokens.h | 2 +- ace/Log_Msg.cpp | 6 +- ace/Name_Space.h | 2 +- ace/Naming_Context.h | 2 +- ace/OS.cpp | 2 +- ace/OS.h | 6 +- ace/OS.i | 12 +- ace/Proactor.cpp | 2 +- ace/Remote_Name_Space.h | 2 +- ace/Service_Config.cpp | 4 +- ace/Service_Config.h | 2 +- ace/Set.cpp | 764 ------------- ace/Set.h | 394 ------- ace/Set.i | 5 - ace/Signal.h | 2 +- ace/Stack.cpp | 446 -------- ace/Stack.h | 291 ----- ace/Stack.i | 105 -- ace/Timer_Heap_T.h | 2 +- ace/Timer_Queue.cpp | 2 +- apps/Gateway/Gateway/Consumer_Dispatch_Set.h | 2 +- apps/Gateway/Gateway/Gateway.cpp | 2 +- .../ASX/Event_Server/Transceiver/transceiver.cpp | 40 +- examples/Misc/test_set.cpp | 50 +- netsvcs/lib/Name_Handler.cpp | 2 +- netsvcs/lib/TS_Clerk_Handler.cpp | 2 +- netsvcs/lib/TS_Server_Handler.cpp | 2 +- 35 files changed, 2106 insertions(+), 2106 deletions(-) create mode 100644 ace/Containers.cpp create mode 100644 ace/Containers.h create mode 100644 ace/Containers.i delete mode 100644 ace/Set.cpp delete mode 100644 ace/Set.h delete mode 100644 ace/Set.i delete mode 100644 ace/Stack.cpp delete mode 100644 ace/Stack.h delete mode 100644 ace/Stack.i diff --git a/ChangeLog-97a b/ChangeLog-97a index c3dcdf4560a..a223eaf6015 100644 --- a/ChangeLog-97a +++ b/ChangeLog-97a @@ -1,11 +1,49 @@ -Mon May 05 14:53:11 1997 David L. Levine +Mon May 5 08:19:54 1997 Douglas C. Schmidt - * netsvcs/lib/Server_Logging_Handler.cpp: fixed ACE_Svc_Handler - specializations, yet again, for Linux w/LXPthreads. Thanks to - Luis Lopes for reporting this - problem with sufficient detail for us to track it down. + * ace/Containers.cpp (set): Optimized for the common case where + we're increasing the size of the set by 1. -Mon May 5 08:19:54 1997 Douglas C. Schmidt + * ace/Containers: Merged the ACE_Set_Node, ACE_Stack_Node, and + ACE_Set_Node into a single "ACE_Node" class. This tidies up the + code quite a bit. + + * ace: Removed the Set.* and Stack.* files and replaced them with + the Containers.* files. This file contains the ACE_*Stack, + ACE_*Queue, and ACE_*Set classes. If this revised file scheme + breaks existing code please let me know and I'll provide + backwards compatibility. + + * ace/Stack: Changed the name of ACE_Unbounded_Queue::enqueue() to + ACE_Unbounded_Queue::enqueue_tail() and also added + ACE_Unbounded_Queue::enqueue_head(). + + * ace/OS: Changed the names of the parameters of the ACE_OS::mem* + methods from ACE_OS::mem* (void *s, const void *t) to + ACE_OS::mem* (void *t, const void *s) since "t" should stand for + "target" and "s" for "source." Thanks to Andres Kruse + for pointing this out. + + * ace/Stack: Removed the peek() method from ACE_Unbounded_Queue. + This functionality is now subsumed by the get(..., 0) method. + If this breaks any existing code please let me know. + + * ace/Stack.h: Moved all the functionality from ACE_Unbounded_Set + into ACE_Unbounded_Queue. That's really where this belonged in + the first place. Thanks to David Levine for noticing this. + + * ace/Set.h: Moved ACE_Set_Node from the *.cpp file into the *.cpp + file in anticipation of AIX C++ compiler bugs ;-). + + * examples/ASX/Event_Server/Transceiver/transceiver.cpp: + Rearranged the location where we register to receive standard + input so that the socket handle will not be initialized at this + point. Thanks to craig perras for + reporting this. + + * examples/ASX/Event_Server/Transceiver/transceiver.cpp + (Event_Transceiver): Make sure to #ifdef around SIGQUIT for + WIN32 since it lacks this signal. Thanks to craig perras + for reporting this. * ace/config-osf1-4.0-g++.h: Removed the ACE_LACKS_SIGNED_CHAR since this seems to be compiler specific. Thanks to Thilo for @@ -59,6 +97,11 @@ Mon May 5 17:16:41 1997 Carlos O'Ryan Mon May 05 11:50:39 1997 David L. Levine + * netsvcs/lib/Server_Logging_Handler.cpp: fixed ACE_Svc_Handler + specializations, yet again, for Linux w/LXPthreads. Thanks to + Luis Lopes for reporting this + problem with sufficient detail for us to track it down. + * ace/Stack.* (ACE_Unbounded_Queue): 1) made peek () const. 2) added another peek (u_int index = 0) function that can peek diff --git a/README b/README index 1f29905869f..1f87531a63b 100644 --- a/README +++ b/README @@ -375,7 +375,7 @@ Audun Tornquist Sandeep Joshi Kirk Sinnard <1764@mn.lawson.lawson.com> Bernd Hofner -Craig Perras +Craig Perras Kirk Sinnard Matthew Newhook Gerolf Wendland diff --git a/ace/Containers.cpp b/ace/Containers.cpp new file mode 100644 index 00000000000..5a927228a88 --- /dev/null +++ b/ace/Containers.cpp @@ -0,0 +1,1182 @@ +// 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) + return; + else 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) + return; + 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) +{ + ACE_NEW (this->last_resort_, ACE_Node); + 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->head_ != 0) + { + ACE_Node *temp = this->head_; + this->head_ = this->head_->next_; + delete temp; + } + + delete this->last_resort_; + this->last_resort_ = 0; +} + +template void +ACE_Unbounded_Stack::copy_all_nodes (const ACE_Unbounded_Stack &s) +{ + ACE_TRACE ("ACE_Unbounded_Stack::copy_all_nodes"); + // Push all of 's nodes onto our stack (this puts them in the + // reverse order). + ACE_Node *temp; + + for (temp = s.head_; + temp != 0; + temp = temp->next_) + { + if (!this->is_full ()) + this->push (temp->item_); + else + break; + } + + // Reverse the order of our stack. + + ACE_Node *prev = 0; + + for (temp = this->head_; temp != 0; ) + { + ACE_Node *next = temp->next_; + + temp->next_ = prev; + prev = temp; + temp = next; + } + + this->head_ = prev; +} + +template +ACE_Unbounded_Stack::ACE_Unbounded_Stack (const ACE_Unbounded_Stack &s) + : head_ (0) +{ + ACE_NEW (this->last_resort_, ACE_Node); + + 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) + return; + + 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 (); +} + +template void +ACE_Unbounded_Stack::push (const T &new_item) +{ + ACE_TRACE ("ACE_Unbounded_Stack::push"); + + ACE_Node *temp = new ACE_Node (new_item, this->head_); + + if (temp == 0) + { + temp = this->last_resort_; + this->last_resort_ = 0; + } + + this->head_ = temp; +} + +template void +ACE_Unbounded_Stack::pop (T &item) +{ + ACE_TRACE ("ACE_Unbounded_Stack::pop"); + item = this->head_->item_; + ACE_Node *temp = this->head_; + this->head_ = this->head_->next_; + + // Restore the node of last resort if necessary. + if (this->last_resort_ == 0) + this->last_resort_ = temp; + else + delete temp; +} + +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) + return; + + 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_->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->head_ == this->head_->next_) + 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 1; + } + else + return 0; +} + +template int +ACE_Unbounded_Queue::set (const T &item, + size_t index) +{ + ACE_TRACE ("ACE_Unbounded_Queue::set"); + + ACE_Node *curr = this->head_->next_; + + int result = 1; + size_t i; + + for (i = 0; i <= index; i++) + { + if (i == this->cur_size_) + { + // We need to expand the list. + + result = 0; + + // A common case will be increasing the set size by 1. + // Therefore, we'll optimize for this case. + if (i + i == index) + // Try to expand the size of the set by 1. + return this->enqueue_tail (item); + else + { + T dummy; + + // 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; + } + } + else + curr = curr->next_; + } + + curr->item_ = item; + return result; +} + +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) + return; + + 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 1; + } + + return 0; +} + +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 1; + } + } + return 0; +} + +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) + return; + else 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 1; + } + + return 0; +} + +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 1; + } + } + return 0; +} + +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 (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 int +ACE_Unbounded_Set::find (const T &item) const +{ +// ACE_TRACE ("ACE_Unbounded_Set::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_ ? 0 : 1; +} + +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) + return; + + this->delete_nodes (); + this->copy_nodes (us); +} + +template int +ACE_Unbounded_Set::insert (const T &item) +{ +// ACE_TRACE ("ACE_Unbounded_Set::insert"); + if (this->find (item) == 0) + return this->insert_tail (item); + else + return 1; +} + +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 0; // 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 1; + } +} + +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; + } +} + +#endif /* ACE_CONTAINERS_C */ diff --git a/ace/Containers.h b/ace/Containers.h new file mode 100644 index 00000000000..a763a016abf --- /dev/null +++ b/ace/Containers.h @@ -0,0 +1,707 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ace +// +// = FILENAME +// Containers.h +// +// = AUTHOR +// Doug Schmidt +// +// ============================================================================ + +#if !defined (ACE_CONTAINERS_H) +#define ACE_CONTAINERS_H + +#include "ace/ACE.h" + +template +class ACE_Bounded_Stack + // = TITLE + // Implement a generic LIFO abstract data type. + // + // = DESCRIPTION + // This implementation of a Stack uses a bounded array + // that is allocated dynamically. +{ +public: + // = Initialization, assignemnt, and termination methods. + ACE_Bounded_Stack (size_t size); + // Initialize a new stack so that it is empty. + + ACE_Bounded_Stack (const ACE_Bounded_Stack &s); + // The copy constructor (performs initialization). + + void operator= (const ACE_Bounded_Stack &s); + // Assignment operator (performs assignment). + + ~ACE_Bounded_Stack (void); + // Perform actions needed when stack goes out of scope. + + // = Classic Stack operations. + + void push (const T &new_item); + // Place a new item on top of the stack. Does not check if the + // stack is full. + + void pop (T &item); + // Remove and return the top stack item. Does not check if stack + // is full. + + void top (T &item) const; + // Return top stack item without removing it. Does not check if + // stack is empty. + + // = Check boundary conditions for Stack operations. + + int is_empty (void) const; + // Returns 1 if the stack is empty, otherwise returns 0. + + int is_full (void) const; + // Returns 1 if the stack is full, otherwise returns 0. + + void dump (void) const; + // Dump the state of an object. + + ACE_ALLOC_HOOK_DECLARE; + // Declare the dynamic allocation hooks. + +private: + size_t size_; + // Size of the dynamically allocated data. + + size_t top_; + // Keeps track of the current top of stack. + + T *stack_; + // Holds the stack's contents. +}; + +//---------------------------------------- + +template +class ACE_Fixed_Stack + // = TITLE + // Implement a generic LIFO abstract data type. + // + // = DESCRIPTION + // This implementation of a Stack uses a fixed array + // with the size fixed at instantiation time. +{ +public: + // = Initialization, assignemnt, and termination methods. + ACE_Fixed_Stack (void); + // Initialize a new stack so that it is empty. + + ACE_Fixed_Stack (const ACE_Fixed_Stack &s); + // The copy constructor (performs initialization). + + void operator= (const ACE_Fixed_Stack &s); + // Assignment operator (performs assignment). + + ~ACE_Fixed_Stack (void); + // Perform actions needed when stack goes out of scope. + + // = Classic Stack operations. + + void push (const T &new_item); + // Place a new item on top of the stack. Does not check if the + // stack is full. + + void pop (T &item); + // Remove and return the top stack item. Does not check if stack + // is full. + + void top (T &item) const; + // Return top stack item without removing it. Does not check if + // stack is empty. + + // = Check boundary conditions for Stack operations. + + int is_empty (void) const; + // Returns 1 if the stack is empty, otherwise returns 0. + + int is_full (void) const; + // Returns 1 if the stack is full, otherwise returns 0. + + void dump (void) const; + // Dump the state of an object. + + ACE_ALLOC_HOOK_DECLARE; + // Declare the dynamic allocation hooks. + +private: + size_t size_; + // Size of the dynamically allocated data. + + size_t top_; + // Keeps track of the current top of stack. + + T stack_[SIZE]; + // Holds the stack's contents. +}; + +//---------------------------------------- + +// Forward declarations. +template class ACE_Unbounded_Set; +template class ACE_Unbounded_Set_Iterator; +template class ACE_Unbounded_Queue; +template class ACE_Unbounded_Queue_Iterator; +template class ACE_Unbounded_Stack; +template class ACE_Unbounded_Stack_Iterator; + +template +class ACE_Node + // = TITLE + // Implementation element in a Queue +{ + friend class ACE_Unbounded_Queue; + friend class ACE_Unbounded_Queue_Iterator; + friend class ACE_Unbounded_Set; + friend class ACE_Unbounded_Set_Iterator; + friend class ACE_Unbounded_Stack; + friend class ACE_Unbounded_Stack_Iterator; +private: + // = Initialization methods + ACE_Node (const T &i, ACE_Node *n); + ACE_Node (ACE_Node *n = 0, int MS_SUCKS = 0); + ACE_Node (const ACE_Node &n); + + ACE_Node *next_; + // Pointer to next element in the list of s. + + T item_; + // Current value of the item in this node. +}; + +template +class ACE_Unbounded_Stack + // = TITLE + // Implement a generic LIFO abstract data type. + // + // = DESCRIPTION + // This implementation of an unbounded Stack uses a linked list. +{ +public: + // = Initialization, assignemnt, and termination methods. + ACE_Unbounded_Stack (void); + // Initialize a new stack so that it is empty. + + ACE_Unbounded_Stack (const ACE_Unbounded_Stack &s); + // The copy constructor (performs initialization). + + void operator= (const ACE_Unbounded_Stack &s); + // Assignment operator (performs assignment). + + ~ACE_Unbounded_Stack (void); + // Perform actions needed when stack goes out of scope. + + // = Classic Stack operations. + + void push (const T &new_item); + // Place a new item on top of the stack. Does not check if the + // stack is full. + + void pop (T &item); + // Remove and return the top stack item. Does not check if stack + // is full. + + void top (T &item) const; + // Return top stack item without removing it. Does not check if + // stack is empty. + + // = Check boundary conditions for Stack operations. + + int is_empty (void) const; + // Returns 1 if the stack is empty, otherwise returns 0. + + int is_full (void) const; + // Returns 1 if the stack is full, otherwise returns 0. + + void dump (void) const; + // Dump the state of an object. + + ACE_ALLOC_HOOK_DECLARE; + // Declare the dynamic allocation hooks. + +private: + void delete_all_nodes (void); + // Delete all the nodes in the stack. + + void copy_all_nodes (const ACE_Unbounded_Stack &s); + // Copy all nodes from to . + + ACE_Node *head_; + // Head of the linked list of Nodes. + + ACE_Node *last_resort_; + // Use this node when all memory is exhausted... +}; + +template +class ACE_Unbounded_Queue; + +template +class ACE_Unbounded_Queue_Iterator + // = TITLE + // Implement an iterator over an unbounded queue. +{ +public: + // = Initialization method. + ACE_Unbounded_Queue_Iterator (ACE_Unbounded_Queue &); + + // = Iteration methods. + + int next (T *&next_item); + // Pass back the 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_Node *current_; + // Pointer to the current node in the iteration. + + ACE_Unbounded_Queue &queue_; + // Pointer to the queue we're iterating over. +}; + +template +class ACE_Unbounded_Queue + // = TITLE + // A Queue of "infinite" length. + // + // = DESCRIPTION + // This implementation of an unbounded queue uses a circular + // linked list with a dummy node. +{ + friend class ACE_Unbounded_Queue_Iterator; +public: + // = Initialization and termination methods. + ACE_Unbounded_Queue (void); + // construction. + + ACE_Unbounded_Queue (const ACE_Unbounded_Queue &); + // Copy constructor. + + void operator= (const ACE_Unbounded_Queue &); + // Assignment operator. + + ~ACE_Unbounded_Queue (void); + // construction. + + // = Classic queue operations. + int enqueue_tail (const T &new_item); + // Adds to the tail of the queue. Returns 0 on success, + // -1 on failure. + + int enqueue_head (const T &new_item); + // Adds to the head of the queue. Returns 0 on success, + // -1 on failure. + + int dequeue_head (T &item); + // Removes and returns the first on the queue. Returns 0 on + // success, -1 if the queue was empty. + + // = Additional utility methods. + + void reset (void); + // Reset the to be empty. + + int get (T *&item, size_t index = 0) const; + // Get the th element in the set. Returns 0 if the element + // isn't in the range <0..size() - 1>, else 1. + + int set (const T &item, size_t index); + // Set the th element in the set. Will pad out the set with + // empty nodes if is beyond the range <0..size() - 1>. + // Returns -1 on failure, 0 if isn't initially in range, and + // 1 otherwise. + + size_t size (void) const; + // The number of items in the queue. + + void dump (void) const; + // Dump the state of an object. + + ACE_ALLOC_HOOK_DECLARE; + // Declare the dynamic allocation hooks. + +protected: + void delete_nodes (void); + // Delete all the nodes in the queue. + + void copy_nodes (const ACE_Unbounded_Queue &); + // Copy nodes into this queue. + + ACE_Node *head_; + // Pointer to the dummy node in the circular linked Queue. + + size_t cur_size_; + // Current size of the queue. +}; + +template +class ACE_Unbounded_Set_Iterator + // = TITLE + // Implement an iterator over an unbounded set. +{ +public: + // = Initialization method. + ACE_Unbounded_Set_Iterator (ACE_Unbounded_Set &s); + + // = Iteration methods. + + int next (T *&next_item); + // Pass back the that hasn't been seen in the Set. + // 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 set 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 *current_; + // Pointer to the current node in the iteration. + + ACE_Unbounded_Set &set_; + // Pointer to the set we're iterating over. +}; + +template +class ACE_Unbounded_Set + // = TITLE + // Implement a simple unordered set of of unbounded size. + // + // = DESCRIPTION + // This implementation of an unordered set uses a circular + // linked list with a dummy node. This implementation does not + // allow duplicates. +{ +friend class ACE_Unbounded_Set_Iterator; +public: + // = Initialization and termination methods. + ACE_Unbounded_Set (void); + // Constructor. + + ACE_Unbounded_Set (const ACE_Unbounded_Set &); + // Copy constructor. + + void operator= (const ACE_Unbounded_Set &); + // Assignment operator. + + ~ACE_Unbounded_Set (void); + // Destructor. + + // = Classic unordered set operations. + int insert (const T &new_item); + // Insert into the set (doesn't allow duplicates). + // Returns -1 if failures occur, 1 if item is already present, else + // 0. + + int remove (const T &item); + // Remove first occurrence of from the set. Returns 1 if + // it removes the item, 0 if it can't find the item, and -1 if a + // failure occurs. + + int find (const T &item) const; + // Return first occurrence of from the set. + // Returns 0 if can't find, else 1. + + size_t size (void) const; + // Size of the set. + + void dump (void) const; + // Dump the state of an object. + + ACE_ALLOC_HOOK_DECLARE; + // Declare the dynamic allocation hooks. + +private: + int insert_tail (const T &item); + // Insert at the tail of the set (doesn't check for + // duplicates). + + void delete_nodes (void); + // Delete all the nodes in the Set. + + void copy_nodes (const ACE_Unbounded_Set &); + // Copy nodes into this set. + + ACE_Node *head_; + // Head of the linked list of Nodes. + + size_t cur_size_; + // Current size of the set. +}; + +// Forward declaration. +template +class ACE_Fixed_Set; + +template +class ACE_Fixed_Set_Iterator + // = TITLE + // Interates through an unordered set. + // + // = DESCRIPTION + // This implementation of an unordered set uses a fixed array. + // Allows deletions while iteration is occurring. +{ +public: + // = Initialization method. + ACE_Fixed_Set_Iterator (ACE_Fixed_Set &s); + + // = Iteration methods. + + int next (T *&next_item); + // Pass back the that hasn't been seen in the Set. + // 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 set 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_Fixed_Set &s_; + // Set we are iterating over. + + ssize_t next_; + // How far we've advanced over the set. +}; + +template +class ACE_Fixed_Set + // = TITLE + // Implement a simple unordered set of with maximum . + // + // = DESCRIPTION + // This implementation of an unordered set uses a fixed array. + // This implementation does not allow duplicates... +{ +friend class ACE_Fixed_Set_Iterator; +public: + // = Initialization and termination methods. + ACE_Fixed_Set (void); + // Constructor. + + ACE_Fixed_Set (size_t size); + // Constructor. + + ACE_Fixed_Set (const ACE_Fixed_Set &); + // Copy constructor. + + void operator = (const ACE_Fixed_Set &); + // Assignment operator. + + ~ACE_Fixed_Set (void); + // Destructor. + + // = Classic unordered set operations. + int insert (const T &new_item); + // Insert into the set (doesn't allow duplicates). + // Returns -1 if failures occur, 1 if item is already present, else + // 0. + + int remove (const T &item); + // Remove first occurrence of from the set. Returns 1 if + // it removes the item, 0 if it can't find the item, and -1 if a + // failure occurs. + + int find (const T &item) const; + // Return first occurrence of from the set. + // Returns 0 if can't find, else 1. + + size_t size (void) const; + // Size of the set. + + void dump (void) const; + // Dump the state of an object. + + ACE_ALLOC_HOOK_DECLARE; + // Declare the dynamic allocation hooks. + +private: + struct + { + T item_; + // Item in the set. + int is_free_; + // Keeps track of whether this item is in use or not. + } search_structure_[SIZE]; + // Holds the contents of the set. + + size_t cur_size_; + // Current size of the set. + + size_t max_size_; + // Maximum size of the set. +}; + +// Forward declaration. +template +class ACE_Bounded_Set; + +template +class ACE_Bounded_Set_Iterator + // = TITLE + // Interates through an unordered set. + // + // = DESCRIPTION + // This implementation of an unordered set uses a Bounded array. + // Allows deletions while iteration is occurring. +{ +public: + // = Initialization method. + ACE_Bounded_Set_Iterator (ACE_Bounded_Set &s); + + // = Iteration methods. + + int next (T *&next_item); + // Pass back the that hasn't been seen in the Set. + // 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 set 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_Bounded_Set &s_; + // Set we are iterating over. + + ssize_t next_; + // How far we've advanced over the set. +}; + +template +class ACE_Bounded_Set + // = TITLE + // Implement a simple unordered set of with maximum + // set at creation time. + // + // = DESCRIPTION + // This implementation of an unordered set uses a Bounded array. + // This implementation does not allow duplicates... +{ +friend class ACE_Bounded_Set_Iterator; +public: + enum + { + DEFAULT_SIZE = 10 + }; + + // = Initialization and termination methods. + ACE_Bounded_Set (void); + // Constructor. + + ACE_Bounded_Set (size_t size); + // Constructor. + + ACE_Bounded_Set (const ACE_Bounded_Set &); + // Copy constructor. + + void operator= (const ACE_Bounded_Set &); + // Assignment operator. + + ~ACE_Bounded_Set (void); + // Destructor + + // = Classic unordered set operations. + int insert (const T &new_item); + // Insert into the set (doesn't allow duplicates). + // Returns -1 if failures occur, 1 if item is already present, else + // 0. + + int remove (const T &item); + // Remove first occurrence of from the set. Returns 1 if it + // removes the item, 0 if it can't find the item, and -1 if a + // failure occurs. + + int find (const T &item) const; + // Return first occurrence of from the set. + // Returns 0 if can't find, else 1. + + size_t size (void) const; + // Size of the set. + + void dump (void) const; + // Dump the state of an object. + + ACE_ALLOC_HOOK_DECLARE; + // Declare the dynamic allocation hooks. + +private: + struct Search_Structure + { + T item_; + // Item in the set. + int is_free_; + // Keeps track of whether this item is in use or not. + }; + + Search_Structure *search_structure_; + // Holds the contents of the set. + + size_t cur_size_; + // Current size of the set. + + size_t max_size_; + // Maximum size of the set. +}; + +#if defined (__ACE_INLINE__) +#include "ace/Containers.i" +#endif /* __ACE_INLINE__ */ + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "ace/Containers.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +#pragma implementation ("Containers.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#endif /* ACE_CONTAINERS_H */ diff --git a/ace/Containers.i b/ace/Containers.i new file mode 100644 index 00000000000..18218b3f41c --- /dev/null +++ b/ace/Containers.i @@ -0,0 +1,105 @@ +/* -*- C++ -*- */ +// $Id$ + +// Containers.i + +template ACE_INLINE void +ACE_Bounded_Stack::push (const T &new_item) +{ + ACE_TRACE ("ACE_Bounded_Stack::push"); + this->stack_[this->top_++] = new_item; +} + +template ACE_INLINE void +ACE_Bounded_Stack::pop (T &item) +{ + ACE_TRACE ("ACE_Bounded_Stack::pop"); + item = this->stack_[--this->top_]; +} + +template ACE_INLINE void +ACE_Bounded_Stack::top (T &item) const +{ + ACE_TRACE ("ACE_Bounded_Stack::top"); + item = this->stack_[this->top_ - 1]; +} + +template ACE_INLINE int +ACE_Bounded_Stack::is_empty (void) const +{ + ACE_TRACE ("ACE_Bounded_Stack::is_empty"); + return this->top_ == 0; +} + +template ACE_INLINE int +ACE_Bounded_Stack::is_full (void) const +{ + ACE_TRACE ("ACE_Bounded_Stack::is_full"); + return this->top_ >= this->size_; +} + +//---------------------------------------- + +template ACE_INLINE void +ACE_Fixed_Stack::push (const T &new_item) +{ + ACE_TRACE ("ACE_Fixed_Stack::push"); + this->stack_[this->top_++] = new_item; +} + +template ACE_INLINE void +ACE_Fixed_Stack::pop (T &item) +{ + ACE_TRACE ("ACE_Fixed_Stack::pop"); + item = this->stack_[--this->top_]; +} + +template ACE_INLINE void +ACE_Fixed_Stack::top (T &item) const +{ + ACE_TRACE ("ACE_Fixed_Stack::top"); + item = this->stack_[this->top_ - 1]; +} + +template ACE_INLINE int +ACE_Fixed_Stack::is_empty (void) const +{ + ACE_TRACE ("ACE_Fixed_Stack::is_empty"); + return this->top_ == 0; +} + +template ACE_INLINE int +ACE_Fixed_Stack::is_full (void) const +{ + ACE_TRACE ("ACE_Fixed_Stack::is_full"); + return this->top_ >= this->size_; +} + +//---------------------------------------- + +template ACE_INLINE void +ACE_Unbounded_Stack::top (T &item) const +{ + ACE_TRACE ("ACE_Unbounded_Stack::top"); + item = this->head_->item_; +} + +template ACE_INLINE int +ACE_Unbounded_Stack::is_empty (void) const +{ + ACE_TRACE ("ACE_Unbounded_Stack::is_empty"); + return this->head_ == 0; +} + +template ACE_INLINE int +ACE_Unbounded_Stack::is_full (void) const +{ + ACE_TRACE ("ACE_Unbounded_Stack::is_full"); + return this->last_resort_ == 0; +} + +template ACE_INLINE size_t +ACE_Unbounded_Queue::size (void) const +{ + return this->cur_size_; +} diff --git a/ace/Local_Name_Space.cpp b/ace/Local_Name_Space.cpp index 48f6dc00535..0ba1c5dc0f2 100644 --- a/ace/Local_Name_Space.cpp +++ b/ace/Local_Name_Space.cpp @@ -162,8 +162,8 @@ template class ACE_Unbounded_Set; template class ACE_Unbounded_Set_Iterator; template class ACE_Unbounded_Set; template class ACE_Unbounded_Set_Iterator; -template class ACE_Set_Node; -template class ACE_Set_Node; +template class ACE_Node; +template class ACE_Node; template class ACE_Guard; template class ACE_Read_Guard; template class ACE_Write_Guard; diff --git a/ace/Local_Name_Space.h b/ace/Local_Name_Space.h index cee5042db1c..e115903cc2f 100644 --- a/ace/Local_Name_Space.h +++ b/ace/Local_Name_Space.h @@ -20,7 +20,7 @@ #define ACE_LOCAL_NAME_SPACE_H #include "ace/SString.h" -#include "ace/Set.h" +#include "ace/Containers.h" #include "ace/Malloc.h" #include "ace/Synch.h" diff --git a/ace/Local_Tokens.cpp b/ace/Local_Tokens.cpp index 0fbe4524db6..d786e4a9b3f 100644 --- a/ace/Local_Tokens.cpp +++ b/ace/Local_Tokens.cpp @@ -1412,5 +1412,5 @@ ACE_Token_Name::dump (void) const template class ACE_TSS ; #endif /* ACE_NO_TSS_TOKENS */ template class ACE_Unbounded_Stack ; -template class ACE_Stack_Node ; +template class ACE_Node ; #endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ diff --git a/ace/Local_Tokens.h b/ace/Local_Tokens.h index 49a66af5b68..5663e0913d0 100644 --- a/ace/Local_Tokens.h +++ b/ace/Local_Tokens.h @@ -40,7 +40,7 @@ #define ACE_LOCAL_MUTEX_H #include "ace/Synch.h" -#include "ace/Stack.h" +#include "ace/Containers.h" #include "ace/Synch_Options.h" #include "ace/Map_Manager.h" diff --git a/ace/Log_Msg.cpp b/ace/Log_Msg.cpp index 6225d122630..701029d69a9 100644 --- a/ace/Log_Msg.cpp +++ b/ace/Log_Msg.cpp @@ -24,7 +24,7 @@ #include "ace/Thread.h" #include "ace/Synch.h" #include "ace/Signal.h" -#include "ace/Set.h" +#include "ace/Containers.h" #if defined (ACE_HAS_UNICODE) #define ACE_WSPRINTF(BUF,VALUE) ::wsprintf (BUF, "%S", VALUE) @@ -169,7 +169,7 @@ ACE_Log_Msg_Manager::atexit (void) ) { // Advance the iterator first because it needs to read the next - // field of the ACE_Set_Node that will be deleted as a result of + // field of the ACE_Node that will be deleted as a result of // the following call to remove the node. i.advance (); @@ -1259,7 +1259,7 @@ ACE_Log_Msg::getpid (void) const #if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -template class ACE_Set_Node; +template class ACE_Node; template class ACE_Unbounded_Set; template class ACE_Unbounded_Set_Iterator; #endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ diff --git a/ace/Name_Space.h b/ace/Name_Space.h index 78a274e86b5..0aecbad5248 100644 --- a/ace/Name_Space.h +++ b/ace/Name_Space.h @@ -21,7 +21,7 @@ #include "ace/ACE.h" #include "ace/SString.h" -#include "ace/Set.h" +#include "ace/Containers.h" #include "ace/Name_Proxy.h" typedef ACE_Unbounded_Set ACE_WSTRING_SET; diff --git a/ace/Naming_Context.h b/ace/Naming_Context.h index afa79ef0bf0..3c418dfdd3b 100644 --- a/ace/Naming_Context.h +++ b/ace/Naming_Context.h @@ -21,7 +21,7 @@ #include "ace/ACE.h" #include "ace/SString.h" -#include "ace/Set.h" +#include "ace/Containers.h" #include "ace/Service_Object.h" #include "ace/Name_Proxy.h" #include "ace/Name_Space.h" diff --git a/ace/OS.cpp b/ace/OS.cpp index babd7ce9427..3a050d24b76 100644 --- a/ace/OS.cpp +++ b/ace/OS.cpp @@ -16,7 +16,7 @@ #endif /* ACE_HAS_INLINED_OS_CALLS */ #include "ace/Synch.h" -#include "ace/Set.h" +#include "ace/Containers.h" #if defined (ACE_MT_SAFE) diff --git a/ace/OS.h b/ace/OS.h index 6f4146d592b..49a20a5c3ec 100644 --- a/ace/OS.h +++ b/ace/OS.h @@ -2722,9 +2722,9 @@ public: static void free (void *); // = A set of wrappers for memory copying operations. - static int memcmp (const void *s, const void *t, size_t len); - static void *memcpy (void *s, const void *t, size_t len); - static void *memmove (void *s, const void *t, size_t len); + static int memcmp (const void *t, const void *s, size_t len); + static void *memcpy (void *t, const void *s, size_t len); + static void *memmove (void *t, const void *s, size_t len); static void *memset (void *s, int c, size_t len); // = A set of wrappers for System V message queues. diff --git a/ace/OS.i b/ace/OS.i index 338f8471e30..8cc1dca73e3 100644 --- a/ace/OS.i +++ b/ace/OS.i @@ -952,24 +952,24 @@ ACE_OS::_exit (int status) } ACE_INLINE int -ACE_OS::memcmp (const void *s, const void *t, size_t len) +ACE_OS::memcmp (const void *t, const void *s, size_t len) { // ACE_TRACE ("ACE_OS::memcmp"); - return ::memcmp (s, t, len); + return ::memcmp (t, s, len); } ACE_INLINE void * -ACE_OS::memcpy (void *s, const void *t, size_t len) +ACE_OS::memcpy (void *t, const void *s, size_t len) { // ACE_TRACE ("ACE_OS::memcpy"); - return ::memcpy (s, t, len); + return ::memcpy (t, s, len); } ACE_INLINE void * -ACE_OS::memmove (void *s, const void *t, size_t len) +ACE_OS::memmove (void *t, const void *s, size_t len) { // ACE_TRACE ("ACE_OS::memcpy"); - return ::memmove (s, t, len); + return ::memmove (t, s, len); } ACE_INLINE void * diff --git a/ace/Proactor.cpp b/ace/Proactor.cpp index 050b142d144..04eaf1d6bdc 100644 --- a/ace/Proactor.cpp +++ b/ace/Proactor.cpp @@ -541,7 +541,7 @@ ACE_Proactor::Asynch_Timer::complete (u_long bytes_transferred, template class ACE_Unbounded_Set *>; template class ACE_Unbounded_Set_Iterator *>; -template class ACE_Set_Node *>; +template class ACE_Node *>; template class ACE_Timer_Node_T; diff --git a/ace/Remote_Name_Space.h b/ace/Remote_Name_Space.h index d6010250c07..d978fa39e00 100644 --- a/ace/Remote_Name_Space.h +++ b/ace/Remote_Name_Space.h @@ -21,7 +21,7 @@ #include "ace/ACE.h" #include "ace/SString.h" -#include "ace/Set.h" +#include "ace/Containers.h" #include "ace/Name_Proxy.h" #include "ace/Name_Space.h" diff --git a/ace/Service_Config.cpp b/ace/Service_Config.cpp index 7c4fd047675..86e58214088 100644 --- a/ace/Service_Config.cpp +++ b/ace/Service_Config.cpp @@ -9,7 +9,7 @@ #include "ace/Service_Manager.h" #include "ace/Service_Repository.h" #include "ace/Service_Record.h" -#include "ace/Set.h" +#include "ace/Containers.h" #include "ace/Auto_Ptr.h" #include "ace/Service_Config.h" @@ -961,7 +961,7 @@ ACE_Service_Config::reconfig_occurred (sig_atomic_t config_occurred) } #if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -template class ACE_Set_Node; +template class ACE_Node; template class ACE_Unbounded_Set; template class ACE_Unbounded_Set_Iterator; template class ACE_Malloc; diff --git a/ace/Service_Config.h b/ace/Service_Config.h index ee7829232e7..1e196cc8246 100644 --- a/ace/Service_Config.h +++ b/ace/Service_Config.h @@ -20,7 +20,7 @@ #include "ace/Service_Object.h" #include "ace/Thread_Manager.h" #include "ace/Signal.h" -#include "ace/Set.h" +#include "ace/Containers.h" // Forward decl. class ACE_Service_Repository; diff --git a/ace/Set.cpp b/ace/Set.cpp deleted file mode 100644 index d09ca2115b3..00000000000 --- a/ace/Set.cpp +++ /dev/null @@ -1,764 +0,0 @@ -// Set.cpp -// $Id$ - -#if !defined (ACE_SET_C) -#define ACE_SET_C - -#define ACE_BUILD_DLL -#include "ace/Set.h" - -#if !defined (__ACE_INLINE__) -#include "ace/Set.i" -#endif /* __ACE_INLINE__ */ - -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) - return; - - 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 1; - } - - return 0; -} - -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 1; - } - } - return 0; -} - -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) - return; - else 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 1; - } - - return 0; -} - -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 1; - } - } - return 0; -} - -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_Set_Node) - -template -class ACE_Set_Node -{ -friend class ACE_Unbounded_Set; -friend class ACE_Unbounded_Set_Iterator; -public: - // = Initialization methods - ACE_Set_Node (const T &i, ACE_Set_Node *n); - ACE_Set_Node (ACE_Set_Node *n = 0, int MS_SUCKS = 0); - ACE_Set_Node (const ACE_Set_Node &n); - -private: - ACE_Set_Node *next_; - // Pointer to next element in the list of ACE_Set_Nodes. - - T item_; - // Current value of the item in this node. -}; - -template -ACE_Set_Node::ACE_Set_Node (const T &i, ACE_Set_Node *n) - : next_ (n), - item_ (i) -{ -// ACE_TRACE ("ACE_Set_Node::ACE_Set_Node"); -} - -template -ACE_Set_Node::ACE_Set_Node (ACE_Set_Node *n, int /* MS_SUCKS */) - : next_ (n) -{ -// ACE_TRACE ("ACE_Set_Node::ACE_Set_Node"); -} - -template -ACE_Set_Node::ACE_Set_Node (const ACE_Set_Node &s) - : next_ (s.next_), - item_ (s.item_) -{ -// ACE_TRACE ("ACE_Set_Node::ACE_Set_Node"); -} - -ACE_ALLOC_HOOK_DEFINE(ACE_Unbounded_Set) - -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_Set_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_Set_Node *curr = this->head_->next_; - - // Keep looking until we've hit the dummy node. - - while (curr != this->head_) - { - ACE_Set_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 int -ACE_Unbounded_Set::find (const T &item) const -{ -// ACE_TRACE ("ACE_Unbounded_Set::find"); - // Set into the dummy node. - this->head_->item_ = item; - - ACE_Set_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_ ? 0 : 1; -} - -template int -ACE_Unbounded_Set::get (T &item, size_t index) const -{ - ACE_TRACE ("ACE_Unbounded_Set::get"); - - ACE_Set_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 1; - } - else - return 0; -} - -template int -ACE_Unbounded_Set::set (const T &item, size_t index) -{ - ACE_TRACE ("ACE_Unbounded_Set::get"); - - ACE_Set_Node *curr = this->head_->next_; - - int result = 1; - size_t i; - - for (i = 0; i <= index; i++) - { - if (i == this->cur_size_) - { - // We need to expand the list. - - result = 0; - - T dummy; - - // 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. - if (this->insert_tail (dummy) == -1) - return -1; - } - else - curr = curr->next_; - } - - curr->item_ = item; - return result; -} - -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_Set_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_Set_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) - return; - - this->delete_nodes (); - this->copy_nodes (us); -} - -template void -ACE_Unbounded_Set::reset (void) -{ - ACE_TRACE ("reset"); - - this->delete_nodes (); -} - -// Insert the new node at the tail of the list. - -template int -ACE_Unbounded_Set::insert_tail (const T &item) -{ -// ACE_TRACE ("ACE_Unbounded_Set::insert"); - ACE_Set_Node *temp; - - // Insert into the old dummy node location. - this->head_->item_ = item; - - // Create a new dummy node. - ACE_NEW_RETURN (temp, ACE_Set_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 int -ACE_Unbounded_Set::insert (const T &item) -{ -// ACE_TRACE ("ACE_Unbounded_Set::insert"); - if (this->find (item) == 0) - return this->insert_tail (item); - else - return 1; -} - -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_Set_Node *curr = this->head_; - - while (!(curr->next_->item_ == item)) - curr = curr->next_; - - if (curr->next_ == this->head_) - return 0; // Item was not found. - else - { - ACE_Set_Node *temp = curr->next_; - // Skip over the node that we're deleting. - curr->next_ = temp->next_; - this->cur_size_--; - delete temp; - return 1; - } -} - -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; - } -} - -#endif /* ACE_SET_C */ diff --git a/ace/Set.h b/ace/Set.h deleted file mode 100644 index fccaeb8a2e3..00000000000 --- a/ace/Set.h +++ /dev/null @@ -1,394 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// ace -// -// = FILENAME -// Set.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (ACE_SET) -#define ACE_SET - -#include "ace/ACE.h" - -// Forward declarations. -template class ACE_Unbounded_Set; - -// "Cheshire cat" forward decl. -template class ACE_Set_Node; - -template -class ACE_Unbounded_Set_Iterator - // = TITLE - // Implement an iterator over an unbounded set. -{ -public: - // = Initialization method. - ACE_Unbounded_Set_Iterator (ACE_Unbounded_Set &s); - - // = Iteration methods. - - int next (T *&next_item); - // Pass back the that hasn't been seen in the Set. - // 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 set 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_Set_Node *current_; - // Pointer to the current node in the iteration. - - ACE_Unbounded_Set &set_; - // Pointer to the set we're iterating over. -}; - -// Forward declaration (use the "Cheshire Cat" approach to information -// hiding). -template -class ACE_Set_Node; - -template -class ACE_Unbounded_Set - // = TITLE - // Implement a simple unordered set of of unbounded size. - // - // = DESCRIPTION - // This implementation of an unordered set uses a linked list. - // This implementation does not allow duplicates... -{ -friend class ACE_Unbounded_Set_Iterator; -public: - // = Initialization and termination methods. - ACE_Unbounded_Set (void); - // Constructor. - - ACE_Unbounded_Set (const ACE_Unbounded_Set &); - // Copy constructor. - - void operator= (const ACE_Unbounded_Set &); - // Assignment operator. - - ~ACE_Unbounded_Set (void); - // Destructor. - - // = Classic unordered set operations. - int insert (const T &new_item); - // Insert into the set (doesn't allow duplicates). - // Returns -1 if failures occur, 1 if item is already present, else - // 0. - - int remove (const T &item); - // Remove first occurrence of from the set. Returns 1 if - // it removes the item, 0 if it can't find the item, and -1 if a - // failure occurs. - - int find (const T &item) const; - // Return first occurrence of from the set. - // Returns 0 if can't find, else 1. - - size_t size (void) const; - // Size of the set. - - // = Additional utility methods. - - int get (T &item, size_t index) const; - // Get the th element in the set. Returns 0 if the element - // isn't in the range <0..size() - 1>, else 1. - - int set (const T &item, size_t index); - // Set the th element in the set. Will pad out the set with - // empty nodes if is beyond the range <0..size() - 1>. - // Returns -1 on failure, 0 if isn't initially in range, and - // 1 otherwise. - - int insert_tail (const T &new_item); - // Insert into the set at the tail. Returns -1 if - // failures occur else 0. - - void reset (void); - // Reset the to be empty. - - void dump (void) const; - // Dump the state of an object. - - ACE_ALLOC_HOOK_DECLARE; - // Declare the dynamic allocation hooks. - -private: - void delete_nodes (void); - // Delete all the nodes in the Set. - - void copy_nodes (const ACE_Unbounded_Set &); - // Copy nodes into this set. - - ACE_Set_Node *head_; - // Head of the linked list of Nodes. - - size_t cur_size_; - // Current size of the set. -}; - -// Forward declaration. -template -class ACE_Fixed_Set; - -template -class ACE_Fixed_Set_Iterator - // = TITLE - // Interates through an unordered set. - // - // = DESCRIPTION - // This implementation of an unordered set uses a fixed array. - // Allows deletions while iteration is occurring. -{ -public: - // = Initialization method. - ACE_Fixed_Set_Iterator (ACE_Fixed_Set &s); - - // = Iteration methods. - - int next (T *&next_item); - // Pass back the that hasn't been seen in the Set. - // 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 set 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_Fixed_Set &s_; - // Set we are iterating over. - - ssize_t next_; - // How far we've advanced over the set. -}; - -template -class ACE_Fixed_Set - // = TITLE - // Implement a simple unordered set of with maximum . - // - // = DESCRIPTION - // This implementation of an unordered set uses a fixed array. - // This implementation does not allow duplicates... -{ -friend class ACE_Fixed_Set_Iterator; -public: - // = Initialization and termination methods. - ACE_Fixed_Set (void); - // Constructor. - - ACE_Fixed_Set (size_t size); - // Constructor. - - ACE_Fixed_Set (const ACE_Fixed_Set &); - // Copy constructor. - - void operator = (const ACE_Fixed_Set &); - // Assignment operator. - - ~ACE_Fixed_Set (void); - // Destructor. - - // = Classic unordered set operations. - int insert (const T &new_item); - // Insert into the set (doesn't allow duplicates). - // Returns -1 if failures occur, 1 if item is already present, else - // 0. - - int remove (const T &item); - // Remove first occurrence of from the set. Returns 1 if - // it removes the item, 0 if it can't find the item, and -1 if a - // failure occurs. - - int find (const T &item) const; - // Return first occurrence of from the set. - // Returns 0 if can't find, else 1. - - size_t size (void) const; - // Size of the set. - - void dump (void) const; - // Dump the state of an object. - - ACE_ALLOC_HOOK_DECLARE; - // Declare the dynamic allocation hooks. - -private: - struct - { - T item_; - // Item in the set. - int is_free_; - // Keeps track of whether this item is in use or not. - } search_structure_[SIZE]; - // Holds the contents of the set. - - size_t cur_size_; - // Current size of the set. - - size_t max_size_; - // Maximum size of the set. -}; - -// Forward declaration. -template -class ACE_Bounded_Set; - -template -class ACE_Bounded_Set_Iterator - // = TITLE - // Interates through an unordered set. - // - // = DESCRIPTION - // This implementation of an unordered set uses a Bounded array. - // Allows deletions while iteration is occurring. -{ -public: - // = Initialization method. - ACE_Bounded_Set_Iterator (ACE_Bounded_Set &s); - - // = Iteration methods. - - int next (T *&next_item); - // Pass back the that hasn't been seen in the Set. - // 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 set 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_Bounded_Set &s_; - // Set we are iterating over. - - ssize_t next_; - // How far we've advanced over the set. -}; - -template -class ACE_Bounded_Set - // = TITLE - // Implement a simple unordered set of with maximum - // set at creation time. - // - // = DESCRIPTION - // This implementation of an unordered set uses a Bounded array. - // This implementation does not allow duplicates... -{ -friend class ACE_Bounded_Set_Iterator; -public: - enum - { - DEFAULT_SIZE = 10 - }; - - // = Initialization and termination methods. - ACE_Bounded_Set (void); - // Constructor. - - ACE_Bounded_Set (size_t size); - // Constructor. - - ACE_Bounded_Set (const ACE_Bounded_Set &); - // Copy constructor. - - void operator= (const ACE_Bounded_Set &); - // Assignment operator. - - ~ACE_Bounded_Set (void); - // Destructor - - // = Classic unordered set operations. - int insert (const T &new_item); - // Insert into the set (doesn't allow duplicates). - // Returns -1 if failures occur, 1 if item is already present, else - // 0. - - int remove (const T &item); - // Remove first occurrence of from the set. Returns 1 if it - // removes the item, 0 if it can't find the item, and -1 if a - // failure occurs. - - int find (const T &item) const; - // Return first occurrence of from the set. - // Returns 0 if can't find, else 1. - - size_t size (void) const; - // Size of the set. - - void dump (void) const; - // Dump the state of an object. - - ACE_ALLOC_HOOK_DECLARE; - // Declare the dynamic allocation hooks. - -private: - struct Search_Structure - { - T item_; - // Item in the set. - int is_free_; - // Keeps track of whether this item is in use or not. - }; - - Search_Structure *search_structure_; - // Holds the contents of the set. - - size_t cur_size_; - // Current size of the set. - - size_t max_size_; - // Maximum size of the set. -}; - -#if defined (__ACE_INLINE__) -#include "ace/Set.i" -#endif /* __ACE_INLINE__ */ - -#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) -#include "ace/Set.cpp" -#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ - -#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) -#pragma implementation ("Set.cpp") -#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ - -#endif /* ACE_SET */ diff --git a/ace/Set.i b/ace/Set.i deleted file mode 100644 index 8628f7acd9f..00000000000 --- a/ace/Set.i +++ /dev/null @@ -1,5 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -// Set.i - diff --git a/ace/Signal.h b/ace/Signal.h index 77d458cfcd6..d289e6869ba 100644 --- a/ace/Signal.h +++ b/ace/Signal.h @@ -19,7 +19,7 @@ #include "ace/Synch.h" #include "ace/Event_Handler.h" -#include "ace/Set.h" +#include "ace/Containers.h" // This worksaround a horrible bug with HP/UX C++... typedef struct sigaction ACE_SIGACTION; diff --git a/ace/Stack.cpp b/ace/Stack.cpp deleted file mode 100644 index a297ca2e9e4..00000000000 --- a/ace/Stack.cpp +++ /dev/null @@ -1,446 +0,0 @@ -// Stack.cpp -// $Id$ - -#if !defined (ACE_STACK_C) -#define ACE_STACK_C - -#define ACE_BUILD_DLL -#include "ace/Stack.h" - -#if !defined (__ACE_INLINE__) -#include "ace/Stack.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) - return; - else 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) - return; - 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_; -} - -//---------------------------------------- - -template -class ACE_Stack_Node -{ -friend class ACE_Unbounded_Stack; -private: -#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) - // = Only use a free list if the compiler supports static data - // members... - - void *operator new (size_t bytes); - void operator delete (void *ptr); - - // Returns all dynamic memory on the free list to the free store. - static void free_all_nodes (void); - - static ACE_Stack_Node *free_list_; - // Head of the free list of Nodes used to speed up allocation. -#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ - - ACE_Stack_Node (T i, ACE_Stack_Node *n); - ACE_Stack_Node (void); - - ACE_Stack_Node *next_; - T item_; -}; - -#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) -/* static */ -template ACE_Stack_Node * -ACE_Stack_Node::free_list_ = 0; - -template void * -ACE_Stack_Node::operator new (size_t bytes) -{ - ACE_TRACE ("ACE_Stack_Node::operator new"); - ACE_Stack_Node *temp = ACE_Stack_Node::free_list_; - - if (temp) - ACE_Stack_Node::free_list_ = ACE_Stack_Node::free_list_->next_; - else - temp = (ACE_Stack_Node *) new char[bytes]; - - return temp; -} - -template void -ACE_Stack_Node::operator delete (void *ptr) -{ - ACE_TRACE ("ACE_Stack_Node::operator delete"); - ((ACE_Stack_Node *) ptr)->next_ = ACE_Stack_Node::free_list_; - ACE_Stack_Node::free_list_ = (ACE_Stack_Node *) ptr; -} - -template void -ACE_Stack_Node::free_all_nodes (void) -{ - ACE_TRACE ("ACE_Stack_Node::free_all_nodes"); - - while (ACE_Stack_Node::free_list_) - { - ACE_Stack_Node *temp = ACE_Stack_Node::free_list_; - ACE_Stack_Node::free_list_ = ACE_Stack_Node::free_list_->next_; - ::delete temp; - } -} - -#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ - -template -ACE_Stack_Node::ACE_Stack_Node (T i, ACE_Stack_Node *n) - : next_ (n), - item_ (i) -{ - ACE_TRACE ("ACE_Stack_Node::ACE_Stack_Node"); -} - -template -ACE_Stack_Node::ACE_Stack_Node (void) - : next_ (0) -{ - ACE_TRACE ("ACE_Stack_Node::ACE_Stack_Node"); -} - -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) -{ - ACE_NEW (this->last_resort_, ACE_Stack_Node); - 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->head_ != 0) - { - ACE_Stack_Node *temp = this->head_; - this->head_ = this->head_->next_; - delete temp; - } - - delete this->last_resort_; - this->last_resort_ = 0; -} - -template void -ACE_Unbounded_Stack::copy_all_nodes (const ACE_Unbounded_Stack &s) -{ - ACE_TRACE ("ACE_Unbounded_Stack::copy_all_nodes"); - // Push all of 's nodes onto our stack (this puts them in the - // reverse order). - ACE_Stack_Node *temp; - - for (temp = s.head_; - temp != 0; - temp = temp->next_) - { - if (!this->is_full ()) - this->push (temp->item_); - else - break; - } - - // Reverse the order of our stack. - - ACE_Stack_Node *prev = 0; - - for (temp = this->head_; temp != 0; ) - { - ACE_Stack_Node *next = temp->next_; - - temp->next_ = prev; - prev = temp; - temp = next; - } - - this->head_ = prev; -} - -template -ACE_Unbounded_Stack::ACE_Unbounded_Stack (const ACE_Unbounded_Stack &s) - : head_ (0) -{ - ACE_NEW (this->last_resort_, ACE_Stack_Node); - - 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) - return; - - 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 (); -} - -template void -ACE_Unbounded_Stack::push (const T &new_item) -{ - ACE_TRACE ("ACE_Unbounded_Stack::push"); - - ACE_Stack_Node *temp = new ACE_Stack_Node (new_item, this->head_); - - if (temp == 0) - { - temp = this->last_resort_; - this->last_resort_ = 0; - } - - this->head_ = temp; -} - -template void -ACE_Unbounded_Stack::pop (T &item) -{ - ACE_TRACE ("ACE_Unbounded_Stack::pop"); - item = this->head_->item_; - ACE_Stack_Node *temp = this->head_; - this->head_ = this->head_->next_; - - // Restore the node of last resort if necessary. - if (this->last_resort_ == 0) - this->last_resort_ = temp; - else - delete temp; -} - -template void -ACE_Unbounded_Stack::delete_free_list (void) -{ - ACE_TRACE ("ACE_Unbounded_Stack::delete_free_list"); -#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) - ACE_Stack_Node::free_all_nodes (); -#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ -} - -template -class ACE_Queue_Node -{ -friend class ACE_Unbounded_Queue; - ACE_Queue_Node (T i, ACE_Queue_Node *n); - - ACE_Queue_Node *next_; - T item_; -}; - -template -ACE_Queue_Node::ACE_Queue_Node (T i, ACE_Queue_Node *n) - : next_ (n), - item_ (i) -{ - ACE_TRACE ("ACE_Queue_Node::ACE_Queue_Node"); -} - -template -ACE_Unbounded_Queue::ACE_Unbounded_Queue (void) - : head_ (0), - tail_ (0), - cur_size_ (0) -{ - ACE_TRACE ("ACE_Unbounded_Queue::ACE_Unbounded_Queue (void)"); -} - -ACE_ALLOC_HOOK_DEFINE(ACE_Unbounded_Queue) - -template void -ACE_Unbounded_Queue::dump (void) const -{ - ACE_TRACE ("ACE_Unbounded_Queue::dump"); -} - -template -ACE_Unbounded_Queue::~ACE_Unbounded_Queue (void) -{ - ACE_TRACE ("ACE_Unbounded_Queue::~ACE_Unbounded_Queue (void)"); - ACE_Queue_Node *temp = head_; - while (temp != 0) - { - head_ = head_->next_; - delete temp; - temp = head_; - this->cur_size_--; - } -} - -template int -ACE_Unbounded_Queue::enqueue (const TYPE &new_item) -{ - ACE_TRACE ("ACE_Unbounded_Queue::enqueue (const TYPE& new_item)"); - - ACE_Queue_Node *temp = new ACE_Queue_Node (new_item, 0); - - if (temp == 0) - return -1; - - if (this->head_ == 0) - this->head_ = this->tail_ = temp; - else - { - this->tail_->next_ = temp; - this->tail_ = temp; - } - - ++this->cur_size_; - - return 0; -} - -template int -ACE_Unbounded_Queue::peek (TYPE &item) const -{ - ACE_TRACE ("ACE_Unbounded_Queue::peek (TYPE *&item)"); - - if (this->head_ == 0) - return -1; - - item = this->head_->item_; - return 0; -} - -template TYPE * -ACE_Unbounded_Queue::peek (const u_int index) const -{ - ACE_TRACE ("ACE_Unbounded_Queue::peek (const u_int index)"); - - ACE_Queue_Node *temp = head_; - for (u_int i = 0; temp != 0 && i < index; temp = temp->next_, ++i) - /* null */; - - return temp == 0 ? 0 : &temp->item_; -} - -template int -ACE_Unbounded_Queue::dequeue (TYPE &item) -{ - ACE_TRACE ("ACE_Unbounded_Queue::dequeue (TYPE *&item)"); - - if (this->head_ == 0) - return -1; - - item = this->head_->item_; - ACE_Queue_Node *temp = this->head_; - this->head_ = this->head_->next_; - delete temp; - --this->cur_size_; - return 0; -} - -#endif /* ACE_STACK_C */ diff --git a/ace/Stack.h b/ace/Stack.h deleted file mode 100644 index aa888fcae80..00000000000 --- a/ace/Stack.h +++ /dev/null @@ -1,291 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// ace -// -// = FILENAME -// Stack.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (ACE_STACK_H) -#define ACE_STACK_H - -#include "ace/ACE.h" - -template -class ACE_Bounded_Stack - // = TITLE - // Implement a generic LIFO abstract data type. - // - // = DESCRIPTION - // This implementation of a Stack uses a bounded array - // that is allocated dynamically. -{ -public: - // = Initialization, assignemnt, and termination methods. - ACE_Bounded_Stack (size_t size); - // Initialize a new stack so that it is empty. - - ACE_Bounded_Stack (const ACE_Bounded_Stack &s); - // The copy constructor (performs initialization). - - void operator= (const ACE_Bounded_Stack &s); - // Assignment operator (performs assignment). - - ~ACE_Bounded_Stack (void); - // Perform actions needed when stack goes out of scope. - - // = Classic Stack operations. - - void push (const T &new_item); - // Place a new item on top of the stack. Does not check if the - // stack is full. - - void pop (T &item); - // Remove and return the top stack item. Does not check if stack - // is full. - - void top (T &item) const; - // Return top stack item without removing it. Does not check if - // stack is empty. - - // = Check boundary conditions for Stack operations. - - int is_empty (void) const; - // Returns 1 if the stack is empty, otherwise returns 0. - - int is_full (void) const; - // Returns 1 if the stack is full, otherwise returns 0. - - void dump (void) const; - // Dump the state of an object. - - ACE_ALLOC_HOOK_DECLARE; - // Declare the dynamic allocation hooks. - -private: - size_t size_; - // Size of the dynamically allocated data. - - size_t top_; - // Keeps track of the current top of stack. - - T *stack_; - // Holds the stack's contents. -}; - -//---------------------------------------- - -template -class ACE_Fixed_Stack - // = TITLE - // Implement a generic LIFO abstract data type. - // - // = DESCRIPTION - // This implementation of a Stack uses a fixed array - // with the size fixed at instantiation time. -{ -public: - // = Initialization, assignemnt, and termination methods. - ACE_Fixed_Stack (void); - // Initialize a new stack so that it is empty. - - ACE_Fixed_Stack (const ACE_Fixed_Stack &s); - // The copy constructor (performs initialization). - - void operator= (const ACE_Fixed_Stack &s); - // Assignment operator (performs assignment). - - ~ACE_Fixed_Stack (void); - // Perform actions needed when stack goes out of scope. - - // = Classic Stack operations. - - void push (const T &new_item); - // Place a new item on top of the stack. Does not check if the - // stack is full. - - void pop (T &item); - // Remove and return the top stack item. Does not check if stack - // is full. - - void top (T &item) const; - // Return top stack item without removing it. Does not check if - // stack is empty. - - // = Check boundary conditions for Stack operations. - - int is_empty (void) const; - // Returns 1 if the stack is empty, otherwise returns 0. - - int is_full (void) const; - // Returns 1 if the stack is full, otherwise returns 0. - - void dump (void) const; - // Dump the state of an object. - - ACE_ALLOC_HOOK_DECLARE; - // Declare the dynamic allocation hooks. - -private: - size_t size_; - // Size of the dynamically allocated data. - - size_t top_; - // Keeps track of the current top of stack. - - T stack_[SIZE]; - // Holds the stack's contents. -}; - -//---------------------------------------- - -// Forward declaration (use the "Cheshire Cat" approach to information -// hiding). -template -class ACE_Stack_Node; - -template -class ACE_Unbounded_Stack - // = TITLE - // Implement a generic LIFO abstract data type. - // - // = DESCRIPTION - // This implementation of an unbounded Stack uses a linked list. -{ -public: - // = Initialization, assignemnt, and termination methods. - ACE_Unbounded_Stack (void); - // Initialize a new stack so that it is empty. - - ACE_Unbounded_Stack (const ACE_Unbounded_Stack &s); - // The copy constructor (performs initialization). - - void operator= (const ACE_Unbounded_Stack &s); - // Assignment operator (performs assignment). - - ~ACE_Unbounded_Stack (void); - // Perform actions needed when stack goes out of scope. - - // = Classic Stack operations. - - void push (const T &new_item); - // Place a new item on top of the stack. Does not check if the - // stack is full. - - void pop (T &item); - // Remove and return the top stack item. Does not check if stack - // is full. - - void top (T &item) const; - // Return top stack item without removing it. Does not check if - // stack is empty. - - // = Check boundary conditions for Stack operations. - - int is_empty (void) const; - // Returns 1 if the stack is empty, otherwise returns 0. - - int is_full (void) const; - // Returns 1 if the stack is full, otherwise returns 0. - - static void delete_free_list (void); - // Returns all dynamic memory on the free list to the free store. - - void dump (void) const; - // Dump the state of an object. - - ACE_ALLOC_HOOK_DECLARE; - // Declare the dynamic allocation hooks. - -private: - void delete_all_nodes (void); - // Delete all the nodes in the stack. - - void copy_all_nodes (const ACE_Unbounded_Stack &s); - // Copy all nodes from to . - - ACE_Stack_Node *head_; - // Head of the linked list of Nodes. - - ACE_Stack_Node *last_resort_; - // Use this node when all memory is exhausted... -}; - -// Forward declaration (use the "Cheshire Cat" approach to information -// hiding). -template -class ACE_Queue_Node; - -template -class ACE_Unbounded_Queue - // = TITLE - // A Queue of "infinite" length. - - // = DESCRIPTION - // Implemented using dynamic memory... -{ -public: - ACE_Unbounded_Queue (void); - // construction. - - ~ACE_Unbounded_Queue (void); - // construction. - - int enqueue (const TYPE &new_item); - // Addes to the queue. Returns 0 on success, -1 on failure. - - int dequeue (TYPE &item); - // Removes and returns the first on the queue. Returns 0 on - // success, -1 if nothing was found. - - int peek (TYPE &item) const; - // Returns the first on the queue without removing it. - // Returns 0 on success, -1 if nothing was found. - - TYPE *peek (const u_int index = 0) const; - // Returns a pointer to the item indicated by index without removing it, - // or 0 if nothing was found because index is greater than the number of - // enqueued items, less one. An index of 0 indicates the first item, and - // so on. - - size_t size (void) const; - // The number of items in the queue. - - void dump (void) const; - // Dump the state of an object. - - ACE_ALLOC_HOOK_DECLARE; - // Declare the dynamic allocation hooks. - -protected: - ACE_Queue_Node *head_; - // Head of the Queue. - - ACE_Queue_Node *tail_; - // Tail of the Queue. - - size_t cur_size_; - // Current size of the queue. -}; - -#if defined (__ACE_INLINE__) -#include "ace/Stack.i" -#endif /* __ACE_INLINE__ */ - -#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) -#include "ace/Stack.cpp" -#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ - -#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) -#pragma implementation ("Stack.cpp") -#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ - -#endif /* ACE_STACK_H */ diff --git a/ace/Stack.i b/ace/Stack.i deleted file mode 100644 index 13f65190d66..00000000000 --- a/ace/Stack.i +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -// Stack.i - -template ACE_INLINE void -ACE_Bounded_Stack::push (const T &new_item) -{ - ACE_TRACE ("ACE_Bounded_Stack::push"); - this->stack_[this->top_++] = new_item; -} - -template ACE_INLINE void -ACE_Bounded_Stack::pop (T &item) -{ - ACE_TRACE ("ACE_Bounded_Stack::pop"); - item = this->stack_[--this->top_]; -} - -template ACE_INLINE void -ACE_Bounded_Stack::top (T &item) const -{ - ACE_TRACE ("ACE_Bounded_Stack::top"); - item = this->stack_[this->top_ - 1]; -} - -template ACE_INLINE int -ACE_Bounded_Stack::is_empty (void) const -{ - ACE_TRACE ("ACE_Bounded_Stack::is_empty"); - return this->top_ == 0; -} - -template ACE_INLINE int -ACE_Bounded_Stack::is_full (void) const -{ - ACE_TRACE ("ACE_Bounded_Stack::is_full"); - return this->top_ >= this->size_; -} - -//---------------------------------------- - -template ACE_INLINE void -ACE_Fixed_Stack::push (const T &new_item) -{ - ACE_TRACE ("ACE_Fixed_Stack::push"); - this->stack_[this->top_++] = new_item; -} - -template ACE_INLINE void -ACE_Fixed_Stack::pop (T &item) -{ - ACE_TRACE ("ACE_Fixed_Stack::pop"); - item = this->stack_[--this->top_]; -} - -template ACE_INLINE void -ACE_Fixed_Stack::top (T &item) const -{ - ACE_TRACE ("ACE_Fixed_Stack::top"); - item = this->stack_[this->top_ - 1]; -} - -template ACE_INLINE int -ACE_Fixed_Stack::is_empty (void) const -{ - ACE_TRACE ("ACE_Fixed_Stack::is_empty"); - return this->top_ == 0; -} - -template ACE_INLINE int -ACE_Fixed_Stack::is_full (void) const -{ - ACE_TRACE ("ACE_Fixed_Stack::is_full"); - return this->top_ >= this->size_; -} - -//---------------------------------------- - -template ACE_INLINE void -ACE_Unbounded_Stack::top (T &item) const -{ - ACE_TRACE ("ACE_Unbounded_Stack::top"); - item = this->head_->item_; -} - -template ACE_INLINE int -ACE_Unbounded_Stack::is_empty (void) const -{ - ACE_TRACE ("ACE_Unbounded_Stack::is_empty"); - return this->head_ == 0; -} - -template ACE_INLINE int -ACE_Unbounded_Stack::is_full (void) const -{ - ACE_TRACE ("ACE_Unbounded_Stack::is_full"); - return this->last_resort_ == 0; -} - -template ACE_INLINE size_t -ACE_Unbounded_Queue::size (void) const -{ - return this->cur_size_; -} diff --git a/ace/Timer_Heap_T.h b/ace/Timer_Heap_T.h index 4c7a7a3be1f..45fb7e26b19 100644 --- a/ace/Timer_Heap_T.h +++ b/ace/Timer_Heap_T.h @@ -18,7 +18,7 @@ #define ACE_TIMER_HEAP_T_H #include "ace/Timer_Queue.h" -#include "ace/Set.h" +#include "ace/Containers.h" // Forward declaration template diff --git a/ace/Timer_Queue.cpp b/ace/Timer_Queue.cpp index 3a05a599f69..5a3033170ad 100644 --- a/ace/Timer_Queue.cpp +++ b/ace/Timer_Queue.cpp @@ -37,7 +37,7 @@ ACE_Event_Handler_Handle_Timeout_Upcall::operator () (TIMER_QUEUE &timer_queue, #if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) template class ACE_Unbounded_Set *>; -template class ACE_Set_Node *>; +template class ACE_Node *>; template class ACE_Unbounded_Set_Iterator *>; template class ACE_Timer_Heap_T; template class ACE_Timer_Heap_Iterator_T; diff --git a/apps/Gateway/Gateway/Consumer_Dispatch_Set.h b/apps/Gateway/Gateway/Consumer_Dispatch_Set.h index 71e2046b56e..5ff672679c2 100644 --- a/apps/Gateway/Gateway/Consumer_Dispatch_Set.h +++ b/apps/Gateway/Gateway/Consumer_Dispatch_Set.h @@ -17,7 +17,7 @@ #if !defined (_DISPATCH_SET) #define _DISPATCH_SET -#include "ace/Set.h" +#include "ace/Containers.h" // Forward reference. class Proxy_Handler; diff --git a/apps/Gateway/Gateway/Gateway.cpp b/apps/Gateway/Gateway/Gateway.cpp index 872366eee93..f6746794dda 100644 --- a/apps/Gateway/Gateway/Gateway.cpp +++ b/apps/Gateway/Gateway/Gateway.cpp @@ -367,6 +367,6 @@ Gateway::parse_consumer_config_file (void) ACE_SVC_FACTORY_DEFINE (Gateway) #if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -template class ACE_Set_Node; +template class ACE_Node; template class ACE_Unbounded_Set; #endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ diff --git a/examples/ASX/Event_Server/Transceiver/transceiver.cpp b/examples/ASX/Event_Server/Transceiver/transceiver.cpp index 4c9a16abaf0..d86e4ee2d9a 100644 --- a/examples/ASX/Event_Server/Transceiver/transceiver.cpp +++ b/examples/ASX/Event_Server/Transceiver/transceiver.cpp @@ -67,6 +67,7 @@ class Event_Transceiver : public ACE_Svc_Handler. @@ -99,12 +100,12 @@ Event_Transceiver::handle_close (ACE_HANDLE, return 0; } -// Close down via SIGINT. +// Close down via SIGINT or SIGQUIT. int Event_Transceiver::handle_signal (int signum, - siginfo_t *, - ucontext_t *) + siginfo_t *, + ucontext_t *) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) received signal %S\n", signum)); @@ -117,24 +118,37 @@ Event_Transceiver::Event_Transceiver (void) ACE_Sig_Set sig_set; sig_set.sig_add (SIGINT); + +#if !defined (ACE_WIN32) sig_set.sig_add (SIGQUIT); +#endif /* ACE_WIN32 */ if (ACE_Service_Config::reactor ()->register_handler (sig_set, this) == -1) ACE_ERROR ((LM_ERROR, "%p\n", "register_handler")); + + // We need to register here before we're connected since + // otherwise will return the connection socket handle + // for the peer. + else if (ACE::register_stdin_handler (this, + ACE_Service_Config::reactor (), + ACE_Service_Config::thr_mgr ()) == -1) + ACE_ERROR ((LM_ERROR, + "%p\n", + "register_stdin_handler")); } int Event_Transceiver::open (void *) { + // Register ourselves to be notified when there's data on the + // socket. if (ACE_Service_Config::reactor ()->register_handler - (this->peer ().get_handle (), this, - ACE_Event_Handler::READ_MASK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "register_handler"), -1); - else if (ACE::register_stdin_handler (this, - ACE_Service_Config::reactor (), - ACE_Service_Config::thr_mgr ()) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "register_stdin_handler"), -1); + (this, ACE_Event_Handler::READ_MASK) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "register_handler"), + -1); return 0; } @@ -192,11 +206,13 @@ main (int argc, char *argv[]) parse_args (argc, argv); - // Establish the connection. ACE_Connector connector; Event_Transceiver transceiver, *tp = &transceiver; - if (connector.connect (tp, ACE_INET_Addr (port_number, host_name)) == -1) + ACE_INET_Addr server_addr (port_number, host_name); + + // Establish the connection to the Event Server. + if (connector.connect (tp, server_addr) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", host_name), 1); // Run event loop until either the event server shuts down or we get diff --git a/examples/Misc/test_set.cpp b/examples/Misc/test_set.cpp index d6ff912e604..e43d96bab82 100644 --- a/examples/Misc/test_set.cpp +++ b/examples/Misc/test_set.cpp @@ -1,60 +1,12 @@ // $Id$ -#include "ace/Set.h" +#include "ace/Containers.h" int main (int, char *[]) { - ACE_Unbounded_Set s1; - - ACE_ASSERT (s1.size () == 0); - s1.insert_tail (10); - s1.insert_tail (20); - ACE_ASSERT (s1.size () == 2); - - ACE_Unbounded_Set s2 (s1); - ACE_ASSERT (s2.size () == 2); - - ACE_Unbounded_Set s3; - ACE_ASSERT (s3.size () == 0); - - s3 = s2; - ACE_ASSERT (s3.size () == s2.size ()); - - ACE_Unbounded_Set s4 (s3); - ACE_ASSERT (s4.size () == 2); - - int *ip = 0; - - ACE_DEBUG ((LM_DEBUG, "dumping s1\n")); - for (ACE_Unbounded_Set_Iterator iter1 (s1); - iter1.next (ip) != 0; - iter1.advance ()) - ACE_DEBUG ((LM_DEBUG, "item = %d\n", *ip)); - - ACE_DEBUG ((LM_DEBUG, "dumping s2\n")); - for (ACE_Unbounded_Set_Iterator iter2 (s2); - iter2.next (ip) != 0; - iter2.advance ()) - ACE_DEBUG ((LM_DEBUG, "item = %d\n", *ip)); - - ACE_DEBUG ((LM_DEBUG, "dumping s3\n")); - for (ACE_Unbounded_Set_Iterator iter3 (s3); - iter3.next (ip) != 0; - iter3.advance ()) - ACE_DEBUG ((LM_DEBUG, "item = %d\n", *ip)); - - ACE_DEBUG ((LM_DEBUG, "dumping s4\n")); - for (ACE_Unbounded_Set_Iterator iter4 (s4); - iter4.next (ip) != 0; - iter4.advance ()) - ACE_DEBUG ((LM_DEBUG, "item = %d\n", *ip)); - return 0; } #if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -template class ACE_Unbounded_Set; -template class ACE_Unbounded_Set_Iterator; -template class ACE_Set_Node; #endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ diff --git a/netsvcs/lib/Name_Handler.cpp b/netsvcs/lib/Name_Handler.cpp index e1904e53375..bfebddaf8b9 100644 --- a/netsvcs/lib/Name_Handler.cpp +++ b/netsvcs/lib/Name_Handler.cpp @@ -2,7 +2,7 @@ // $Id$ #define ACE_BUILD_SVC_DLL -#include "ace/Set.h" +#include "ace/Containers.h" #include "ace/Get_Opt.h" #include "Name_Handler.h" diff --git a/netsvcs/lib/TS_Clerk_Handler.cpp b/netsvcs/lib/TS_Clerk_Handler.cpp index a526b49324d..b7122e0f931 100644 --- a/netsvcs/lib/TS_Clerk_Handler.cpp +++ b/netsvcs/lib/TS_Clerk_Handler.cpp @@ -596,7 +596,7 @@ ACE_SVC_FACTORY_DEFINE (ACE_TS_Clerk_Processor) #if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) template class ACE_Connector; -template class ACE_Set_Node; +template class ACE_Node; template class ACE_Svc_Tuple; template class ACE_Unbounded_Set; template class ACE_Unbounded_Set_Iterator; diff --git a/netsvcs/lib/TS_Server_Handler.cpp b/netsvcs/lib/TS_Server_Handler.cpp index a8ff6c99ab6..3df08b7551c 100644 --- a/netsvcs/lib/TS_Server_Handler.cpp +++ b/netsvcs/lib/TS_Server_Handler.cpp @@ -3,7 +3,7 @@ #define ACE_BUILD_SVC_DLL #include "ace/SString.h" -#include "ace/Set.h" +#include "ace/Containers.h" #include "ace/Get_Opt.h" #include "TS_Server_Handler.h" -- cgit v1.2.1