Containers_T.cpp

Go to the documentation of this file.
00001 // $Id: Containers_T.cpp 80826 2008-03-04 14:51:23Z wotte $
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_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   if (this->is_empty ())
00743     return 0;
00744 
00745   T *temp = static_cast<T *> (this->head_->next_);
00746   // Detach it from the list.
00747   this->remove_element (temp);
00748   return temp;
00749 }
00750 
00751 template <class T> T *
00752 ACE_Double_Linked_List<T>::delete_tail (void)
00753 {
00754   if (this->is_empty ())
00755     return 0;
00756 
00757   T *temp = static_cast <T *> (this->head_->prev_);
00758   // Detach it from the list.
00759   this->remove_element (temp);
00760   return temp;
00761 }
00762 
00763 template <class T> void
00764 ACE_Double_Linked_List<T>::reset (void)
00765 {
00766   this->delete_nodes ();
00767 }
00768 
00769 template <class T> int
00770 ACE_Double_Linked_List<T>::get (T *&item, size_t slot)
00771 {
00772   ACE_Double_Linked_List_Iterator<T> iter (*this);
00773 
00774   for (size_t i = 0;
00775        i < slot && !iter.done ();
00776        i++)
00777     iter.advance ();
00778 
00779   item = iter.next ();
00780   return item ? 0 : -1;
00781 }
00782 
00783 template <class T> size_t
00784 ACE_Double_Linked_List<T>::size (void) const
00785 {
00786   return this->size_;
00787 }
00788 
00789 template <class T> void
00790 ACE_Double_Linked_List<T>::dump (void) const
00791 {
00792 #if defined (ACE_HAS_DUMP)
00793   // Dump the state of an object.
00794 #endif /* ACE_HAS_DUMP */
00795 }
00796 
00797 #if 0
00798 template <class T> T *
00799 ACE_Double_Linked_List<T>::find (const T &item)
00800 {
00801   for (ACE_Double_Linked_List_Iterator<T> iter (*this);
00802        !iter.done ();
00803        iter.advance ())
00804     {
00805       T *temp = iter.next ();
00806 
00807       if (*temp == item)
00808         return temp;
00809     }
00810 
00811   return 0;
00812 }
00813 
00814 template <class T> int
00815 ACE_Double_Linked_List<T>::remove (const T &item)
00816 {
00817   T *temp = this->find (item);
00818 
00819   if (temp != 0)
00820     return this->remove (temp);
00821   else
00822     return -1;
00823 }
00824 #endif /* 0 */
00825 
00826 template <class T> int
00827 ACE_Double_Linked_List<T>::remove (T *n)
00828 {
00829   return this->remove_element (n);
00830 }
00831 
00832 template <class T> void
00833 ACE_Double_Linked_List<T>::delete_nodes (void)
00834 {
00835   while (! this->is_empty ())
00836     {
00837       T * temp = static_cast<T*> (this->head_->next_);
00838       this->remove_element (temp);
00839       ACE_DES_FREE (temp,
00840                     this->allocator_->free,
00841                     T);
00842     }
00843 }
00844 
00845 template <class T> void
00846 ACE_Double_Linked_List<T>::copy_nodes (const ACE_Double_Linked_List<T> &c)
00847 {
00848   for (ACE_Double_Linked_List_Iterator<T> iter (c);
00849        !iter.done ();
00850        iter.advance ())
00851     {
00852       T* temp = 0;
00853       ACE_NEW_MALLOC (temp,
00854                       (T *)this->allocator_->malloc (sizeof (T)),
00855                       T (*iter.next ()));
00856       this->insert_tail (temp);
00857     }
00858 }
00859 
00860 template <class T> void
00861 ACE_Double_Linked_List<T>::init_head (void)
00862 {
00863   this->head_->next_ = this->head_;
00864   this->head_->prev_ = this->head_;
00865 }
00866 
00867 template <class T> int
00868 ACE_Double_Linked_List<T>::insert_element (T *new_item,
00869                                            int before,
00870                                            T *old_item)
00871 {
00872   if (old_item == 0)
00873     old_item = this->head_;
00874 
00875   if (before)
00876     old_item = static_cast<T *> (old_item->prev_);
00877 
00878   new_item->next_ = old_item->next_;
00879   new_item->next_->prev_ = new_item;
00880   new_item->prev_ = old_item;
00881   old_item->next_ = new_item;
00882   ++this->size_;
00883   return 0;                     // Well, what will cause errors here?
00884 }
00885 
00886 template <class T> int
00887 ACE_Double_Linked_List<T>::remove_element (T *item)
00888 {
00889   // Notice that you have to ensure that item is an element of this
00890   // list.  We can't do much checking here.
00891 
00892   if (item == this->head_ || item->next_ == 0
00893       || item->prev_ == 0 || this->size () == 0)      // Can't remove head
00894     return -1;
00895 
00896   item->prev_->next_ = item->next_;
00897   item->next_->prev_ = item->prev_;
00898   item->next_ = item->prev_ = 0; // reset pointers to prevent double removal.
00899   --this->size_;
00900   return 0;
00901 }
00902 
00903 //--------------------------------------------------
00904 ACE_ALLOC_HOOK_DEFINE(ACE_Fixed_Set)
00905 
00906 template <class T, size_t ACE_SIZE> size_t
00907 ACE_Fixed_Set<T, ACE_SIZE>::size (void) const
00908 {
00909   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::size");
00910   return this->cur_size_;
00911 }
00912 
00913 template <class T, size_t ACE_SIZE> void
00914 ACE_Fixed_Set<T, ACE_SIZE>::dump (void) const
00915 {
00916 #if defined (ACE_HAS_DUMP)
00917   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::dump");
00918 #endif /* ACE_HAS_DUMP */
00919 }
00920 
00921 template <class T, size_t ACE_SIZE>
00922 ACE_Fixed_Set<T, ACE_SIZE>::~ACE_Fixed_Set (void)
00923 {
00924   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::~ACE_Fixed_Set");
00925   this->cur_size_ = 0;
00926 }
00927 
00928 template <class T, size_t ACE_SIZE>
00929 ACE_Fixed_Set<T, ACE_SIZE>::ACE_Fixed_Set (const ACE_Fixed_Set<T, ACE_SIZE> &fs)
00930   : cur_size_ (fs.cur_size_)
00931 {
00932   ACE_TRACE ("ACE_Fixed_Set<T>::ACE_Fixed_Set");
00933 
00934   for (size_t i = 0, j = 0; i < fs.max_size_ && j < this->cur_size_; ++i)
00935     if (fs.search_structure_[i].is_free_ == 0)
00936       this->search_structure_[j++] = fs.search_structure_[i];
00937 }
00938 
00939 template <class T, size_t ACE_SIZE> void
00940 ACE_Fixed_Set<T, ACE_SIZE>::operator= (const ACE_Fixed_Set<T, ACE_SIZE> &fs)
00941 {
00942   ACE_TRACE ("ACE_Fixed_Set<T>::operator=");
00943 
00944   if (this != &fs)
00945     {
00946       this->cur_size_ = fs.cur_size_;
00947 
00948       for (size_t i = 0, j = 0; i < fs.max_size_ && j < this->cur_size_; ++i)
00949         if (fs.search_structure_[i].is_free_ == 0)
00950           this->search_structure_[j++] = fs.search_structure_[i];
00951     }
00952 }
00953 
00954 template <class T, size_t ACE_SIZE>
00955 ACE_Fixed_Set<T, ACE_SIZE>::ACE_Fixed_Set (void)
00956   : cur_size_ (0),
00957     max_size_ (ACE_SIZE)
00958 {
00959   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::ACE_Fixed_Set");
00960   for (size_t i = 0; i < this->max_size_; i++)
00961     this->search_structure_[i].is_free_ = 1;
00962 }
00963 
00964 template <class T, size_t ACE_SIZE> int
00965 ACE_Fixed_Set<T, ACE_SIZE>::find (const T &item) const
00966 {
00967   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::find");
00968 
00969   for (size_t i = 0, j = 0; i < this->max_size_ && j < this->cur_size_; ++i)
00970     if (this->search_structure_[i].is_free_ == 0)
00971       {
00972         if (this->search_structure_[i].item_ == item)
00973           return 0;
00974         ++j;
00975       }
00976 
00977   return -1;
00978 }
00979 
00980 template <class T, size_t ACE_SIZE> int
00981 ACE_Fixed_Set<T, ACE_SIZE>::insert (const T &item)
00982 {
00983   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::insert");
00984   ssize_t first_free = -1;   // Keep track of first free slot.
00985   size_t i;
00986 
00987   for (i = 0;
00988        i < this->max_size_  && first_free == -1;
00989        ++i)
00990 
00991     // First, make sure we don't allow duplicates.
00992 
00993     if (this->search_structure_[i].is_free_ == 0)
00994       {
00995         if (this->search_structure_[i].item_ == item)
00996           return 1;
00997       }
00998     else
00999       first_free = static_cast<ssize_t> (i);
01000 
01001   // If we found a free spot let's reuse it.
01002 
01003   if (first_free > -1)
01004     {
01005       this->search_structure_[first_free].item_ = item;
01006       this->search_structure_[first_free].is_free_ = 0;
01007       this->cur_size_++;
01008       return 0;
01009     }
01010   else /* No more room! */
01011     {
01012       errno = ENOMEM;
01013       return -1;
01014     }
01015 }
01016 
01017 template <class T, size_t ACE_SIZE> int
01018 ACE_Fixed_Set<T, ACE_SIZE>::remove (const T &item)
01019 {
01020   ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::remove");
01021 
01022   for (size_t i = 0, j = 0;
01023        i < this->max_size_ && j < this->cur_size_;
01024        ++i)
01025     if (this->search_structure_[i].is_free_ == 0)
01026       {
01027         if (this->search_structure_[i].item_ == item)
01028           {
01029             // Mark this entry as being free.
01030             this->search_structure_[i].is_free_ = 1;
01031 
01032             --this->cur_size_;
01033             return 0;
01034           }
01035         else
01036           ++j;
01037       }
01038 
01039   return -1;
01040 }
01041 
01042 //--------------------------------------------------
01043 ACE_ALLOC_HOOK_DEFINE(ACE_Fixed_Set_Iterator_Base)
01044 
01045 template <class T, size_t ACE_SIZE> void
01046 ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::dump_i (void) const
01047 {
01048 #if defined (ACE_HAS_DUMP)
01049   ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::dump_i");
01050 #endif /* ACE_HAS_DUMP */
01051 }
01052 
01053 template <class T, size_t ACE_SIZE>
01054 ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::ACE_Fixed_Set_Iterator_Base (ACE_Fixed_Set<T, ACE_SIZE> &s)
01055   : s_ (s),
01056     next_ (-1),
01057     iterated_items_ (0)
01058 {
01059   ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::ACE_Fixed_Set_Iterator_Base");
01060   this->advance ();
01061 }
01062 
01063 template <class T, size_t ACE_SIZE> int
01064 ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::advance (void)
01065 {
01066   ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::advance");
01067 
01068   if (this->iterated_items_ < this->s_.cur_size_)
01069     {
01070       for (++this->next_;
01071            static_cast<size_t> (this->next_) < this->s_.max_size_;
01072            ++this->next_)
01073       if (this->s_.search_structure_[this->next_].is_free_ == 0)
01074         {
01075           ++this->iterated_items_;
01076           return 1;
01077         }
01078     }
01079   else
01080     ++this->next_;
01081 
01082   return 0;
01083 }
01084 
01085 template <class T, size_t ACE_SIZE> int
01086 ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::first (void)
01087 {
01088   ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::first");
01089 
01090   next_ = -1;
01091   iterated_items_ = 0;
01092   return this->advance ();
01093 }
01094 
01095 template <class T, size_t ACE_SIZE> int
01096 ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::done (void) const
01097 {
01098   ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::done");
01099 
01100   return ! (this->iterated_items_ < this->s_.cur_size_);
01101 }
01102 
01103 template <class T, size_t ACE_SIZE> int
01104 ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::next_i (T *&item)
01105 {
01106   ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::next_i");
01107 
01108   if (static_cast<size_t> (this->next_) < this->s_.max_size_)
01109     do
01110       {
01111         if (this->s_.search_structure_[this->next_].is_free_ == 0)
01112           {
01113             item = &this->s_.search_structure_[this->next_].item_;
01114             this->advance ();
01115             return 1;
01116           }
01117       }
01118     while (this->advance () == 1);
01119 
01120   return 0;
01121 }
01122 
01123 //--------------------------------------------------
01124 ACE_ALLOC_HOOK_DEFINE(ACE_Fixed_Set_Iterator)
01125 
01126 template <class T, size_t ACE_SIZE> void
01127 ACE_Fixed_Set_Iterator<T, ACE_SIZE>::dump (void) const
01128 {
01129 #if defined (ACE_HAS_DUMP)
01130   this->dump_i ();
01131 #endif /* ACE_HAS_DUMP */
01132 }
01133 
01134 template <class T, size_t ACE_SIZE>
01135 ACE_Fixed_Set_Iterator<T, ACE_SIZE>::ACE_Fixed_Set_Iterator (ACE_Fixed_Set<T, ACE_SIZE> &s)
01136   : ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE> (s)
01137 {
01138   ACE_TRACE ("ACE_Fixed_Set_Iterator<T, ACE_SIZE>::ACE_Fixed_Set_Iterator");
01139 }
01140 
01141 template <class T, size_t ACE_SIZE> int
01142 ACE_Fixed_Set_Iterator<T, ACE_SIZE>::next (T *&item)
01143 {
01144   ACE_TRACE ("ACE_Fixed_Set_Iterator<T, ACE_SIZE>::next");
01145   return this->next_i (item);
01146 }
01147 
01148 template <class T, size_t ACE_SIZE> int
01149 ACE_Fixed_Set_Iterator<T, ACE_SIZE>::remove (T *&item)
01150 {
01151   ACE_TRACE ("ACE_Fixed_Set_Iterator<T, ACE_SIZE>::remove");
01152 
01153   if (this->s_.search_structure_[this->next_].is_free_ == 0)
01154     {
01155       item = &this->s_.search_structure_[this->next_].item_;
01156       this->s_.remove (*item);
01157       --(this->iterated_items_);
01158       return 1;
01159     }
01160 
01161   return 0;
01162 }
01163 
01164 template <class T, size_t ACE_SIZE> T&
01165 ACE_Fixed_Set_Iterator<T, ACE_SIZE>::operator* (void)
01166 {
01167   T *retv = 0;
01168 
01169   if (this->s_.search_structure_[this->next_].is_free_ == 0)
01170     retv = &this->s_.search_structure_[this->next_].item_;
01171 
01172   ACE_ASSERT (retv != 0);
01173 
01174   return *retv;
01175 }
01176 
01177 //--------------------------------------------------
01178 ACE_ALLOC_HOOK_DEFINE(ACE_Fixed_Set_Const_Iterator)
01179 
01180 template <class T, size_t ACE_SIZE> void
01181 ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>::dump (void) const
01182 {
01183 #if defined (ACE_HAS_DUMP)
01184   this->dump_i ();
01185 #endif /* ACE_HAS_DUMP */
01186 }
01187 
01188 template <class T, size_t ACE_SIZE>
01189 ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>::ACE_Fixed_Set_Const_Iterator (const ACE_Fixed_Set<T, ACE_SIZE> &s)
01190   : ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE> (s)
01191 {
01192   ACE_TRACE ("ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>::ACE_Fixed_Set_Const_Iterator");
01193 }
01194 
01195 template <class T, size_t ACE_SIZE> int
01196 ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>::next (const T *&item)
01197 {
01198   ACE_TRACE ("ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>::next");
01199 
01200   return this->next_i (item);
01201 }
01202 
01203 template <class T, size_t ACE_SIZE> const T&
01204 ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>::operator* (void) const
01205 {
01206   const T *retv = 0;
01207 
01208   if (this->s_.search_structure_[this->next_].is_free_ == 0)
01209     retv = &this->s_.search_structure_[this->next_].item_;
01210 
01211   ACE_ASSERT (retv != 0);
01212 
01213   return *retv;
01214 }
01215 
01216 //--------------------------------------------------
01217 ACE_ALLOC_HOOK_DEFINE(ACE_Bounded_Set)
01218 
01219 template <class T> void
01220 ACE_Bounded_Set<T>::dump (void) const
01221 {
01222 #if defined (ACE_HAS_DUMP)
01223   ACE_TRACE ("ACE_Bounded_Set<T>::dump");
01224 #endif /* ACE_HAS_DUMP */
01225 }
01226 
01227 template <class T>
01228 ACE_Bounded_Set<T>::~ACE_Bounded_Set (void)
01229 {
01230   ACE_TRACE ("ACE_Bounded_Set<T>::~ACE_Bounded_Set");
01231   delete [] this->search_structure_;
01232 }
01233 
01234 template <class T>
01235 ACE_Bounded_Set<T>::ACE_Bounded_Set (void)
01236   : cur_size_ (0),
01237     max_size_ (static_cast<size_t> (ACE_Bounded_Set<T>::DEFAULT_SIZE))
01238 {
01239   ACE_TRACE ("ACE_Bounded_Set<T>::ACE_Bounded_Set");
01240 
01241   ACE_NEW (this->search_structure_,
01242            typename ACE_Bounded_Set<T>::Search_Structure[this->max_size_]);
01243 
01244   for (size_t i = 0; i < this->max_size_; ++i)
01245     this->search_structure_[i].is_free_ = 1;
01246 }
01247 
01248 template <class T> size_t
01249 ACE_Bounded_Set<T>::size (void) const
01250 {
01251   ACE_TRACE ("ACE_Bounded_Set<T>::size");
01252   return this->cur_size_;
01253 }
01254 
01255 template <class T>
01256 ACE_Bounded_Set<T>::ACE_Bounded_Set (const ACE_Bounded_Set<T> &bs)
01257   : cur_size_ (bs.cur_size_),
01258     max_size_ (bs.max_size_)
01259 {
01260   ACE_TRACE ("ACE_Bounded_Set<T>::ACE_Bounded_Set");
01261 
01262   ACE_NEW (this->search_structure_,
01263            typename ACE_Bounded_Set<T>::Search_Structure[this->max_size_]);
01264 
01265   for (size_t i = 0; i < this->cur_size_; i++)
01266     this->search_structure_[i] = bs.search_structure_[i];
01267 }
01268 
01269 template <class T> void
01270 ACE_Bounded_Set<T>::operator= (const ACE_Bounded_Set<T> &bs)
01271 {
01272   ACE_TRACE ("ACE_Bounded_Set<T>::operator=");
01273 
01274   if (this != &bs)
01275     {
01276       if (this->max_size_ < bs.cur_size_)
01277         {
01278           delete [] this->search_structure_;
01279           ACE_NEW (this->search_structure_,
01280                    typename ACE_Bounded_Set<T>::Search_Structure[bs.cur_size_]);
01281           this->max_size_ = bs.cur_size_;
01282         }
01283 
01284       this->cur_size_ = bs.cur_size_;
01285 
01286       for (size_t i = 0; i < this->cur_size_; i++)
01287         this->search_structure_[i] = bs.search_structure_[i];
01288     }
01289 }
01290 
01291 template <class T>
01292 ACE_Bounded_Set<T>::ACE_Bounded_Set (size_t size)
01293   : cur_size_ (0),
01294     max_size_ (size)
01295 {
01296   ACE_TRACE ("ACE_Bounded_Set<T>::ACE_Bounded_Set");
01297   ACE_NEW (this->search_structure_,
01298            typename ACE_Bounded_Set<T>::Search_Structure[size]);
01299 
01300   for (size_t i = 0; i < this->max_size_; i++)
01301     this->search_structure_[i].is_free_ = 1;
01302 }
01303 
01304 template <class T> int
01305 ACE_Bounded_Set<T>::find (const T &item) const
01306 {
01307   ACE_TRACE ("ACE_Bounded_Set<T>::find");
01308 
01309   for (size_t i = 0; i < this->cur_size_; i++)
01310     if (this->search_structure_[i].item_ == item
01311         && this->search_structure_[i].is_free_ == 0)
01312       return 0;
01313 
01314   return -1;
01315 }
01316 
01317 template <class T> int
01318 ACE_Bounded_Set<T>::insert (const T &item)
01319 {
01320   ACE_TRACE ("ACE_Bounded_Set<T>::insert");
01321   int first_free = -1;   // Keep track of first free slot.
01322   size_t i;
01323 
01324   for (i = 0; i < this->cur_size_; i++)
01325     // First, make sure we don't allow duplicates.
01326 
01327     if (this->search_structure_[i].item_ == item
01328         && this->search_structure_[i].is_free_ == 0)
01329       return 1;
01330     else if (this->search_structure_[i].is_free_ && first_free == -1)
01331       first_free = static_cast<int> (i);
01332 
01333   if (first_free > -1)   // If we found a free spot let's reuse it.
01334     {
01335       this->search_structure_[first_free].item_ = item;
01336       this->search_structure_[first_free].is_free_ = 0;
01337       return 0;
01338     }
01339   else if (i < this->max_size_) // Insert at the end of the active portion.
01340     {
01341       this->search_structure_[i].item_ = item;
01342       this->search_structure_[i].is_free_ = 0;
01343       this->cur_size_++;
01344       return 0;
01345     }
01346   else /* No more room! */
01347     {
01348       errno = ENOMEM;
01349       return -1;
01350     }
01351 }
01352 
01353 template <class T> int
01354 ACE_Bounded_Set<T>::remove (const T &item)
01355 {
01356   ACE_TRACE ("ACE_Bounded_Set<T>::remove");
01357   for (size_t i = 0; i < this->cur_size_; i++)
01358     if (this->search_structure_[i].item_ == item)
01359       {
01360         // Mark this entry as being free.
01361         this->search_structure_[i].is_free_ = 1;
01362 
01363         // If we just unbound the highest entry, then we need to
01364         // figure out where the next highest active entry is.
01365         if (i + 1 == this->cur_size_)
01366           {
01367             while (i > 0 && this->search_structure_[--i].is_free_)
01368               continue;
01369 
01370             if (i == 0 && this->search_structure_[i].is_free_)
01371               this->cur_size_ = 0;
01372             else
01373               this->cur_size_ = i + 1;
01374           }
01375         return 0;
01376       }
01377 
01378   return -1;
01379 }
01380 
01381 ACE_ALLOC_HOOK_DEFINE(ACE_Bounded_Set_Iterator)
01382 
01383   template <class T> void
01384 ACE_Bounded_Set_Iterator<T>::dump (void) const
01385 {
01386 #if defined (ACE_HAS_DUMP)
01387   ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::dump");
01388 #endif /* ACE_HAS_DUMP */
01389 }
01390 
01391 template <class T>
01392 ACE_Bounded_Set_Iterator<T>::ACE_Bounded_Set_Iterator (ACE_Bounded_Set<T> &s)
01393   : s_ (s),
01394     next_ (-1)
01395 {
01396   ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::ACE_Bounded_Set_Iterator");
01397   this->advance ();
01398 }
01399 
01400 template <class T> int
01401 ACE_Bounded_Set_Iterator<T>::advance (void)
01402 {
01403   ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::advance");
01404 
01405   for (++this->next_;
01406        static_cast<size_t> (this->next_) < this->s_.cur_size_
01407          && this->s_.search_structure_[this->next_].is_free_;
01408        ++this->next_)
01409     continue;
01410 
01411   return static_cast<size_t> (this->next_) < this->s_.cur_size_;
01412 }
01413 
01414 template <class T> int
01415 ACE_Bounded_Set_Iterator<T>::first (void)
01416 {
01417   ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::first");
01418 
01419   next_ = -1;
01420   return this->advance ();
01421 }
01422 
01423 template <class T> int
01424 ACE_Bounded_Set_Iterator<T>::done (void) const
01425 {
01426   ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::done");
01427 
01428   return static_cast<ACE_CAST_CONST size_t> (this->next_) >=
01429     this->s_.cur_size_;
01430 }
01431 
01432 template <class T> int
01433 ACE_Bounded_Set_Iterator<T>::next (T *&item)
01434 {
01435   ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::next");
01436   if (static_cast<size_t> (this->next_) < this->s_.cur_size_)
01437     {
01438       item = &this->s_.search_structure_[this->next_].item_;
01439       return 1;
01440     }
01441   else
01442     return 0;
01443 }
01444 
01445 ACE_ALLOC_HOOK_DEFINE(ACE_DNode)
01446 
01447   template <class T>
01448 ACE_DNode<T>::ACE_DNode (const T &i, ACE_DNode<T> *n, ACE_DNode<T> *p)
01449   : next_ (n), prev_ (p), item_ (i)
01450 {
01451 }
01452 
01453 template <class T>
01454 ACE_DNode<T>::~ACE_DNode (void)
01455 {
01456 }
01457 
01458 // ****************************************************************
01459 
01460 template <class T> void
01461 ACE_Unbounded_Stack_Iterator<T>::dump (void) const
01462 {
01463 #if defined (ACE_HAS_DUMP)
01464   // ACE_TRACE ("ACE_Unbounded_Stack_Iterator<T>::dump");
01465 #endif /* ACE_HAS_DUMP */
01466 }
01467 
01468 template <class T>
01469 ACE_Unbounded_Stack_Iterator<T>::ACE_Unbounded_Stack_Iterator (ACE_Unbounded_Stack<T> &q)
01470   : current_ (q.head_->next_),
01471     stack_ (q)
01472 {
01473   // ACE_TRACE ("ACE_Unbounded_Stack_Iterator<T>::ACE_Unbounded_Stack_Iterator");
01474 }
01475 
01476 template <class T> int
01477 ACE_Unbounded_Stack_Iterator<T>::advance (void)
01478 {
01479   // ACE_TRACE ("ACE_Unbounded_Stack_Iterator<T>::advance");
01480   this->current_ = this->current_->next_;
01481   return this->current_ != this->stack_.head_;
01482 }
01483 
01484 template <class T> int
01485 ACE_Unbounded_Stack_Iterator<T>::first (void)
01486 {
01487   // ACE_TRACE ("ACE_Unbounded_Stack_Iterator<T>::first");
01488   this->current_ = this->stack_.head_->next_;
01489   return this->current_ != this->stack_.head_;
01490 }
01491 
01492 template <class T> int
01493 ACE_Unbounded_Stack_Iterator<T>::done (void) const
01494 {
01495   ACE_TRACE ("ACE_Unbounded_Stack_Iterator<T>::done");
01496 
01497   return this->current_ == this->stack_.head_;
01498 }
01499 
01500 template <class T> int
01501 ACE_Unbounded_Stack_Iterator<T>::next (T *&item)
01502 {
01503   // ACE_TRACE ("ACE_Unbounded_Stack_Iterator<T>::next");
01504   if (this->current_ == this->stack_.head_)
01505     return 0;
01506   else
01507     {
01508       item = &this->current_->item_;
01509       return 1;
01510     }
01511 }
01512 
01513 
01514 ACE_ALLOC_HOOK_DEFINE(ACE_Ordered_MultiSet)
01515 
01516 
01517   template <class T>
01518 ACE_Ordered_MultiSet<T>::ACE_Ordered_MultiSet (ACE_Allocator *alloc)
01519   : head_ (0)
01520   , tail_ (0)
01521   , cur_size_ (0)
01522   , allocator_ (alloc)
01523 {
01524   // ACE_TRACE ("ACE_Ordered_MultiSet<T>::ACE_Ordered_MultiSet");
01525 
01526   if (this->allocator_ == 0)
01527     this->allocator_ = ACE_Allocator::instance ();
01528 }
01529 
01530 template <class T>
01531 ACE_Ordered_MultiSet<T>::ACE_Ordered_MultiSet (const ACE_Ordered_MultiSet<T> &us)
01532   : head_ (0)
01533   , tail_ (0)
01534   , cur_size_ (0)
01535   , allocator_ (us.allocator_)
01536 {
01537   ACE_TRACE ("ACE_Ordered_MultiSet<T>::ACE_Ordered_MultiSet");
01538 
01539   if (this->allocator_ == 0)
01540     this->allocator_ = ACE_Allocator::instance ();
01541 
01542   this->copy_nodes (us);
01543 }
01544 
01545 template <class T>
01546 ACE_Ordered_MultiSet<T>::~ACE_Ordered_MultiSet (void)
01547 {
01548   // ACE_TRACE ("ACE_Ordered_MultiSet<T>::~ACE_Ordered_MultiSet");
01549 
01550   this->delete_nodes ();
01551 }
01552 
01553 
01554 template <class T> void
01555 ACE_Ordered_MultiSet<T>::operator= (const ACE_Ordered_MultiSet<T> &us)
01556 {
01557   ACE_TRACE ("ACE_Ordered_MultiSet<T>::operator=");
01558 
01559   if (this != &us)
01560     {
01561       this->delete_nodes ();
01562       this->copy_nodes (us);
01563     }
01564 }
01565 
01566 
01567 template <class T> int
01568 ACE_Ordered_MultiSet<T>::insert (const T &item)
01569 {
01570   // ACE_TRACE ("ACE_Ordered_MultiSet<T>::insert");
01571 
01572   return this->insert_from (item, this->head_, 0);
01573 }
01574 
01575 template <class T> int
01576 ACE_Ordered_MultiSet<T>::insert (const T &new_item,
01577                                  ITERATOR &iter)
01578 {
01579   // ACE_TRACE ("ACE_Ordered_MultiSet<T>::insert using iterator");
01580 
01581   return  this->insert_from (new_item, iter.current_, &iter.current_);
01582 }
01583 
01584 template <class T> int
01585 ACE_Ordered_MultiSet<T>::remove (const T &item)
01586 {
01587   // ACE_TRACE ("ACE_Ordered_MultiSet<T>::remove");
01588 
01589   ACE_DNode<T> *node = 0;
01590 
01591   int result = locate (item, 0, node);
01592 
01593   // if we found the node, remove from list and free it
01594   if (node && (result == 0))
01595     {
01596       if (node->prev_)
01597         node->prev_->next_ = node->next_;
01598       else
01599         head_ = node->next_;
01600 
01601       if (node->next_)
01602         node->next_->prev_ = node->prev_;
01603       else
01604         tail_ = node->prev_;
01605 
01606       --this->cur_size_;
01607 
01608       ACE_DES_FREE_TEMPLATE (node,
01609                              this->allocator_->free,
01610                              ACE_DNode,
01611                              <T>);
01612       return 0;
01613     }
01614 
01615   return -1;
01616 }
01617 
01618 template <class T> int
01619 ACE_Ordered_MultiSet<T>::find (const T &item,
01620                                ITERATOR &iter) const
01621 {
01622   // search an occurance of item, using iterator's current position as a hint
01623   ACE_DNode<T> *node = iter.current_;
01624   int const result = locate (item, node, node);
01625 
01626   // if we found the node, update the iterator and indicate success
01627   if (node && (result == 0))
01628     {
01629       iter.current_ = node;
01630       return 0;
01631     }
01632 
01633   return -1;
01634 }
01635 
01636 
01637 
01638 template <class T> void
01639 ACE_Ordered_MultiSet<T>::reset (void)
01640 {
01641   ACE_TRACE ("reset");
01642 
01643   this->delete_nodes ();
01644 }
01645 
01646 template <class T> void
01647 ACE_Ordered_MultiSet<T>::dump (void) const
01648 {
01649 #if defined (ACE_HAS_DUMP)
01650   //  ACE_TRACE ("ACE_Ordered_MultiSet<T>::dump");
01651   //
01652   //  ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
01653   //  ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("\nhead_ = %u"), this->head_));
01654   //  ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("\nhead_->next_ = %u"), this->head_->next_));
01655   //  ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("\ncur_size_ = %d\n"), this->cur_size_));
01656   //
01657   //  T *item = 0;
01658   //  size_t count = 1;
01659   //
01660   //  for (ACE_Ordered_MultiSet_Iterator<T> iter (*(ACE_Ordered_MultiSet<T> *) this);
01661   //       iter.next (item) != 0;
01662   //       iter.advance ())
01663   //    ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("count = %d\n"), count++));
01664   //
01665   //  ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
01666 #endif /* ACE_HAS_DUMP */
01667 }
01668 
01669 template <class T> int
01670 ACE_Ordered_MultiSet<T>::insert_from (const T &item, ACE_DNode<T> *position,
01671                                       ACE_DNode<T> **new_position)
01672 {
01673   // ACE_TRACE ("ACE_Ordered_MultiSet<T>::insert_from");
01674 
01675   // create a new node
01676   ACE_DNode<T> *temp = 0;
01677   ACE_NEW_MALLOC_RETURN (temp,
01678                          static_cast<ACE_DNode<T>*> (this->allocator_->malloc (sizeof (ACE_DNode<T>))),
01679                          ACE_DNode<T> (item),
01680                          -1);
01681   // obtain approximate location of the node
01682   int result = locate (item, position, position);
01683 
01684   // if there are nodes in the multiset
01685   if (position)
01686     {
01687       switch (result)
01688         {
01689           // insert after the approximate position
01690         case -1:
01691 
01692           // if there is a following node
01693           if (position->next_)
01694             {
01695               // link up with the following node
01696               position->next_->prev_ = temp;
01697               temp->next_ = position->next_;
01698             }
01699           else
01700             // appending to the end of the set
01701             tail_ = temp;
01702 
01703           // link up with the preceeding node
01704           temp->prev_ = position;
01705           position->next_ = temp;
01706 
01707           break;
01708 
01709           // insert before the position
01710         case  0:
01711         case  1:
01712 
01713           // if there is a preceeding node
01714           if (position->prev_)
01715             {
01716               // link up with the preceeding node
01717               position->prev_->next_ = temp;
01718               temp->prev_ = position->prev_;
01719             }
01720           else
01721             // prepending to the start of the set
01722             head_ = temp;
01723 
01724           // link up with the preceeding node
01725           temp->next_ = position;
01726           position->prev_ = temp;
01727 
01728           break;
01729 
01730         default:
01731           return -1;
01732         }
01733     }
01734   else
01735     {
01736       // point the head and tail to the new node.
01737       this->head_ = temp;
01738       this->tail_ = temp;
01739     }
01740 
01741   ++this->cur_size_;
01742   if (new_position)
01743     *new_position = temp;
01744 
01745   return 0;
01746 }
01747 
01748 template <class T> int
01749 ACE_Ordered_MultiSet<T>::locate (const T &item, ACE_DNode<T> *start_position,
01750                                  ACE_DNode<T> *&new_position) const
01751 {
01752   if (! start_position)
01753     start_position = this->head_;
01754 
01755   // If starting before the item, move forward until at or just before
01756   // item.
01757   while (start_position && start_position->item_ < item &&
01758          start_position->next_)
01759     start_position = start_position->next_;
01760 
01761   // If starting after the item, move back until at or just after item
01762   while (start_position && item < start_position->item_ &&
01763          start_position->prev_)
01764     start_position = start_position->prev_;
01765 
01766   // Save the (approximate) location in the passed pointer.
01767   new_position = start_position;
01768 
01769   // Show the location is after (1), before (-1) , or at (0) the item
01770   if (!new_position)
01771     return 1;
01772   else if (item < new_position->item_)
01773     return 1;
01774   else if (new_position->item_ < item)
01775     return -1;
01776   else
01777     return 0;
01778 }
01779 
01780 // Looks for first occurance of <item> in the ordered set, using the
01781 // passed starting position as a hint: if there is such an instance,
01782 // it updates the new_position pointer to point to one such node and
01783 // returns 0; if there is no such node, then if there is a node before
01784 // where the item would have been, it updates the new_position pointer
01785 // to point to this node and returns -1; if there is no such node,
01786 // then if there is a node after where the item would have been, it
01787 // updates the new_position pointer to point to this node (or 0 if
01788 // there is no such node) and returns 1;
01789 
01790 template <class T> void
01791 ACE_Ordered_MultiSet<T>::copy_nodes (const ACE_Ordered_MultiSet<T> &us)
01792 {
01793   ACE_DNode<T> *insertion_point = this->head_;
01794 
01795   for (ACE_DNode<T> *curr = us.head_;
01796        curr != 0;
01797        curr = curr->next_)
01798     this->insert_from (curr->item_, insertion_point, &insertion_point);
01799 }
01800 
01801 template <class T> void
01802 ACE_Ordered_MultiSet<T>::delete_nodes (void)
01803 {
01804   // iterate through list, deleting nodes
01805   for (ACE_DNode<T> *curr = this->head_;
01806        curr != 0;
01807        )
01808     {
01809       ACE_DNode<T> *temp = curr;
01810       curr = curr->next_;
01811       ACE_DES_FREE_TEMPLATE (temp,
01812                              this->allocator_->free,
01813                              ACE_DNode,
01814                              <T>);
01815     }
01816 
01817   this->head_ = 0;
01818   this->tail_ = 0;
01819   this->cur_size_ = 0;
01820 }
01821 
01822 ACE_ALLOC_HOOK_DEFINE(ACE_Ordered_MultiSet_Iterator)
01823 
01824 template <class T>
01825 ACE_Ordered_MultiSet_Iterator<T>::ACE_Ordered_MultiSet_Iterator (ACE_Ordered_MultiSet<T> &s)
01826   : current_ (s.head_),
01827     set_ (s)
01828 {
01829   // ACE_TRACE ("ACE_Ordered_MultiSet_Iterator<T>::ACE_Ordered_MultiSet_Iterator");
01830 }
01831 
01832 template <class T> int
01833 ACE_Ordered_MultiSet_Iterator<T>::next (T *&item) const
01834 {
01835   // ACE_TRACE ("ACE_Ordered_MultiSet_Iterator<T>::next");
01836   if (this->current_)
01837     {
01838       item = &this->current_->item_;
01839       return 1;
01840     }
01841 
01842   return 0;
01843 }
01844 
01845 template <class T> T&
01846 ACE_Ordered_MultiSet_Iterator<T>::operator* (void)
01847 {
01848   //ACE_TRACE ("ACE_Ordered_MultiSet_Iterator<T>::operator*");
01849   T *retv = 0;
01850 
01851   int const result = this->next (retv);
01852   ACE_ASSERT (result != 0);
01853   ACE_UNUSED_ARG (result);
01854 
01855   return *retv;
01856 }
01857 
01858 ACE_ALLOC_HOOK_DEFINE (ACE_DLList_Node)
01859 
01860 template <class T> T *
01861 ACE_DLList<T>::insert_tail (T *new_item)
01862 {
01863   ACE_DLList_Node *temp1 = 0;
01864   ACE_NEW_MALLOC_RETURN (temp1,
01865                          static_cast<ACE_DLList_Node *> (this->allocator_->malloc (sizeof (ACE_DLList_Node))),
01866                          ACE_DLList_Node (new_item),
01867                          0);
01868   ACE_DLList_Node *temp2 = ACE_DLList_Base::insert_tail (temp1);
01869   return (T *) (temp2 ? temp2->item_ : 0);
01870 }
01871 
01872 template <class T> T *
01873 ACE_DLList<T>::insert_head (T *new_item)
01874 {
01875   ACE_DLList_Node *temp1 = 0;
01876   ACE_NEW_MALLOC_RETURN (temp1,
01877                          (ACE_DLList_Node *) this->allocator_->malloc (sizeof (ACE_DLList_Node)),
01878                          ACE_DLList_Node (new_item), 0);
01879   ACE_DLList_Node *temp2 = ACE_DLList_Base::insert_head (temp1);
01880   return (T *) (temp2 ? temp2->item_ : 0);
01881 }
01882 
01883 template <class T> T *
01884 ACE_DLList<T>::delete_head (void)
01885 {
01886   ACE_DLList_Node *temp1 = ACE_DLList_Base::delete_head ();
01887   T *temp2 = (T *) (temp1 ? temp1->item_ : 0);
01888   ACE_DES_FREE (temp1,
01889                 this->allocator_->free,
01890                 ACE_DLList_Node);
01891 
01892   return temp2;
01893 }
01894 
01895 template <class T> T *
01896 ACE_DLList<T>::delete_tail (void)
01897 {
01898   ACE_DLList_Node *temp1 = ACE_DLList_Base::delete_tail ();
01899   T *temp2 = (T *) (temp1 ? temp1->item_ : 0);
01900   ACE_DES_FREE (temp1,
01901                 this->allocator_->free,
01902                 ACE_DLList_Node);
01903   return temp2;
01904 }
01905 
01906 // ****************************************************************
01907 
01908 // Compare this array with <s> for equality.
01909 
01910 template <class T> bool
01911 ACE_Array<T>::operator== (const ACE_Array<T> &s) const
01912 {
01913   if (this == &s)
01914     return true;
01915   else if (this->size () != s.size ())
01916     return false;
01917 
01918   const size_t len = s.size ();
01919   for (size_t slot = 0; slot < len; ++slot)
01920     if ((*this)[slot] != s[slot])
01921       return false;
01922 
01923   return true;
01924 }
01925 
01926 // ****************************************************************
01927 
01928 ACE_END_VERSIONED_NAMESPACE_DECL
01929 
01930 #endif /* ACE_CONTAINERS_T_CPP */

Generated on Tue Feb 2 17:18:39 2010 for ACE by  doxygen 1.4.7