Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Containers_T.cpp

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

Generated on Mon Jun 16 11:19:29 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002