Containers_T.cpp

Go to the documentation of this file.
00001 // Containers_T.cpp,v 1.74 2006/06/29 09:13:11 jwillemsen Exp
00002 
00003 #ifndef ACE_CONTAINERS_T_CPP
00004 #define ACE_CONTAINERS_T_CPP
00005 
00006 #include "ace/Log_Msg.h"
00007 #include "ace/Malloc_Base.h"
00008 #include "ace/OS_Memory.h"
00009 
00010 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00011 # pragma once
00012 #endif /* ACE_LACKS_PRAGMA_ONCE */
00013 
00014 #include "ace/Containers.h"
00015 
00016 #if !defined (__ACE_INLINE__)
00017 #include "ace/Containers_T.inl"
00018 #endif /* __ACE_INLINE__ */
00019 
00020 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00021 
00022 ACE_ALLOC_HOOK_DEFINE(ACE_Bounded_Stack)
00023 
00024 template <class T> void
00025 ACE_Bounded_Stack<T>::dump (void) const
00026 {
00027 #if defined (ACE_HAS_DUMP)
00028   ACE_TRACE ("ACE_Bounded_Stack<T>::dump");
00029 #endif /* ACE_HAS_DUMP */
00030 }
00031 
00032 template<class T>
00033 ACE_Bounded_Stack<T>::ACE_Bounded_Stack (size_t size)
00034   : size_ (size),
00035     top_ (0)
00036 {
00037   ACE_NEW (this->stack_,
00038            T[size]);
00039   ACE_TRACE ("ACE_Bounded_Stack<T>::ACE_Bounded_Stack");
00040 }
00041 
00042 template<class T>
00043 ACE_Bounded_Stack<T>::ACE_Bounded_Stack (const ACE_Bounded_Stack<T> &s)
00044   : size_ (s.size_),
00045     top_ (s.top_)
00046 {
00047   ACE_NEW (this->stack_,
00048            T[s.size_]);
00049 
00050   ACE_TRACE ("ACE_Bounded_Stack<T>::ACE_Bounded_Stack");
00051 
00052   for (size_t i = 0; i < this->top_; i++)
00053     this->stack_[i] = s.stack_[i];
00054 }
00055 
00056 template<class T> void
00057 ACE_Bounded_Stack<T>::operator= (const ACE_Bounded_Stack<T> &s)
00058 {
00059   ACE_TRACE ("ACE_Bounded_Stack<T>::operator=");
00060 
00061   if (&s != this)
00062     {
00063       if (this->size_ < s.size_)
00064         {
00065           delete [] this->stack_;
00066           ACE_NEW (this->stack_,
00067                    T[s.size_]);
00068           this->size_ = s.size_;
00069         }
00070       this->top_ = s.top_;
00071 
00072       for (size_t i = 0; i < this->top_; i++)
00073         this->stack_[i] = s.stack_[i];
00074     }
00075 }
00076 
00077 template<class T>
00078 ACE_Bounded_Stack<T>::~ACE_Bounded_Stack (void)
00079 {
00080   ACE_TRACE ("ACE_Bounded_Stack<T>::~ACE_Bounded_Stack");
00081   delete [] this->stack_;
00082 }
00083 
00084 // ----------------------------------------
00085 
00086 ACE_ALLOC_HOOK_DEFINE(ACE_Fixed_Stack)
00087 
00088 template <class T, size_t ACE_SIZE> void
00089 ACE_Fixed_Stack<T, ACE_SIZE>::dump (void) const
00090 {
00091 #if defined (ACE_HAS_DUMP)
00092   ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::dump");
00093 #endif /* ACE_HAS_DUMP */
00094 }
00095 
00096 template<class T, size_t ACE_SIZE>
00097 ACE_Fixed_Stack<T, ACE_SIZE>::ACE_Fixed_Stack (void)
00098   : size_ (ACE_SIZE),
00099     top_ (0)
00100 {
00101   ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::ACE_Fixed_Stack");
00102 }
00103 
00104 template<class T, size_t ACE_SIZE>
00105 ACE_Fixed_Stack<T, ACE_SIZE>::ACE_Fixed_Stack (const ACE_Fixed_Stack<T, ACE_SIZE> &s)
00106   : size_ (s.size_),
00107     top_ (s.top_)
00108 {
00109   ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::ACE_Fixed_Stack");
00110   for (size_t i = 0; i < this->top_; i++)
00111     this->stack_[i] = s.stack_[i];
00112 }
00113 
00114 template<class T, size_t ACE_SIZE> void
00115 ACE_Fixed_Stack<T, ACE_SIZE>::operator= (const ACE_Fixed_Stack<T, ACE_SIZE> &s)
00116 {
00117   ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::operator=");
00118 
00119   if (&s != this)
00120     {
00121       this->top_ = s.top_;
00122 
00123       for (size_t i = 0; i < this->top_; i++)
00124         this->stack_[i] = s.stack_[i];
00125     }
00126 }
00127 
00128 template<class T, size_t ACE_SIZE>
00129 ACE_Fixed_Stack<T, ACE_SIZE>::~ACE_Fixed_Stack (void)
00130 {
00131   ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::~ACE_Fixed_Stack");
00132 }
00133 
00134 //----------------------------------------
00135 
00136 ACE_ALLOC_HOOK_DEFINE(ACE_Unbounded_Stack)
00137 
00138 template <class T> void
00139 ACE_Unbounded_Stack<T>::dump (void) const
00140 {
00141 #if defined (ACE_HAS_DUMP)
00142   //  ACE_TRACE ("ACE_Unbounded_Stack<T>::dump");
00143 #endif /* ACE_HAS_DUMP */
00144 }
00145 
00146 template<class T>
00147 ACE_Unbounded_Stack<T>::ACE_Unbounded_Stack (ACE_Allocator *alloc)
00148   : head_ (0),
00149     cur_size_ (0),
00150     allocator_ (alloc)
00151 {
00152   //  ACE_TRACE ("ACE_Unbounded_Stack<T>::ACE_Unbounded_Stack");
00153   if (this->allocator_ == 0)
00154     this->allocator_ = ACE_Allocator::instance ();
00155 
00156   ACE_NEW_MALLOC (this->head_,
00157                   (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)),
00158                   ACE_Node<T>);
00159   this->head_->next_ = this->head_;
00160 }
00161 
00162 template<class T> void
00163 ACE_Unbounded_Stack<T>::delete_all_nodes (void)
00164 {
00165   //  ACE_TRACE ("ACE_Unbounded_Stack<T>::delete_all_nodes");
00166 
00167   while (this->is_empty () == 0)
00168     {
00169       ACE_Node<T> *temp = this->head_->next_;
00170       this->head_->next_ = temp->next_;
00171       ACE_DES_FREE_TEMPLATE (temp, this->allocator_->free,
00172                              ACE_Node, <T>);
00173     }
00174 
00175   this->cur_size_ = 0;
00176 
00177   ACE_ASSERT (this->head_ == this->head_->next_
00178               && this->is_empty ());
00179 }
00180 
00181 template<class T> void
00182 ACE_Unbounded_Stack<T>::copy_all_nodes (const ACE_Unbounded_Stack<T> &s)
00183 {
00184   //  ACE_TRACE ("ACE_Unbounded_Stack<T>::copy_all_nodes");
00185 
00186   ACE_ASSERT (this->head_ == this->head_->next_);
00187 
00188   ACE_Node<T> *temp = this->head_;
00189 
00190   for (ACE_Node<T> *s_temp = s.head_->next_;
00191        s_temp != s.head_;
00192        s_temp = s_temp->next_)
00193     {
00194       ACE_Node<T> *nptr = temp->next_;
00195       ACE_NEW_MALLOC (temp->next_,
00196                       (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)),
00197                       ACE_Node<T> (s_temp->item_, nptr));
00198       temp = temp->next_;
00199     }
00200   this->cur_size_ = s.cur_size_;
00201 }
00202 
00203 template<class T>
00204 ACE_Unbounded_Stack<T>::ACE_Unbounded_Stack (const ACE_Unbounded_Stack<T> &s)
00205   : head_ (0),
00206     cur_size_ (0),
00207     allocator_ (s.allocator_)
00208 {
00209   if (this->allocator_ == 0)
00210     this->allocator_ = ACE_Allocator::instance ();
00211 
00212   ACE_NEW_MALLOC (this->head_,
00213                   (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)),
00214                   ACE_Node<T>);
00215   this->head_->next_ = this->head_;
00216 
00217   //  ACE_TRACE ("ACE_Unbounded_Stack<T>::ACE_Unbounded_Stack");
00218   this->copy_all_nodes (s);
00219 }
00220 
00221 template<class T> void
00222 ACE_Unbounded_Stack<T>::operator= (const ACE_Unbounded_Stack<T> &s)
00223 {
00224   //  ACE_TRACE ("ACE_Unbounded_Stack<T>::operator=");
00225 
00226   if (this != &s)
00227     {
00228       this->delete_all_nodes ();
00229       this->copy_all_nodes (s);
00230     }
00231 }
00232 
00233 template<class T>
00234 ACE_Unbounded_Stack<T>::~ACE_Unbounded_Stack (void)
00235 {
00236   //  ACE_TRACE ("ACE_Unbounded_Stack<T>::~ACE_Unbounded_Stack");
00237 
00238   this->delete_all_nodes ();
00239   ACE_DES_FREE_TEMPLATE (head_,
00240                          this->allocator_->free,
00241                          ACE_Node,
00242                          <T>);
00243 }
00244 
00245 template<class T> int
00246 ACE_Unbounded_Stack<T>::push (const T &new_item)
00247 {
00248   //  ACE_TRACE ("ACE_Unbounded_Stack<T>::push");
00249 
00250   ACE_Node<T> *temp = 0;
00251 
00252   ACE_NEW_MALLOC_RETURN (temp,
00253                          static_cast<ACE_Node<T> *> (this->allocator_->malloc (sizeof (ACE_Node<T>))),
00254                          ACE_Node<T> (new_item, this->head_->next_),
00255                          -1);
00256   this->head_->next_ = temp;
00257   this->cur_size_++;
00258   return 0;
00259 }
00260 
00261 template<class T> int
00262 ACE_Unbounded_Stack<T>::pop (T &item)
00263 {
00264   //  ACE_TRACE ("ACE_Unbounded_Stack<T>::pop");
00265 
00266   if (this->is_empty ())
00267     return -1;
00268   else
00269     {
00270       ACE_Node<T> *temp = this->head_->next_;
00271       item = temp->item_;
00272       this->head_->next_ = temp->next_;
00273 
00274       ACE_DES_FREE_TEMPLATE (temp,
00275                              this->allocator_->free,
00276                              ACE_Node,
00277                              <T>);
00278       this->cur_size_--;
00279       return 0;
00280     }
00281 }
00282 
00283 template <class T> int
00284 ACE_Unbounded_Stack<T>::find (const T &item) const
00285 {
00286   // ACE_TRACE ("ACE_Unbounded_Stack<T>::find");
00287   // Set <item> into the dummy node.
00288   this->head_->item_ = item;
00289 
00290   ACE_Node<T> *temp = this->head_->next_;
00291 
00292   // Keep looping until we find the item.
00293   while (!(temp->item_ == item))
00294     temp = temp->next_;
00295 
00296   // If we found the dummy node then it's not really there, otherwise,
00297   // it is there.
00298   return temp == this->head_ ? -1 : 0;
00299 }
00300 
00301 template <class T> int
00302 ACE_Unbounded_Stack<T>::insert (const T &item)
00303 {
00304   // ACE_TRACE ("ACE_Unbounded_Stack<T>::insert");
00305 
00306   if (this->find (item) == 0)
00307     return 1;
00308   else
00309     return this->push (item);
00310 }
00311 
00312 template <class T> int
00313 ACE_Unbounded_Stack<T>::remove (const T &item)
00314 {
00315   // ACE_TRACE ("ACE_Unbounded_Stack<T>::remove");
00316 
00317   // Insert the item to be founded into the dummy node.
00318   this->head_->item_ = item;
00319 
00320   ACE_Node<T> *curr = this->head_;
00321 
00322   while (!(curr->next_->item_ == item))
00323     curr = curr->next_;
00324 
00325   if (curr->next_ == this->head_)
00326     return -1; // Item was not found.
00327   else
00328     {
00329       ACE_Node<T> *temp = curr->next_;
00330       // Skip over the node that we're deleting.
00331       curr->next_ = temp->next_;
00332       this->cur_size_--;
00333       ACE_DES_FREE_TEMPLATE (temp,
00334                              this->allocator_->free,
00335                              ACE_Node,
00336                              <T>);
00337       return 0;
00338     }
00339 }
00340 
00341 //--------------------------------------------------
00342 ACE_ALLOC_HOOK_DEFINE(ACE_Double_Linked_List_Iterator_Base)
00343 
00344 template <class T>
00345 ACE_Double_Linked_List_Iterator_Base<T>::ACE_Double_Linked_List_Iterator_Base (const ACE_Double_Linked_List<T> &dll)
00346   : current_ (0), dllist_ (&dll)
00347 {
00348   // Do nothing
00349 }
00350 
00351 template <class T>
00352 ACE_Double_Linked_List_Iterator_Base<T>::ACE_Double_Linked_List_Iterator_Base (const ACE_Double_Linked_List_Iterator_Base<T> &iter)
00353   : current_ (iter.current_),
00354     dllist_ (iter.dllist_)
00355 {
00356   // Do nothing
00357 }
00358 
00359 
00360 template <class T> T *
00361 ACE_Double_Linked_List_Iterator_Base<T>::next (void) const
00362 {
00363   return this->not_done ();
00364 }
00365 
00366 template <class T> int
00367 ACE_Double_Linked_List_Iterator_Base<T>::next (T *&ptr) const
00368 {
00369   ptr = this->not_done ();
00370   return ptr ? 1 : 0;
00371 }
00372 
00373 
00374 template <class T> int
00375 ACE_Double_Linked_List_Iterator_Base<T>::done (void) const
00376 {
00377   return this->not_done () ? 0 : 1;
00378 }
00379 
00380 template <class T> T &
00381 ACE_Double_Linked_List_Iterator_Base<T>::operator* (void) const
00382 {
00383   return *(this->not_done ());
00384 }
00385 
00386 // @@ Is this a valid retasking? Make sure to check with Purify and
00387 // whatnot that we're not leaking memory or doing any other screwing things.
00388 template <class T> void
00389 ACE_Double_Linked_List_Iterator_Base<T>::reset (ACE_Double_Linked_List<T> &dll)
00390 {
00391   current_ = 0;
00392   dllist_ = &dll;
00393 }
00394 
00395  template <class T> int
00396 ACE_Double_Linked_List_Iterator_Base<T>::go_head (void)
00397 {
00398   this->current_ = static_cast<T*> (dllist_->head_->next_);
00399   return this->current_ ? 1 : 0;
00400 }
00401 
00402 template <class T> int
00403 ACE_Double_Linked_List_Iterator_Base<T>::go_tail (void)
00404 {
00405   this->current_ = static_cast<T*> (dllist_->head_->prev_);
00406   return this->current_ ? 1 : 0;
00407 }
00408 
00409 template <class T> T *
00410 ACE_Double_Linked_List_Iterator_Base<T>::not_done (void) const
00411 {
00412   if (this->current_ != this->dllist_->head_)
00413     return this->current_;
00414   else
00415     return 0;
00416 }
00417 
00418 template <class T> T *
00419 ACE_Double_Linked_List_Iterator_Base<T>::do_advance (void)
00420 {
00421   if (this->not_done ())
00422     {
00423       this->current_ = static_cast<T*> (this->current_->next_);
00424       return this->not_done ();
00425     }
00426   else
00427     return 0;
00428 }
00429 
00430 template <class T> T *
00431 ACE_Double_Linked_List_Iterator_Base<T>::do_retreat (void)
00432 {
00433   if (this->not_done ())
00434     {
00435       this->current_ = static_cast<T*> (this->current_->prev_);
00436       return this->not_done ();
00437     }
00438   else
00439     return 0;
00440 }
00441 
00442 template <class T> void
00443 ACE_Double_Linked_List_Iterator_Base<T>::dump_i (void) const
00444 {
00445   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00446   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("current_ = %x"), this->current_));
00447   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00448 }
00449 
00450 //--------------------------------------------------
00451 ACE_ALLOC_HOOK_DEFINE(ACE_Double_Linked_List_Iterator)
00452 
00453 template <class T>
00454 ACE_Double_Linked_List_Iterator<T>::ACE_Double_Linked_List_Iterator (const ACE_Double_Linked_List<T> &dll)
00455   : ACE_Double_Linked_List_Iterator_Base <T> (dll)
00456 {
00457   this->current_ = static_cast<T*> (dll.head_->next_);
00458   // Advance current_ out of the null area and onto the first item in
00459   // the list
00460 }
00461 
00462 template <class T> void
00463 ACE_Double_Linked_List_Iterator<T>::reset (ACE_Double_Linked_List<T> &dll)
00464 {
00465   this->ACE_Double_Linked_List_Iterator_Base <T>::reset (dll);
00466   this->current_ = static_cast<T*> (dll.head_->next_);
00467   // Advance current_ out of the null area and onto the first item in
00468   // the list
00469 }
00470 
00471 template <class T> int
00472 ACE_Double_Linked_List_Iterator<T>::first (void)
00473 {
00474   return this->go_head ();
00475 }
00476 
00477 template <class T> int
00478 ACE_Double_Linked_List_Iterator<T>::advance (void)
00479 {
00480   return this->do_advance () ? 1 : 0;
00481 }
00482 
00483 template <class T> T*
00484 ACE_Double_Linked_List_Iterator<T>::advance_and_remove (int dont_remove)
00485 {
00486   T* item = 0;
00487   if (dont_remove)
00488     this->do_advance ();
00489   else
00490     {
00491       item = this->next ();
00492       this->do_advance ();
00493       // It seems dangerous to remove nodes in an iterator, but so it goes...
00494       ACE_Double_Linked_List<T> *dllist =
00495         const_cast<ACE_Double_Linked_List<T> *> (this->dllist_);
00496       dllist->remove (item);
00497     }
00498   return item;
00499 }
00500 
00501 template <class T> void
00502 ACE_Double_Linked_List_Iterator<T>::dump (void) const
00503 {
00504 #if defined (ACE_HAS_DUMP)
00505   this->dump_i ();
00506 #endif /* ACE_HAS_DUMP */
00507 }
00508 
00509 // Prefix advance.
00510 
00511 template <class T>
00512 ACE_Double_Linked_List_Iterator<T> &
00513 ACE_Double_Linked_List_Iterator<T>::operator++ (void)
00514 {
00515   this->do_advance ();
00516   return *this;
00517 }
00518 
00519 
00520 // Postfix advance.
00521 
00522 template <class T>
00523 ACE_Double_Linked_List_Iterator<T>
00524 ACE_Double_Linked_List_Iterator<T>::operator++ (int)
00525 {
00526   ACE_Double_Linked_List_Iterator<T> retv (*this);
00527   this->do_advance ();
00528   return retv;
00529 }
00530 
00531 
00532 // Prefix reverse.
00533 
00534 template <class T>
00535 ACE_Double_Linked_List_Iterator<T> &
00536 ACE_Double_Linked_List_Iterator<T>::operator-- (void)
00537 {
00538   this->do_retreat ();
00539   return *this;
00540 }
00541 
00542 
00543 // Postfix reverse.
00544 
00545 template <class T>
00546 ACE_Double_Linked_List_Iterator<T>
00547 ACE_Double_Linked_List_Iterator<T>::operator-- (int)
00548 {
00549   ACE_Double_Linked_List_Iterator<T> retv (*this);
00550   this->do_retreat ();
00551   return retv;
00552 }
00553 
00554 
00555 //--------------------------------------------------
00556 ACE_ALLOC_HOOK_DEFINE(ACE_Double_Linked_List_Reverse_Iterator)
00557 
00558   template <class T>
00559 ACE_Double_Linked_List_Reverse_Iterator<T>::ACE_Double_Linked_List_Reverse_Iterator (ACE_Double_Linked_List<T> &dll)
00560   : ACE_Double_Linked_List_Iterator_Base <T> (dll)
00561 {
00562   this->current_ = static_cast<T*> (dll.head_->prev_);
00563   // Advance current_ out of the null area and onto the last item in
00564   // the list
00565 }
00566 
00567 template <class T> void
00568 ACE_Double_Linked_List_Reverse_Iterator<T>::reset (ACE_Double_Linked_List<T> &dll)
00569 {
00570   this->ACE_Double_Linked_List_Iterator_Base <T>::reset (dll);
00571   this->current_ = static_cast<T*> (dll.head_->prev_);
00572   // Advance current_ out of the null area and onto the last item in
00573   // the list
00574 }
00575 
00576 template <class T> int
00577 ACE_Double_Linked_List_Reverse_Iterator<T>::first (void)
00578 {
00579   return this->go_tail ();
00580 }
00581 
00582 template <class T> int
00583 ACE_Double_Linked_List_Reverse_Iterator<T>::advance (void)
00584 {
00585   return this->do_retreat () ? 1 : 0;
00586 }
00587 
00588 template <class T> T*
00589 ACE_Double_Linked_List_Reverse_Iterator<T>::advance_and_remove (int dont_remove)
00590 {
00591   T* item = 0;
00592   if (dont_remove)
00593     this->do_retreat ();
00594   else
00595     {
00596       item = this->next ();
00597       this->do_retreat ();
00598       // It seems dangerous to remove nodes in an iterator, but so it goes...
00599       ACE_Double_Linked_List<T> *dllist =
00600         const_cast<ACE_Double_Linked_List<T> *> (this->dllist_);
00601       dllist->remove (item);
00602     }
00603   return item;
00604 }
00605 
00606 template <class T> void
00607 ACE_Double_Linked_List_Reverse_Iterator<T>::dump (void) const
00608 {
00609 #if defined (ACE_HAS_DUMP)
00610   this->dump_i ();
00611 #endif /* ACE_HAS_DUMP */
00612 }
00613 
00614 // Prefix advance.
00615 
00616 template <class T>
00617 ACE_Double_Linked_List_Reverse_Iterator<T> &
00618 ACE_Double_Linked_List_Reverse_Iterator<T>::operator++ (void)
00619 {
00620   this->do_retreat ();
00621   return *this;
00622 }
00623 
00624 
00625 // Postfix advance.
00626 
00627 template <class T>
00628 ACE_Double_Linked_List_Reverse_Iterator<T>
00629 ACE_Double_Linked_List_Reverse_Iterator<T>::operator++ (int)
00630 {
00631   ACE_Double_Linked_List_Reverse_Iterator<T> retv (*this);
00632   this->do_retreat ();
00633   return retv;
00634 }
00635 
00636 
00637 // Prefix reverse.
00638 
00639 template <class T>
00640 ACE_Double_Linked_List_Reverse_Iterator<T> &
00641 ACE_Double_Linked_List_Reverse_Iterator<T>::operator-- (void)
00642 {
00643   this->do_advance ();
00644   return *this;
00645 }
00646 
00647 
00648 // Postfix reverse.
00649 
00650 template <class T>
00651 ACE_Double_Linked_List_Reverse_Iterator<T>
00652 ACE_Double_Linked_List_Reverse_Iterator<T>::operator-- (int)
00653 {
00654   ACE_Double_Linked_List_Reverse_Iterator<T> retv (*this);
00655   this->do_advance ();
00656   return retv;
00657 }
00658 
00659 
00660 ACE_ALLOC_HOOK_DEFINE(ACE_Double_Linked_List)
00661 
00662   template <class T>
00663 ACE_Double_Linked_List<T>:: ACE_Double_Linked_List (ACE_Allocator *alloc)
00664   : size_ (0), allocator_ (alloc)
00665 {
00666   if (this->allocator_ == 0)
00667     this->allocator_ = ACE_Allocator::instance ();
00668 
00669   ACE_NEW_MALLOC (this->head_,
00670                   (T *) this->allocator_->malloc (sizeof (T)),
00671                   T);
00672   this->init_head ();
00673 }
00674 
00675 template <class T>
00676 ACE_Double_Linked_List<T>::ACE_Double_Linked_List (const ACE_Double_Linked_List<T> &cx)
00677   : allocator_ (cx.allocator_)
00678 {
00679   if (this->allocator_ == 0)
00680     this->allocator_ = ACE_Allocator::instance ();
00681 
00682   ACE_NEW_MALLOC (this->head_,
00683                   (T *) this->allocator_->malloc (sizeof (T)),
00684                   T);
00685   this->init_head ();
00686   this->copy_nodes (cx);
00687   this->size_ = cx.size_;
00688 }
00689 
00690 template <class T> void
00691 ACE_Double_Linked_List<T>::operator= (const ACE_Double_Linked_List<T> &cx)
00692 {
00693   if (this != &cx)
00694     {
00695       this->delete_nodes ();
00696       this->copy_nodes (cx);
00697     }
00698 }
00699 
00700 template <class T>
00701 ACE_Double_Linked_List<T>::~ACE_Double_Linked_List (void)
00702 {
00703   this->delete_nodes ();
00704 
00705   ACE_DES_FREE (head_,
00706                 this->allocator_->free,
00707                 T);
00708 
00709   this->head_ = 0;
00710 }
00711 
00712 template <class T> int
00713 ACE_Double_Linked_List<T>::is_empty (void) const
00714 {
00715   return this->size () ? 0 : 1;
00716 }
00717 
00718 template <class T> int
00719 ACE_Double_Linked_List<T>::is_full (void) const
00720 {
00721   return 0;                     // We have no bound.
00722 }
00723 
00724 template <class T> T *
00725 ACE_Double_Linked_List<T>::insert_tail (T *new_item)
00726 {
00727   // Insert it before <head_>, i.e., at tail.
00728   this->insert_element (new_item, 1);
00729   return new_item;
00730 }
00731 
00732 template <class T> T *
00733 ACE_Double_Linked_List<T>::insert_head (T *new_item)
00734 {
00735   this->insert_element (new_item); // Insert it after <head_>, i.e., at head.
00736   return new_item;
00737 }
00738 
00739 template <class T> T *
00740 ACE_Double_Linked_List<T>::delete_head (void)
00741 {
00742   T *temp;
00743 
00744   if (this->is_empty ())
00745     return 0;
00746 
00747   temp = static_cast<T *> (this->head_->next_);
00748   // Detach it from the list.
00749   this->remove_element (temp);
00750   return temp;
00751 }
00752 
00753 template <class T> T *
00754 ACE_Double_Linked_List<T>::delete_tail (void)
00755 {
00756   T *temp;
00757 
00758   if (this->is_empty ())
00759     return 0;
00760 
00761   temp = static_cast <T *> (this->head_->prev_);
00762   // Detach it from the list.
00763   this->remove_element (temp);
00764   return temp;
00765 }
00766 
00767 template <class T> void
00768 ACE_Double_Linked_List<T>::reset (void)
00769 {
00770   this->delete_nodes ();
00771 }
00772 
00773 template <class T> int
00774 ACE_Double_Linked_List<T>::get (T *&item, size_t slot)
00775 {
00776   ACE_Double_Linked_List_Iterator<T> iter (*this);
00777 
00778   for (size_t i = 0;
00779        i < slot && !iter.done ();
00780        i++)
00781     iter.advance ();
00782 
00783   item = iter.next ();
00784   return item ? 0 : -1;
00785 }
00786 
00787 template <class T> size_t
00788 ACE_Double_Linked_List<T>::size (void) const
00789 {
00790   return this->size_;
00791 }
00792 
00793 template <class T> void
00794 ACE_Double_Linked_List<T>::dump (void) const
00795 {
00796 #if defined (ACE_HAS_DUMP)
00797   // Dump the state of an object.
00798 #endif /* ACE_HAS_DUMP */
00799 }
00800 
00801 #if 0
00802 template <class T> T *
00803 ACE_Double_Linked_List<T>::find (const T &item)
00804 {
00805   for (ACE_Double_Linked_List_Iterator<T> iter (*this);
00806        !iter.done ();
00807        iter.advance ())
00808     {
00809       T *temp = iter.next ();
00810 
00811       if (*temp == item)
00812         return temp;
00813     }
00814 
00815   return 0;
00816 }
00817 
00818 template <class T> int
00819 ACE_Double_Linked_List<T>::remove (const T &item)
00820 {
00821   T *temp = this->find (item);
00822 
00823   if (temp != 0)
00824     return this->remove (temp);
00825   else
00826     return -1;
00827 }
00828 #endif /* 0 */
00829 
00830 template <class T> int
00831 ACE_Double_Linked_List<T>::remove (T *n)
00832 {
00833   return this->remove_element (n);
00834 }
00835 
00836 template <class T> void
00837 ACE_Double_Linked_List<T>::delete_nodes (void)
00838 {
00839   while (! this->is_empty ())
00840     {
00841       T * temp = static_cast<T*> (this->head_->next_);
00842       this->remove_element (temp);
00843       ACE_DES_FREE (temp,
00844                     this->allocator_->free,
00845                     T);
00846     }
00847 }
00848 
00849 template <class T> void
00850 ACE_Double_Linked_List<T>::copy_nodes (const ACE_Double_Linked_List<T> &c)
00851 {
00852   for (ACE_Double_Linked_List_Iterator<T> iter (c);
00853        !iter.done ();
00854        iter.advance ())
00855     {
00856       T* temp = 0;
00857       ACE_NEW_MALLOC (temp,
00858                       (T *)this->allocator_->malloc (sizeof (T)),
00859                       T (*iter.next ()));
00860       this->insert_tail (temp);
00861     }
00862 }
00863 
00864 template <class T> void
00865 ACE_Double_Linked_List<T>::init_head (void)
00866 {
00867   this->head_->next_ = this->head_;
00868   this->head_->prev_ = this->head_;
00869 }
00870 
00871 template <class T> int
00872 ACE_Double_Linked_List<T>::insert_element (T *new_item,
00873                                            int before,
00874                                            T *old_item)
00875 {
00876   if (old_item == 0)
00877     old_item = this->head_;
00878 
00879   if (before)
00880     old_item = static_cast<T *> (old_item->prev_);
00881 
00882   new_item->next_ = old_item->next_;
00883   new_item->next_->prev_ = new_item;
00884   new_item->prev_ = old_item;
00885   old_item->next_ = new_item;
00886   this->size_++;
00887   return 0;                     // Well, what will cause errors here?
00888 }
00889 
00890 template <class T> int
00891 ACE_Double_Linked_List<T>::remove_element (T *item)
00892 {
00893   // Notice that you have to ensure that item is an element of this
00894   // list.  We can't do much checking here.
00895 
00896   if (item == this->head_ || item->next_ == 0
00897       || item->prev_ == 0 || this->size () == 0)      // Can't remove head
00898     return -1;
00899 
00900   item->prev_->next_ = item->next_;
00901   item->next_->prev_ = item->prev_;
00902   item->next_ = item->prev_ = 0; // reset pointers to prevent double removal.
00903   this->size_--;
00904   return 0;
00905 }
00906 
00907 //--------------------------------------------------
00908 ACE_ALLOC_HOOK_DEFINE(ACE_Fixed_Set)
00909 
00910 template <class T, size_t ACE_SIZE> size_t
00911 ACE_Fixed_Set<T, ACE_SIZE>::size (void) const
00912 {
00913   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::size");
00914   return this->cur_size_;
00915 }
00916 
00917 template <class T, size_t ACE_SIZE> void
00918 ACE_Fixed_Set<T, ACE_SIZE>::dump (void) const
00919 {
00920 #if defined (ACE_HAS_DUMP)
00921   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::dump");
00922 #endif /* ACE_HAS_DUMP */
00923 }
00924 
00925 template <class T, size_t ACE_SIZE>
00926 ACE_Fixed_Set<T, ACE_SIZE>::~ACE_Fixed_Set (void)
00927 {
00928   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::~ACE_Fixed_Set");
00929   this->cur_size_ = 0;
00930 }
00931 
00932 template <class T, size_t ACE_SIZE>
00933 ACE_Fixed_Set<T, ACE_SIZE>::ACE_Fixed_Set (const ACE_Fixed_Set<T, ACE_SIZE> &fs)
00934   : cur_size_ (fs.cur_size_)
00935 {
00936   ACE_TRACE ("ACE_Fixed_Set<T>::ACE_Fixed_Set");
00937 
00938   for (size_t i = 0, j = 0; i < fs.max_size_ && j < this->cur_size_; ++i)
00939     if (fs.search_structure_[i].is_free_ == 0)
00940       this->search_structure_[j++] = fs.search_structure_[i];
00941 }
00942 
00943 template <class T, size_t ACE_SIZE> void
00944 ACE_Fixed_Set<T, ACE_SIZE>::operator= (const ACE_Fixed_Set<T, ACE_SIZE> &fs)
00945 {
00946   ACE_TRACE ("ACE_Fixed_Set<T>::operator=");
00947 
00948   if (this != &fs)
00949     {
00950       this->cur_size_ = fs.cur_size_;
00951 
00952       for (size_t i = 0, j = 0; i < fs.max_size_ && j < this->cur_size_; ++i)
00953         if (fs.search_structure_[i].is_free_ == 0)
00954           this->search_structure_[j++] = fs.search_structure_[i];
00955     }
00956 }
00957 
00958 template <class T, size_t ACE_SIZE>
00959 ACE_Fixed_Set<T, ACE_SIZE>::ACE_Fixed_Set (void)
00960   : cur_size_ (0),
00961     max_size_ (ACE_SIZE)
00962 {
00963   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::ACE_Fixed_Set");
00964   for (size_t i = 0; i < this->max_size_; i++)
00965     this->search_structure_[i].is_free_ = 1;
00966 }
00967 
00968 template <class T, size_t ACE_SIZE> int
00969 ACE_Fixed_Set<T, ACE_SIZE>::find (const T &item) const
00970 {
00971   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::find");
00972 
00973   for (size_t i = 0, j = 0; i < this->max_size_ && j < this->cur_size_; ++i)
00974     if (this->search_structure_[i].is_free_ == 0)
00975       {
00976         if (this->search_structure_[i].item_ == item)
00977           return 0;
00978         ++j;
00979       }
00980 
00981   return -1;
00982 }
00983 
00984 template <class T, size_t ACE_SIZE> int
00985 ACE_Fixed_Set<T, ACE_SIZE>::insert (const T &item)
00986 {
00987   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::insert");
00988   ssize_t first_free = -1;   // Keep track of first free slot.
00989   size_t i;
00990 
00991   for (i = 0;
00992        i < this->max_size_  && first_free == -1;
00993        ++i)
00994 
00995     // First, make sure we don't allow duplicates.
00996 
00997     if (this->search_structure_[i].is_free_ == 0)
00998       {
00999         if (this->search_structure_[i].item_ == item)
01000           return 1;
01001       }
01002     else
01003       first_free = i;
01004 
01005   // If we found a free spot let's reuse it.
01006 
01007   if (first_free > -1)
01008     {
01009       this->search_structure_[first_free].item_ = item;
01010       this->search_structure_[first_free].is_free_ = 0;
01011       this->cur_size_++;
01012       return 0;
01013     }
01014   else /* No more room! */
01015     {
01016       errno = ENOMEM;
01017       return -1;
01018     }
01019 }
01020 
01021 template <class T, size_t ACE_SIZE> int
01022 ACE_Fixed_Set<T, ACE_SIZE>::remove (const T &item)
01023 {
01024   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::remove");
01025 
01026   for (size_t i = 0, j = 0;
01027        i < this->max_size_ && j < this->cur_size_;
01028        ++i)
01029     if (this->search_structure_[i].is_free_ == 0)
01030       {
01031         if (this->search_structure_[i].item_ == item)
01032           {
01033             // Mark this entry as being free.
01034             this->search_structure_[i].is_free_ = 1;
01035 
01036             --this->cur_size_;
01037             return 0;
01038           }
01039         else
01040           ++j;
01041       }
01042 
01043   return -1;
01044 }
01045 
01046 //--------------------------------------------------
01047 ACE_ALLOC_HOOK_DEFINE(ACE_Fixed_Set_Iterator_Base)
01048 
01049 template <class T, size_t ACE_SIZE> void
01050 ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::dump_i (void) const
01051 {
01052 #if defined (ACE_HAS_DUMP)
01053   ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::dump_i");
01054 #endif /* ACE_HAS_DUMP */
01055 }
01056 
01057 template <class T, size_t ACE_SIZE>
01058 ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::ACE_Fixed_Set_Iterator_Base (ACE_Fixed_Set<T, ACE_SIZE> &s)
01059   : s_ (s),
01060     next_ (-1),
01061     iterated_items_ (0)
01062 {
01063   ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::ACE_Fixed_Set_Iterator_Base");
01064   this->advance ();
01065 }
01066 
01067 template <class T, size_t ACE_SIZE> int
01068 ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::advance (void)
01069 {
01070   ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::advance");
01071 
01072   if (this->iterated_items_ < this->s_.cur_size_)
01073     {
01074       for (++this->next_;
01075            static_cast<size_t> (this->next_) < this->s_.max_size_;
01076            ++this->next_)
01077       if (this->s_.search_structure_[this->next_].is_free_ == 0)
01078         {
01079           ++this->iterated_items_;
01080           return 1;
01081         }
01082     }
01083   else
01084     ++this->next_;
01085 
01086   return 0;
01087 }
01088 
01089 template <class T, size_t ACE_SIZE> int
01090 ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::first (void)
01091 {
01092   ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::first");
01093 
01094   next_ = -1;
01095   iterated_items_ = 0;
01096   return this->advance ();
01097 }
01098 
01099 template <class T, size_t ACE_SIZE> int
01100 ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::done (void) const
01101 {
01102   ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::done");
01103 
01104   return ! (this->iterated_items_ < this->s_.cur_size_);
01105 }
01106 
01107 template <class T, size_t ACE_SIZE> int
01108 ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::next_i (T *&item)
01109 {
01110   ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::next_i");
01111 
01112   if (static_cast<size_t> (this->next_) < this->s_.max_size_)
01113     do
01114       {
01115         if (this->s_.search_structure_[this->next_].is_free_ == 0)
01116           {
01117             item = &this->s_.search_structure_[this->next_].item_;
01118             this->advance ();
01119             return 1;
01120           }
01121       }
01122     while (this->advance () == 1);
01123 
01124   return 0;
01125 }
01126 
01127 //--------------------------------------------------
01128 ACE_ALLOC_HOOK_DEFINE(ACE_Fixed_Set_Iterator)
01129 
01130 template <class T, size_t ACE_SIZE> void
01131 ACE_Fixed_Set_Iterator<T, ACE_SIZE>::dump (void) const
01132 {
01133 #if defined (ACE_HAS_DUMP)
01134   this->dump_i ();
01135 #endif /* ACE_HAS_DUMP */
01136 }
01137 
01138 template <class T, size_t ACE_SIZE>
01139 ACE_Fixed_Set_Iterator<T, ACE_SIZE>::ACE_Fixed_Set_Iterator (ACE_Fixed_Set<T, ACE_SIZE> &s)
01140   : ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE> (s)
01141 {
01142   ACE_TRACE ("ACE_Fixed_Set_Iterator<T, ACE_SIZE>::ACE_Fixed_Set_Iterator");
01143 }
01144 
01145 template <class T, size_t ACE_SIZE> int
01146 ACE_Fixed_Set_Iterator<T, ACE_SIZE>::next (T *&item)
01147 {
01148   ACE_TRACE ("ACE_Fixed_Set_Iterator<T, ACE_SIZE>::next");
01149   return this->next_i (item);
01150 }
01151 
01152 template <class T, size_t ACE_SIZE> int
01153 ACE_Fixed_Set_Iterator<T, ACE_SIZE>::remove (T *&item)
01154 {
01155   ACE_TRACE ("ACE_Fixed_Set_Iterator<T, ACE_SIZE>::remove");
01156 
01157   if (this->s_.search_structure_[this->next_].is_free_ == 0)
01158     {
01159       item = &this->s_.search_structure_[this->next_].item_;
01160       this->s_.remove (*item);
01161       --(this->iterated_items_);
01162       return 1;
01163     }
01164 
01165   return 0;
01166 }
01167 
01168 template <class T, size_t ACE_SIZE> T&
01169 ACE_Fixed_Set_Iterator<T, ACE_SIZE>::operator* (void)
01170 {
01171   T *retv = 0;
01172 
01173   if (this->s_.search_structure_[this->next_].is_free_ == 0)
01174     retv = &this->s_.search_structure_[this->next_].item_;
01175 
01176   ACE_ASSERT (retv != 0);
01177 
01178   return *retv;
01179 }
01180 
01181 //--------------------------------------------------
01182 ACE_ALLOC_HOOK_DEFINE(ACE_Fixed_Set_Const_Iterator)
01183 
01184 template <class T, size_t ACE_SIZE> void
01185 ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>::dump (void) const
01186 {
01187 #if defined (ACE_HAS_DUMP)
01188   this->dump_i ();
01189 #endif /* ACE_HAS_DUMP */
01190 }
01191 
01192 template <class T, size_t ACE_SIZE>
01193 ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>::ACE_Fixed_Set_Const_Iterator (const ACE_Fixed_Set<T, ACE_SIZE> &s)
01194   : ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE> (s)
01195 {
01196   ACE_TRACE ("ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>::ACE_Fixed_Set_Const_Iterator");
01197 }
01198 
01199 template <class T, size_t ACE_SIZE> int
01200 ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>::next (const T *&item)
01201 {
01202   ACE_TRACE ("ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>::next");
01203 
01204   return this->next_i (item);
01205 }
01206 
01207 template <class T, size_t ACE_SIZE> const T&
01208 ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>::operator* (void) const
01209 {
01210   const T *retv = 0;
01211 
01212   if (this->s_.search_structure_[this->next_].is_free_ == 0)
01213     retv = &this->s_.search_structure_[this->next_].item_;
01214 
01215   ACE_ASSERT (retv != 0);
01216 
01217   return *retv;
01218 }
01219 
01220 //--------------------------------------------------
01221 ACE_ALLOC_HOOK_DEFINE(ACE_Bounded_Set)
01222 
01223 template <class T> void
01224 ACE_Bounded_Set<T>::dump (void) const
01225 {
01226 #if defined (ACE_HAS_DUMP)
01227   ACE_TRACE ("ACE_Bounded_Set<T>::dump");
01228 #endif /* ACE_HAS_DUMP */
01229 }
01230 
01231 template <class T>
01232 ACE_Bounded_Set<T>::~ACE_Bounded_Set (void)
01233 {
01234   ACE_TRACE ("ACE_Bounded_Set<T>::~ACE_Bounded_Set");
01235   delete [] this->search_structure_;
01236 }
01237 
01238 template <class T>
01239 ACE_Bounded_Set<T>::ACE_Bounded_Set (void)
01240   : cur_size_ (0),
01241     max_size_ (static_cast<size_t> (ACE_Bounded_Set<T>::DEFAULT_SIZE))
01242 {
01243   ACE_TRACE ("ACE_Bounded_Set<T>::ACE_Bounded_Set");
01244 
01245   ACE_NEW (this->search_structure_,
01246            ACE_TYPENAME ACE_Bounded_Set<T>::Search_Structure[this->max_size_]);
01247 
01248   for (size_t i = 0; i < this->max_size_; ++i)
01249     this->search_structure_[i].is_free_ = 1;
01250 }
01251 
01252 template <class T> size_t
01253 ACE_Bounded_Set<T>::size (void) const
01254 {
01255   ACE_TRACE ("ACE_Bounded_Set<T>::size");
01256   return this->cur_size_;
01257 }
01258 
01259 template <class T>
01260 ACE_Bounded_Set<T>::ACE_Bounded_Set (const ACE_Bounded_Set<T> &bs)
01261   : cur_size_ (bs.cur_size_),
01262     max_size_ (bs.max_size_)
01263 {
01264   ACE_TRACE ("ACE_Bounded_Set<T>::ACE_Bounded_Set");
01265 
01266   ACE_NEW (this->search_structure_,
01267            ACE_TYPENAME ACE_Bounded_Set<T>::Search_Structure[this->max_size_]);
01268 
01269   for (size_t i = 0; i < this->cur_size_; i++)
01270     this->search_structure_[i] = bs.search_structure_[i];
01271 }
01272 
01273 template <class T> void
01274 ACE_Bounded_Set<T>::operator= (const ACE_Bounded_Set<T> &bs)
01275 {
01276   ACE_TRACE ("ACE_Bounded_Set<T>::operator=");
01277 
01278   if (this != &bs)
01279     {
01280       if (this->max_size_ < bs.cur_size_)
01281         {
01282           delete [] this->search_structure_;
01283           ACE_NEW (this->search_structure_,
01284                    ACE_TYPENAME ACE_Bounded_Set<T>::Search_Structure[bs.cur_size_]);
01285           this->max_size_ = bs.cur_size_;
01286         }
01287 
01288       this->cur_size_ = bs.cur_size_;
01289 
01290       for (size_t i = 0; i < this->cur_size_; i++)
01291         this->search_structure_[i] = bs.search_structure_[i];
01292     }
01293 }
01294 
01295 template <class T>
01296 ACE_Bounded_Set<T>::ACE_Bounded_Set (size_t size)
01297   : cur_size_ (0),
01298     max_size_ (size)
01299 {
01300   ACE_TRACE ("ACE_Bounded_Set<T>::ACE_Bounded_Set");
01301   ACE_NEW (this->search_structure_,
01302            ACE_TYPENAME ACE_Bounded_Set<T>::Search_Structure[size]);
01303 
01304   for (size_t i = 0; i < this->max_size_; i++)
01305     this->search_structure_[i].is_free_ = 1;
01306 }
01307 
01308 template <class T> int
01309 ACE_Bounded_Set<T>::find (const T &item) const
01310 {
01311   ACE_TRACE ("ACE_Bounded_Set<T>::find");
01312 
01313   for (size_t i = 0; i < this->cur_size_; i++)
01314     if (this->search_structure_[i].item_ == item
01315         && this->search_structure_[i].is_free_ == 0)
01316       return 0;
01317 
01318   return -1;
01319 }
01320 
01321 template <class T> int
01322 ACE_Bounded_Set<T>::insert (const T &item)
01323 {
01324   ACE_TRACE ("ACE_Bounded_Set<T>::insert");
01325   int first_free = -1;   // Keep track of first free slot.
01326   size_t i;
01327 
01328   for (i = 0; i < this->cur_size_; i++)
01329     // First, make sure we don't allow duplicates.
01330 
01331     if (this->search_structure_[i].item_ == item
01332         && this->search_structure_[i].is_free_ == 0)
01333       return 1;
01334     else if (this->search_structure_[i].is_free_ && first_free == -1)
01335       first_free = static_cast<int> (i);
01336 
01337   if (first_free > -1)   // If we found a free spot let's reuse it.
01338     {
01339       this->search_structure_[first_free].item_ = item;
01340       this->search_structure_[first_free].is_free_ = 0;
01341       return 0;
01342     }
01343   else if (i < this->max_size_) // Insert at the end of the active portion.
01344     {
01345       this->search_structure_[i].item_ = item;
01346       this->search_structure_[i].is_free_ = 0;
01347       this->cur_size_++;
01348       return 0;
01349     }
01350   else /* No more room! */
01351     {
01352       errno = ENOMEM;
01353       return -1;
01354     }
01355 }
01356 
01357 template <class T> int
01358 ACE_Bounded_Set<T>::remove (const T &item)
01359 {
01360   ACE_TRACE ("ACE_Bounded_Set<T>::remove");
01361   for (size_t i = 0; i < this->cur_size_; i++)
01362     if (this->search_structure_[i].item_ == item)
01363       {
01364         // Mark this entry as being free.
01365         this->search_structure_[i].is_free_ = 1;
01366 
01367         // If we just unbound the highest entry, then we need to
01368         // figure out where the next highest active entry is.
01369         if (i + 1 == this->cur_size_)
01370           {
01371             while (i > 0 && this->search_structure_[--i].is_free_)
01372               continue;
01373 
01374             if (i == 0 && this->search_structure_[i].is_free_)
01375               this->cur_size_ = 0;
01376             else
01377               this->cur_size_ = i + 1;
01378           }
01379         return 0;
01380       }
01381 
01382   return -1;
01383 }
01384 
01385 ACE_ALLOC_HOOK_DEFINE(ACE_Bounded_Set_Iterator)
01386 
01387   template <class T> void
01388 ACE_Bounded_Set_Iterator<T>::dump (void) const
01389 {
01390 #if defined (ACE_HAS_DUMP)
01391   ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::dump");
01392 #endif /* ACE_HAS_DUMP */
01393 }
01394 
01395 template <class T>
01396 ACE_Bounded_Set_Iterator<T>::ACE_Bounded_Set_Iterator (ACE_Bounded_Set<T> &s)
01397   : s_ (s),
01398     next_ (-1)
01399 {
01400   ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::ACE_Bounded_Set_Iterator");
01401   this->advance ();
01402 }
01403 
01404 template <class T> int
01405 ACE_Bounded_Set_Iterator<T>::advance (void)
01406 {
01407   ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::advance");
01408 
01409   for (++this->next_;
01410        static_cast<size_t> (this->next_) < this->s_.cur_size_
01411          && this->s_.search_structure_[this->next_].is_free_;
01412        ++this->next_)
01413     continue;
01414 
01415   return static_cast<size_t> (this->next_) < this->s_.cur_size_;
01416 }
01417 
01418 template <class T> int
01419 ACE_Bounded_Set_Iterator<T>::first (void)
01420 {
01421   ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::first");
01422 
01423   next_ = -1;
01424   return this->advance ();
01425 }
01426 
01427 template <class T> int
01428 ACE_Bounded_Set_Iterator<T>::done (void) const
01429 {
01430   ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::done");
01431 
01432   return static_cast<ACE_CAST_CONST size_t> (this->next_) >=
01433     this->s_.cur_size_;
01434 }
01435 
01436 template <class T> int
01437 ACE_Bounded_Set_Iterator<T>::next (T *&item)
01438 {
01439   ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::next");
01440   if (static_cast<size_t> (this->next_) < this->s_.cur_size_)
01441     {
01442       item = &this->s_.search_structure_[this->next_].item_;
01443       return 1;
01444     }
01445   else
01446     return 0;
01447 }
01448 
01449 ACE_ALLOC_HOOK_DEFINE(ACE_DNode)
01450 
01451   template <class T>
01452 ACE_DNode<T>::ACE_DNode (const T &i, ACE_DNode<T> *n, ACE_DNode<T> *p)
01453   : next_ (n), prev_ (p), item_ (i)
01454 {
01455 }
01456 
01457 # if ! defined (ACE_HAS_BROKEN_NOOP_DTORS)
01458 template <class T>
01459 ACE_DNode<T>::~ACE_DNode (void)
01460 {
01461 }
01462 # endif /* ! defined (ACE_HAS_BROKEN_NOOP_DTORS) */
01463 
01464 // ****************************************************************
01465 
01466 template <class T> void
01467 ACE_Unbounded_Stack_Iterator<T>::dump (void) const
01468 {
01469 #if defined (ACE_HAS_DUMP)
01470   // ACE_TRACE ("ACE_Unbounded_Stack_Iterator<T>::dump");
01471 #endif /* ACE_HAS_DUMP */
01472 }
01473 
01474 template <class T>
01475 ACE_Unbounded_Stack_Iterator<T>::ACE_Unbounded_Stack_Iterator (ACE_Unbounded_Stack<T> &q)
01476   : current_ (q.head_->next_),
01477     stack_ (q)
01478 {
01479   // ACE_TRACE ("ACE_Unbounded_Stack_Iterator<T>::ACE_Unbounded_Stack_Iterator");
01480 }
01481 
01482 template <class T> int
01483 ACE_Unbounded_Stack_Iterator<T>::advance (void)
01484 {
01485   // ACE_TRACE ("ACE_Unbounded_Stack_Iterator<T>::advance");
01486   this->current_ = this->current_->next_;
01487   return this->current_ != this->stack_.head_;
01488 }
01489 
01490 template <class T> int
01491 ACE_Unbounded_Stack_Iterator<T>::first (void)
01492 {
01493   // ACE_TRACE ("ACE_Unbounded_Stack_Iterator<T>::first");
01494   this->current_ = this->stack_.head_->next_;
01495   return this->current_ != this->stack_.head_;
01496 }
01497 
01498 template <class T> int
01499 ACE_Unbounded_Stack_Iterator<T>::done (void) const
01500 {
01501   ACE_TRACE ("ACE_Unbounded_Stack_Iterator<T>::done");
01502 
01503   return this->current_ == this->stack_.head_;
01504 }
01505 
01506 template <class T> int
01507 ACE_Unbounded_Stack_Iterator<T>::next (T *&item)
01508 {
01509   // ACE_TRACE ("ACE_Unbounded_Stack_Iterator<T>::next");
01510   if (this->current_ == this->stack_.head_)
01511     return 0;
01512   else
01513     {
01514       item = &this->current_->item_;
01515       return 1;
01516     }
01517 }
01518 
01519 
01520 ACE_ALLOC_HOOK_DEFINE(ACE_Ordered_MultiSet)
01521 
01522 
01523   template <class T>
01524 ACE_Ordered_MultiSet<T>::ACE_Ordered_MultiSet (ACE_Allocator *alloc)
01525   : head_ (0)
01526   , tail_ (0)
01527   , cur_size_ (0)
01528   , allocator_ (alloc)
01529 {
01530   // ACE_TRACE ("ACE_Ordered_MultiSet<T>::ACE_Ordered_MultiSet");
01531 
01532   if (this->allocator_ == 0)
01533     this->allocator_ = ACE_Allocator::instance ();
01534 }
01535 
01536 template <class T>
01537 ACE_Ordered_MultiSet<T>::ACE_Ordered_MultiSet (const ACE_Ordered_MultiSet<T> &us)
01538   : head_ (0)
01539   , tail_ (0)
01540   , cur_size_ (0)
01541   , allocator_ (us.allocator_)
01542 {
01543   ACE_TRACE ("ACE_Ordered_MultiSet<T>::ACE_Ordered_MultiSet");
01544 
01545   if (this->allocator_ == 0)
01546     this->allocator_ = ACE_Allocator::instance ();
01547 
01548   this->copy_nodes (us);
01549 }
01550 
01551 template <class T>
01552 ACE_Ordered_MultiSet<T>::~ACE_Ordered_MultiSet (void)
01553 {
01554   // ACE_TRACE ("ACE_Ordered_MultiSet<T>::~ACE_Ordered_MultiSet");
01555 
01556   this->delete_nodes ();
01557 }
01558 
01559 
01560 template <class T> void
01561 ACE_Ordered_MultiSet<T>::operator= (const ACE_Ordered_MultiSet<T> &us)
01562 {
01563   ACE_TRACE ("ACE_Ordered_MultiSet<T>::operator=");
01564 
01565   if (this != &us)
01566     {
01567       this->delete_nodes ();
01568       this->copy_nodes (us);
01569     }
01570 }
01571 
01572 
01573 template <class T> int
01574 ACE_Ordered_MultiSet<T>::insert (const T &item)
01575 {
01576   // ACE_TRACE ("ACE_Ordered_MultiSet<T>::insert");
01577 
01578   return  this->insert_from (item, this->head_, 0);
01579 }
01580 
01581 template <class T> int
01582 ACE_Ordered_MultiSet<T>::insert (const T &new_item,
01583                                  ITERATOR &iter)
01584 {
01585   // ACE_TRACE ("ACE_Ordered_MultiSet<T>::insert using iterator");
01586 
01587   return  this->insert_from (new_item, iter.current_, &iter.current_);
01588 }
01589 
01590 template <class T> int
01591 ACE_Ordered_MultiSet<T>::remove (const T &item)
01592 {
01593   // ACE_TRACE ("ACE_Ordered_MultiSet<T>::remove");
01594 
01595   ACE_DNode<T> *node = 0;
01596 
01597   int result = locate (item, 0, node);
01598 
01599   // if we found the node, remove from list and free it
01600   if (node && (result == 0))
01601     {
01602       if (node->prev_)
01603         node->prev_->next_ = node->next_;
01604       else
01605         head_ = node->next_;
01606 
01607       if (node->next_)
01608         node->next_->prev_ = node->prev_;
01609       else
01610         tail_ = node->prev_;
01611 
01612       this->cur_size_--;
01613 
01614       ACE_DES_FREE_TEMPLATE (node,
01615                              this->allocator_->free,
01616                              ACE_DNode,
01617                              <T>);
01618       return 0;
01619     }
01620 
01621   return -1;
01622 }
01623 
01624 template <class T> int
01625 ACE_Ordered_MultiSet<T>::find (const T &item,
01626                                ITERATOR &iter) const
01627 {
01628   // search an occurance of item, using iterator's current position as a hint
01629   ACE_DNode<T> *node = iter.current_;
01630   int result = locate (item, node, node);
01631 
01632   // if we found the node, update the iterator and indicate success
01633   if (node && (result == 0))
01634     {
01635       iter.current_ = node;
01636       return 0;
01637     }
01638 
01639   return -1;
01640 }
01641 
01642 
01643 
01644 template <class T> void
01645 ACE_Ordered_MultiSet<T>::reset (void)
01646 {
01647   ACE_TRACE ("reset");
01648 
01649   this->delete_nodes ();
01650 }
01651 
01652 template <class T> void
01653 ACE_Ordered_MultiSet<T>::dump (void) const
01654 {
01655 #if defined (ACE_HAS_DUMP)
01656   //  ACE_TRACE ("ACE_Ordered_MultiSet<T>::dump");
01657   //
01658   //  ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
01659   //  ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("\nhead_ = %u"), this->head_));
01660   //  ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("\nhead_->next_ = %u"), this->head_->next_));
01661   //  ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("\ncur_size_ = %d\n"), this->cur_size_));
01662   //
01663   //  T *item = 0;
01664   //  size_t count = 1;
01665   //
01666   //  for (ACE_Ordered_MultiSet_Iterator<T> iter (*(ACE_Ordered_MultiSet<T> *) this);
01667   //       iter.next (item) != 0;
01668   //       iter.advance ())
01669   //    ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("count = %d\n"), count++));
01670   //
01671   //  ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
01672 #endif /* ACE_HAS_DUMP */
01673 }
01674 
01675 template <class T> int
01676 ACE_Ordered_MultiSet<T>::insert_from (const T &item, ACE_DNode<T> *position,
01677                                       ACE_DNode<T> **new_position)
01678 {
01679   // ACE_TRACE ("ACE_Ordered_MultiSet<T>::insert_from");
01680 
01681   // create a new node
01682   ACE_DNode<T> *temp;
01683   ACE_NEW_MALLOC_RETURN (temp,
01684                          static_cast<ACE_DNode<T>*> (this->allocator_->malloc (sizeof (ACE_DNode<T>))),
01685                          ACE_DNode<T> (item),
01686                          -1);
01687   // obtain approximate location of the node
01688   int result = locate (item, position, position);
01689 
01690   // if there are nodes in the multiset
01691   if (position)
01692     {
01693       switch (result)
01694         {
01695           // insert after the approximate position
01696         case -1:
01697 
01698           // if there is a following node
01699           if (position->next_)
01700             {
01701               // link up with the following node
01702               position->next_->prev_ = temp;
01703               temp->next_ = position->next_;
01704             }
01705           else
01706             // appending to the end of the set
01707             tail_ = temp;
01708 
01709           // link up with the preceeding node
01710           temp->prev_ = position;
01711           position->next_ = temp;
01712 
01713           break;
01714 
01715           // insert before the position
01716         case  0:
01717         case  1:
01718 
01719           // if there is a preceeding node
01720           if (position->prev_)
01721             {
01722               // link up with the preceeding node
01723               position->prev_->next_ = temp;
01724               temp->prev_ = position->prev_;
01725             }
01726           else
01727             // prepending to the start of the set
01728             head_ = temp;
01729 
01730           // link up with the preceeding node
01731           temp->next_ = position;
01732           position->prev_ = temp;
01733 
01734           break;
01735 
01736         default:
01737           return -1;
01738         }
01739     }
01740   else
01741     {
01742       // point the head and tail to the new node.
01743       this->head_ = temp;
01744       this->tail_ = temp;
01745     }
01746 
01747   this->cur_size_++;
01748   if (new_position)
01749     *new_position = temp;
01750 
01751   return 0;
01752 }
01753 
01754 template <class T> int
01755 ACE_Ordered_MultiSet<T>::locate (const T &item, ACE_DNode<T> *start_position,
01756                                  ACE_DNode<T> *&new_position) const
01757 {
01758   if (! start_position)
01759     start_position = this->head_;
01760 
01761   // If starting before the item, move forward until at or just before
01762   // item.
01763   while (start_position && start_position->item_ < item &&
01764          start_position->next_)
01765     start_position = start_position->next_;
01766 
01767   // If starting after the item, move back until at or just after item
01768   while (start_position && item < start_position->item_ &&
01769          start_position->prev_)
01770     start_position = start_position->prev_;
01771 
01772   // Save the (approximate) location in the passed pointer.
01773   new_position = start_position;
01774 
01775   // Show the location is after (1), before (-1) , or at (0) the item
01776   if (!new_position)
01777     return 1;
01778   else if (item < new_position->item_)
01779     return 1;
01780   else if (new_position->item_ < item)
01781     return -1;
01782   else
01783     return 0;
01784 }
01785 
01786 // Looks for first occurance of <item> in the ordered set, using the
01787 // passed starting position as a hint: if there is such an instance,
01788 // it updates the new_position pointer to point to one such node and
01789 // returns 0; if there is no such node, then if there is a node before
01790 // where the item would have been, it updates the new_position pointer
01791 // to point to this node and returns -1; if there is no such node,
01792 // then if there is a node after where the item would have been, it
01793 // updates the new_position pointer to point to this node (or 0 if
01794 // there is no such node) and returns 1;
01795 
01796 template <class T> void
01797 ACE_Ordered_MultiSet<T>::copy_nodes (const ACE_Ordered_MultiSet<T> &us)
01798 {
01799   ACE_DNode<T> *insertion_point = this->head_;
01800 
01801   for (ACE_DNode<T> *curr = us.head_;
01802        curr != 0;
01803        curr = curr->next_)
01804     this->insert_from (curr->item_, insertion_point, &insertion_point);
01805 }
01806 
01807 template <class T> void
01808 ACE_Ordered_MultiSet<T>::delete_nodes (void)
01809 {
01810   // iterate through list, deleting nodes
01811   for (ACE_DNode<T> *curr = this->head_;
01812        curr != 0;
01813        )
01814     {
01815       ACE_DNode<T> *temp = curr;
01816       curr = curr->next_;
01817       ACE_DES_FREE_TEMPLATE (temp,
01818                              this->allocator_->free,
01819                              ACE_DNode,
01820                              <T>);
01821     }
01822 
01823   this->head_ = 0;
01824   this->tail_ = 0;
01825   this->cur_size_ = 0;
01826 }
01827 
01828 ACE_ALLOC_HOOK_DEFINE(ACE_Ordered_MultiSet_Iterator)
01829 
01830 template <class T>
01831 ACE_Ordered_MultiSet_Iterator<T>::ACE_Ordered_MultiSet_Iterator (ACE_Ordered_MultiSet<T> &s)
01832   : current_ (s.head_),
01833     set_ (s)
01834 {
01835   // ACE_TRACE ("ACE_Ordered_MultiSet_Iterator<T>::ACE_Ordered_MultiSet_Iterator");
01836 }
01837 
01838 template <class T> int
01839 ACE_Ordered_MultiSet_Iterator<T>::next (T *&item) const
01840 {
01841   // ACE_TRACE ("ACE_Ordered_MultiSet_Iterator<T>::next");
01842   if (this->current_)
01843     {
01844       item = &this->current_->item_;
01845       return 1;
01846     }
01847 
01848   return 0;
01849 }
01850 
01851 template <class T> T&
01852 ACE_Ordered_MultiSet_Iterator<T>::operator* (void)
01853 {
01854   //ACE_TRACE ("ACE_Ordered_MultiSet_Iterator<T>::operator*");
01855   T *retv = 0;
01856 
01857   int result = this->next (retv);
01858   ACE_ASSERT (result != 0);
01859   ACE_UNUSED_ARG (result);
01860 
01861   return *retv;
01862 }
01863 
01864 ACE_ALLOC_HOOK_DEFINE (ACE_DLList_Node)
01865 
01866 template <class T> T *
01867 ACE_DLList<T>::insert_tail (T *new_item)
01868 {
01869   ACE_DLList_Node *temp1, *temp2;
01870   ACE_NEW_MALLOC_RETURN (temp1,
01871                          static_cast<ACE_DLList_Node *> (this->allocator_->malloc (sizeof (ACE_DLList_Node))),
01872                          ACE_DLList_Node ((void *&)new_item),
01873                          0);
01874   temp2 = ACE_DLList_Base::insert_tail (temp1);
01875   return (T *) (temp2 ? temp2->item_ : 0);
01876 }
01877 
01878 template <class T> T *
01879 ACE_DLList<T>::insert_head (T *new_item)
01880 {
01881   ACE_DLList_Node *temp1;
01882   ACE_NEW_MALLOC_RETURN (temp1,
01883                          (ACE_DLList_Node *) this->allocator_->malloc (sizeof (ACE_DLList_Node)),
01884                          ACE_DLList_Node ((void *&)new_item), 0);
01885   ACE_DLList_Node *temp2 =
01886     ACE_DLList_Base::insert_head (temp1);
01887   return (T *) (temp2 ? temp2->item_ : 0);
01888 }
01889 
01890 template <class T> T *
01891 ACE_DLList<T>::delete_head (void)
01892 {
01893   ACE_DLList_Node *temp1 = ACE_DLList_Base::delete_head ();
01894   T *temp2 = (T *) (temp1 ? temp1->item_ : 0);
01895   ACE_DES_FREE (temp1,
01896                 this->allocator_->free,
01897                 ACE_DLList_Node);
01898 
01899   return temp2;
01900 }
01901 
01902 template <class T> T *
01903 ACE_DLList<T>::delete_tail (void)
01904 {
01905   ACE_DLList_Node *temp1 = ACE_DLList_Base::delete_tail ();
01906   T *temp2 = (T *) (temp1 ? temp1->item_ : 0);
01907   ACE_DES_FREE (temp1,
01908                 this->allocator_->free,
01909                 ACE_DLList_Node);
01910   return temp2;
01911 }
01912 
01913 // ****************************************************************
01914 
01915 // Compare this array with <s> for equality.
01916 
01917 template <class T> bool
01918 ACE_Array<T>::operator== (const ACE_Array<T> &s) const
01919 {
01920   if (this == &s)
01921     return true;
01922   else if (this->size () != s.size ())
01923     return false;
01924 
01925   const size_t len = s.size ();
01926   for (size_t slot = 0; slot < len; ++slot)
01927     if ((*this)[slot] != s[slot])
01928       return false;
01929 
01930   return true;
01931 }
01932 
01933 // ****************************************************************
01934 
01935 ACE_END_VERSIONED_NAMESPACE_DECL
01936 
01937 #endif /* ACE_CONTAINERS_T_CPP */

Generated on Thu Nov 9 09:41:49 2006 for ACE by doxygen 1.3.6