Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Containers_T.cpp
blob1b3b6b144bc27b71c5fa29c9b90475933b614c3c
1 #ifndef ACE_CONTAINERS_T_CPP
2 #define ACE_CONTAINERS_T_CPP
4 #include "ace/Log_Category.h"
5 #include "ace/Malloc_Base.h"
6 #include "ace/OS_Memory.h"
8 #if !defined (ACE_LACKS_PRAGMA_ONCE)
9 # pragma once
10 #endif /* ACE_LACKS_PRAGMA_ONCE */
12 #include "ace/Containers.h"
14 #if !defined (__ACE_INLINE__)
15 #include "ace/Containers_T.inl"
16 #endif /* __ACE_INLINE__ */
18 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
20 ACE_ALLOC_HOOK_DEFINE_Tc(ACE_Bounded_Stack)
22 template <class T> void
23 ACE_Bounded_Stack<T>::dump () const
25 #if defined (ACE_HAS_DUMP)
26 ACE_TRACE ("ACE_Bounded_Stack<T>::dump");
27 #endif /* ACE_HAS_DUMP */
30 template<class T>
31 ACE_Bounded_Stack<T>::ACE_Bounded_Stack (size_t size)
32 : size_ (size),
33 top_ (0)
35 ACE_NEW (this->stack_,
36 T[size]);
37 ACE_TRACE ("ACE_Bounded_Stack<T>::ACE_Bounded_Stack");
40 template<class T>
41 ACE_Bounded_Stack<T>::ACE_Bounded_Stack (const ACE_Bounded_Stack<T> &s)
42 : size_ (s.size_),
43 top_ (s.top_)
45 ACE_NEW (this->stack_,
46 T[s.size_]);
48 ACE_TRACE ("ACE_Bounded_Stack<T>::ACE_Bounded_Stack");
50 for (size_t i = 0; i < this->top_; i++)
51 this->stack_[i] = s.stack_[i];
54 template<class T> void
55 ACE_Bounded_Stack<T>::operator= (const ACE_Bounded_Stack<T> &s)
57 ACE_TRACE ("ACE_Bounded_Stack<T>::operator=");
59 if (&s != this)
61 if (this->size_ < s.size_)
63 delete [] this->stack_;
64 ACE_NEW (this->stack_,
65 T[s.size_]);
66 this->size_ = s.size_;
68 this->top_ = s.top_;
70 for (size_t i = 0; i < this->top_; i++)
71 this->stack_[i] = s.stack_[i];
75 template<class T>
76 ACE_Bounded_Stack<T>::~ACE_Bounded_Stack ()
78 ACE_TRACE ("ACE_Bounded_Stack<T>::~ACE_Bounded_Stack");
79 delete [] this->stack_;
82 // ----------------------------------------
84 ACE_ALLOC_HOOK_DEFINE_Tcs(ACE_Fixed_Stack)
86 template <class T, size_t ACE_SIZE> void
87 ACE_Fixed_Stack<T, ACE_SIZE>::dump () const
89 #if defined (ACE_HAS_DUMP)
90 ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::dump");
91 #endif /* ACE_HAS_DUMP */
94 template<class T, size_t ACE_SIZE>
95 ACE_Fixed_Stack<T, ACE_SIZE>::ACE_Fixed_Stack ()
96 : size_ (ACE_SIZE),
97 top_ (0)
99 ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::ACE_Fixed_Stack");
102 template<class T, size_t ACE_SIZE>
103 ACE_Fixed_Stack<T, ACE_SIZE>::ACE_Fixed_Stack (const ACE_Fixed_Stack<T, ACE_SIZE> &s)
104 : size_ (s.size_),
105 top_ (s.top_)
107 ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::ACE_Fixed_Stack");
108 for (size_t i = 0; i < this->top_; i++)
109 this->stack_[i] = s.stack_[i];
112 template<class T, size_t ACE_SIZE> void
113 ACE_Fixed_Stack<T, ACE_SIZE>::operator= (const ACE_Fixed_Stack<T, ACE_SIZE> &s)
115 ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::operator=");
117 if (&s != this)
119 this->top_ = s.top_;
121 for (size_t i = 0; i < this->top_; i++)
122 this->stack_[i] = s.stack_[i];
126 template<class T, size_t ACE_SIZE>
127 ACE_Fixed_Stack<T, ACE_SIZE>::~ACE_Fixed_Stack ()
129 ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::~ACE_Fixed_Stack");
132 //----------------------------------------
134 ACE_ALLOC_HOOK_DEFINE_Tc(ACE_Unbounded_Stack)
136 template <class T> void
137 ACE_Unbounded_Stack<T>::dump () const
139 #if defined (ACE_HAS_DUMP)
140 // ACE_TRACE ("ACE_Unbounded_Stack<T>::dump");
141 #endif /* ACE_HAS_DUMP */
144 template<class T>
145 ACE_Unbounded_Stack<T>::ACE_Unbounded_Stack (ACE_Allocator *alloc)
146 : head_ (0),
147 cur_size_ (0),
148 allocator_ (alloc)
150 // ACE_TRACE ("ACE_Unbounded_Stack<T>::ACE_Unbounded_Stack");
151 if (this->allocator_ == 0)
152 this->allocator_ = ACE_Allocator::instance ();
154 ACE_NEW_MALLOC (this->head_,
155 (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)),
156 ACE_Node<T>);
157 this->head_->next_ = this->head_;
160 template<class T> void
161 ACE_Unbounded_Stack<T>::delete_all_nodes ()
163 // ACE_TRACE ("ACE_Unbounded_Stack<T>::delete_all_nodes");
165 while (this->is_empty () == 0)
167 ACE_Node<T> *temp = this->head_->next_;
168 this->head_->next_ = temp->next_;
169 ACE_DES_FREE_TEMPLATE (temp, this->allocator_->free,
170 ACE_Node, <T>);
173 this->cur_size_ = 0;
175 ACE_ASSERT (this->head_ == this->head_->next_
176 && this->is_empty ());
179 template<class T> void
180 ACE_Unbounded_Stack<T>::copy_all_nodes (const ACE_Unbounded_Stack<T> &s)
182 // ACE_TRACE ("ACE_Unbounded_Stack<T>::copy_all_nodes");
184 ACE_ASSERT (this->head_ == this->head_->next_);
186 ACE_Node<T> *temp = this->head_;
188 for (ACE_Node<T> *s_temp = s.head_->next_;
189 s_temp != s.head_;
190 s_temp = s_temp->next_)
192 ACE_Node<T> *nptr = temp->next_;
193 ACE_NEW_MALLOC (temp->next_,
194 (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)),
195 ACE_Node<T> (s_temp->item_, nptr));
196 temp = temp->next_;
198 this->cur_size_ = s.cur_size_;
201 template<class T>
202 ACE_Unbounded_Stack<T>::ACE_Unbounded_Stack (const ACE_Unbounded_Stack<T> &s)
203 : head_ (0),
204 cur_size_ (0),
205 allocator_ (s.allocator_)
207 if (this->allocator_ == 0)
208 this->allocator_ = ACE_Allocator::instance ();
210 ACE_NEW_MALLOC (this->head_,
211 (ACE_Node<T> *) this->allocator_->malloc (sizeof (ACE_Node<T>)),
212 ACE_Node<T>);
213 this->head_->next_ = this->head_;
215 // ACE_TRACE ("ACE_Unbounded_Stack<T>::ACE_Unbounded_Stack");
216 this->copy_all_nodes (s);
219 template<class T> void
220 ACE_Unbounded_Stack<T>::operator= (const ACE_Unbounded_Stack<T> &s)
222 // ACE_TRACE ("ACE_Unbounded_Stack<T>::operator=");
224 if (this != &s)
226 this->delete_all_nodes ();
227 this->copy_all_nodes (s);
231 template<class T>
232 ACE_Unbounded_Stack<T>::~ACE_Unbounded_Stack ()
234 // ACE_TRACE ("ACE_Unbounded_Stack<T>::~ACE_Unbounded_Stack");
236 this->delete_all_nodes ();
237 ACE_DES_FREE_TEMPLATE (head_,
238 this->allocator_->free,
239 ACE_Node,
240 <T>);
243 template<class T> int
244 ACE_Unbounded_Stack<T>::push (const T &new_item)
246 // ACE_TRACE ("ACE_Unbounded_Stack<T>::push");
248 ACE_Node<T> *temp = 0;
250 ACE_NEW_MALLOC_RETURN (temp,
251 static_cast<ACE_Node<T> *> (this->allocator_->malloc (sizeof (ACE_Node<T>))),
252 ACE_Node<T> (new_item, this->head_->next_),
253 -1);
254 this->head_->next_ = temp;
255 ++this->cur_size_;
256 return 0;
259 template<class T> int
260 ACE_Unbounded_Stack<T>::pop (T &item)
262 // ACE_TRACE ("ACE_Unbounded_Stack<T>::pop");
264 if (this->is_empty ())
265 return -1;
266 else
268 ACE_Node<T> *temp = this->head_->next_;
269 item = temp->item_;
270 this->head_->next_ = temp->next_;
272 ACE_DES_FREE_TEMPLATE (temp,
273 this->allocator_->free,
274 ACE_Node,
275 <T>);
276 --this->cur_size_;
277 return 0;
281 template <class T> int
282 ACE_Unbounded_Stack<T>::find (const T &item) const
284 // ACE_TRACE ("ACE_Unbounded_Stack<T>::find");
285 // Set <item> into the dummy node.
286 this->head_->item_ = item;
288 ACE_Node<T> *temp = this->head_->next_;
290 // Keep looping until we find the item.
291 while (!(temp->item_ == item))
292 temp = temp->next_;
294 // If we found the dummy node then it's not really there, otherwise,
295 // it is there.
296 return temp == this->head_ ? -1 : 0;
299 template <class T> int
300 ACE_Unbounded_Stack<T>::insert (const T &item)
302 // ACE_TRACE ("ACE_Unbounded_Stack<T>::insert");
304 if (this->find (item) == 0)
305 return 1;
306 else
307 return this->push (item);
310 template <class T> int
311 ACE_Unbounded_Stack<T>::remove (const T &item)
313 // ACE_TRACE ("ACE_Unbounded_Stack<T>::remove");
315 // Insert the item to be founded into the dummy node.
316 this->head_->item_ = item;
318 ACE_Node<T> *curr = this->head_;
320 while (!(curr->next_->item_ == item))
321 curr = curr->next_;
323 if (curr->next_ == this->head_)
324 return -1; // Item was not found.
325 else
327 ACE_Node<T> *temp = curr->next_;
328 // Skip over the node that we're deleting.
329 curr->next_ = temp->next_;
330 --this->cur_size_;
331 ACE_DES_FREE_TEMPLATE (temp,
332 this->allocator_->free,
333 ACE_Node,
334 <T>);
335 return 0;
339 //--------------------------------------------------
340 ACE_ALLOC_HOOK_DEFINE_Tc(ACE_Double_Linked_List_Iterator_Base)
342 template <class T>
343 ACE_Double_Linked_List_Iterator_Base<T>::ACE_Double_Linked_List_Iterator_Base (const ACE_Double_Linked_List<T> &dll)
344 : current_ (0), dllist_ (&dll)
346 // Do nothing
349 template <class T>
350 ACE_Double_Linked_List_Iterator_Base<T>::ACE_Double_Linked_List_Iterator_Base (const ACE_Double_Linked_List_Iterator_Base<T> &iter)
351 : current_ (iter.current_),
352 dllist_ (iter.dllist_)
354 // Do nothing
358 template <class T> T *
359 ACE_Double_Linked_List_Iterator_Base<T>::next () const
361 return this->not_done ();
364 template <class T> int
365 ACE_Double_Linked_List_Iterator_Base<T>::next (T *&ptr) const
367 ptr = this->not_done ();
368 return ptr ? 1 : 0;
372 template <class T> int
373 ACE_Double_Linked_List_Iterator_Base<T>::done () const
375 return this->not_done () ? 0 : 1;
378 template <class T> T &
379 ACE_Double_Linked_List_Iterator_Base<T>::operator* () const
381 return *(this->not_done ());
384 // @@ Is this a valid retasking? Make sure to check with Purify and
385 // whatnot that we're not leaking memory or doing any other screwing things.
386 template <class T> void
387 ACE_Double_Linked_List_Iterator_Base<T>::reset (ACE_Double_Linked_List<T> &dll)
389 current_ = 0;
390 dllist_ = &dll;
393 template <class T> int
394 ACE_Double_Linked_List_Iterator_Base<T>::go_head ()
396 this->current_ = static_cast<T*> (dllist_->head_->next_);
397 return this->current_ ? 1 : 0;
400 template <class T> int
401 ACE_Double_Linked_List_Iterator_Base<T>::go_tail ()
403 this->current_ = static_cast<T*> (dllist_->head_->prev_);
404 return this->current_ ? 1 : 0;
407 template <class T> T *
408 ACE_Double_Linked_List_Iterator_Base<T>::not_done () const
410 if (this->current_ != this->dllist_->head_)
411 return this->current_;
412 else
413 return 0;
416 template <class T> T *
417 ACE_Double_Linked_List_Iterator_Base<T>::do_advance ()
419 if (this->not_done ())
421 this->current_ = static_cast<T*> (this->current_->next_);
422 return this->not_done ();
424 else
425 return 0;
428 template <class T> T *
429 ACE_Double_Linked_List_Iterator_Base<T>::do_retreat ()
431 if (this->not_done ())
433 this->current_ = static_cast<T*> (this->current_->prev_);
434 return this->not_done ();
436 else
437 return 0;
440 template <class T> void
441 ACE_Double_Linked_List_Iterator_Base<T>::dump_i () const
443 ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
444 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("current_ = %x"), this->current_));
445 ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
448 //--------------------------------------------------
449 ACE_ALLOC_HOOK_DEFINE_Tc(ACE_Double_Linked_List_Iterator)
451 template <class T>
452 ACE_Double_Linked_List_Iterator<T>::ACE_Double_Linked_List_Iterator (const ACE_Double_Linked_List<T> &dll)
453 : ACE_Double_Linked_List_Iterator_Base <T> (dll)
455 this->current_ = static_cast<T*> (dll.head_->next_);
456 // Advance current_ out of the null area and onto the first item in
457 // the list
460 template <class T> void
461 ACE_Double_Linked_List_Iterator<T>::reset (ACE_Double_Linked_List<T> &dll)
463 this->ACE_Double_Linked_List_Iterator_Base <T>::reset (dll);
464 this->current_ = static_cast<T*> (dll.head_->next_);
465 // Advance current_ out of the null area and onto the first item in
466 // the list
469 template <class T> int
470 ACE_Double_Linked_List_Iterator<T>::first ()
472 return this->go_head ();
475 template <class T> int
476 ACE_Double_Linked_List_Iterator<T>::advance ()
478 return this->do_advance () ? 1 : 0;
481 template <class T> T*
482 ACE_Double_Linked_List_Iterator<T>::advance_and_remove (bool dont_remove)
484 T* item = 0;
485 if (dont_remove)
486 this->do_advance ();
487 else
489 item = this->next ();
490 this->do_advance ();
491 // It seems dangerous to remove nodes in an iterator, but so it goes...
492 ACE_Double_Linked_List<T> *dllist =
493 const_cast<ACE_Double_Linked_List<T> *> (this->dllist_);
494 dllist->remove (item);
496 return item;
499 template <class T> void
500 ACE_Double_Linked_List_Iterator<T>::dump () const
502 #if defined (ACE_HAS_DUMP)
503 this->dump_i ();
504 #endif /* ACE_HAS_DUMP */
507 // Prefix advance.
509 template <class T>
510 ACE_Double_Linked_List_Iterator<T> &
511 ACE_Double_Linked_List_Iterator<T>::operator++ ()
513 this->do_advance ();
514 return *this;
518 // Postfix advance.
520 template <class T>
521 ACE_Double_Linked_List_Iterator<T>
522 ACE_Double_Linked_List_Iterator<T>::operator++ (int)
524 ACE_Double_Linked_List_Iterator<T> retv (*this);
525 this->do_advance ();
526 return retv;
530 // Prefix reverse.
532 template <class T>
533 ACE_Double_Linked_List_Iterator<T> &
534 ACE_Double_Linked_List_Iterator<T>::operator-- ()
536 this->do_retreat ();
537 return *this;
541 // Postfix reverse.
543 template <class T>
544 ACE_Double_Linked_List_Iterator<T>
545 ACE_Double_Linked_List_Iterator<T>::operator-- (int)
547 ACE_Double_Linked_List_Iterator<T> retv (*this);
548 this->do_retreat ();
549 return retv;
553 //--------------------------------------------------
554 ACE_ALLOC_HOOK_DEFINE_Tc(ACE_Double_Linked_List_Reverse_Iterator)
556 template <class T>
557 ACE_Double_Linked_List_Reverse_Iterator<T>::ACE_Double_Linked_List_Reverse_Iterator (ACE_Double_Linked_List<T> &dll)
558 : ACE_Double_Linked_List_Iterator_Base <T> (dll)
560 this->current_ = static_cast<T*> (dll.head_->prev_);
561 // Advance current_ out of the null area and onto the last item in
562 // the list
565 template <class T> void
566 ACE_Double_Linked_List_Reverse_Iterator<T>::reset (ACE_Double_Linked_List<T> &dll)
568 this->ACE_Double_Linked_List_Iterator_Base <T>::reset (dll);
569 this->current_ = static_cast<T*> (dll.head_->prev_);
570 // Advance current_ out of the null area and onto the last item in
571 // the list
574 template <class T> int
575 ACE_Double_Linked_List_Reverse_Iterator<T>::first ()
577 return this->go_tail ();
580 template <class T> int
581 ACE_Double_Linked_List_Reverse_Iterator<T>::advance ()
583 return this->do_retreat () ? 1 : 0;
586 template <class T> T*
587 ACE_Double_Linked_List_Reverse_Iterator<T>::advance_and_remove (bool dont_remove)
589 T* item = 0;
590 if (dont_remove)
592 this->do_retreat ();
594 else
596 item = this->next ();
597 this->do_retreat ();
598 // It seems dangerous to remove nodes in an iterator, but so it goes...
599 ACE_Double_Linked_List<T> *dllist =
600 const_cast<ACE_Double_Linked_List<T> *> (this->dllist_);
601 dllist->remove (item);
603 return item;
606 template <class T> void
607 ACE_Double_Linked_List_Reverse_Iterator<T>::dump () const
609 #if defined (ACE_HAS_DUMP)
610 this->dump_i ();
611 #endif /* ACE_HAS_DUMP */
614 // Prefix advance.
616 template <class T>
617 ACE_Double_Linked_List_Reverse_Iterator<T> &
618 ACE_Double_Linked_List_Reverse_Iterator<T>::operator++ ()
620 this->do_retreat ();
621 return *this;
625 // Postfix advance.
627 template <class T>
628 ACE_Double_Linked_List_Reverse_Iterator<T>
629 ACE_Double_Linked_List_Reverse_Iterator<T>::operator++ (int)
631 ACE_Double_Linked_List_Reverse_Iterator<T> retv (*this);
632 this->do_retreat ();
633 return retv;
637 // Prefix reverse.
639 template <class T>
640 ACE_Double_Linked_List_Reverse_Iterator<T> &
641 ACE_Double_Linked_List_Reverse_Iterator<T>::operator-- ()
643 this->do_advance ();
644 return *this;
648 // Postfix reverse.
650 template <class T>
651 ACE_Double_Linked_List_Reverse_Iterator<T>
652 ACE_Double_Linked_List_Reverse_Iterator<T>::operator-- (int)
654 ACE_Double_Linked_List_Reverse_Iterator<T> retv (*this);
655 this->do_advance ();
656 return retv;
660 ACE_ALLOC_HOOK_DEFINE_Tc(ACE_Double_Linked_List)
662 template <class T>
663 ACE_Double_Linked_List<T>:: ACE_Double_Linked_List (ACE_Allocator *alloc)
664 : size_ (0), allocator_ (alloc)
666 if (this->allocator_ == 0)
667 this->allocator_ = ACE_Allocator::instance ();
669 ACE_NEW_MALLOC (this->head_,
670 (T *) this->allocator_->malloc (sizeof (T)),
672 this->init_head ();
675 template <class T>
676 ACE_Double_Linked_List<T>::ACE_Double_Linked_List (const ACE_Double_Linked_List<T> &cx)
677 : allocator_ (cx.allocator_)
679 if (this->allocator_ == 0)
680 this->allocator_ = ACE_Allocator::instance ();
682 ACE_NEW_MALLOC (this->head_,
683 (T *) this->allocator_->malloc (sizeof (T)),
685 this->init_head ();
686 this->copy_nodes (cx);
687 this->size_ = cx.size_;
690 template <class T> void
691 ACE_Double_Linked_List<T>::operator= (const ACE_Double_Linked_List<T> &cx)
693 if (this != &cx)
695 this->delete_nodes ();
696 this->copy_nodes (cx);
700 template <class T>
701 ACE_Double_Linked_List<T>::~ACE_Double_Linked_List ()
703 this->delete_nodes ();
705 ACE_DES_FREE (head_,
706 this->allocator_->free,
709 this->head_ = 0;
712 template <class T> int
713 ACE_Double_Linked_List<T>::is_empty () const
715 return this->size () ? 0 : 1;
718 template <class T> int
719 ACE_Double_Linked_List<T>::is_full () const
721 return 0; // We have no bound.
724 template <class T> T *
725 ACE_Double_Linked_List<T>::insert_tail (T *new_item)
727 // Insert it before <head_>, i.e., at tail.
728 this->insert_element (new_item, 1);
729 return new_item;
732 template <class T> T *
733 ACE_Double_Linked_List<T>::insert_head (T *new_item)
735 this->insert_element (new_item); // Insert it after <head_>, i.e., at head.
736 return new_item;
739 template <class T> T *
740 ACE_Double_Linked_List<T>::delete_head ()
742 if (this->is_empty ())
743 return 0;
745 T *temp = static_cast<T *> (this->head_->next_);
746 // Detach it from the list.
747 this->remove_element (temp);
748 return temp;
751 template <class T> T *
752 ACE_Double_Linked_List<T>::delete_tail ()
754 if (this->is_empty ())
755 return 0;
757 T *temp = static_cast <T *> (this->head_->prev_);
758 // Detach it from the list.
759 this->remove_element (temp);
760 return temp;
763 template <class T> void
764 ACE_Double_Linked_List<T>::reset ()
766 this->delete_nodes ();
769 template <class T> int
770 ACE_Double_Linked_List<T>::get (T *&item, size_t slot)
772 ACE_Double_Linked_List_Iterator<T> iter (*this);
774 for (size_t i = 0;
775 i < slot && !iter.done ();
776 i++)
777 iter.advance ();
779 item = iter.next ();
780 return item ? 0 : -1;
783 template <class T> size_t
784 ACE_Double_Linked_List<T>::size () const
786 return this->size_;
789 template <class T> void
790 ACE_Double_Linked_List<T>::dump () const
792 #if defined (ACE_HAS_DUMP)
793 // Dump the state of an object.
794 #endif /* ACE_HAS_DUMP */
797 template <class T> int
798 ACE_Double_Linked_List<T>::remove (T *n)
800 return this->remove_element (n);
803 template <class T> void
804 ACE_Double_Linked_List<T>::delete_nodes ()
806 while (! this->is_empty ())
808 T * temp = static_cast<T*> (this->head_->next_);
809 this->remove_element (temp);
810 ACE_DES_FREE (temp,
811 this->allocator_->free,
816 template <class T> void
817 ACE_Double_Linked_List<T>::copy_nodes (const ACE_Double_Linked_List<T> &c)
819 for (ACE_Double_Linked_List_Iterator<T> iter (c);
820 !iter.done ();
821 iter.advance ())
823 T* temp = 0;
824 ACE_NEW_MALLOC (temp,
825 (T *)this->allocator_->malloc (sizeof (T)),
826 T (*iter.next ()));
827 this->insert_tail (temp);
831 template <class T> void
832 ACE_Double_Linked_List<T>::init_head ()
834 this->head_->next_ = this->head_;
835 this->head_->prev_ = this->head_;
838 template <class T> int
839 ACE_Double_Linked_List<T>::insert_element (T *new_item,
840 int before,
841 T *old_item)
843 if (old_item == 0)
844 old_item = this->head_;
846 if (before)
847 old_item = static_cast<T *> (old_item->prev_);
849 new_item->next_ = old_item->next_;
850 new_item->next_->prev_ = new_item;
851 new_item->prev_ = old_item;
852 old_item->next_ = new_item;
853 ++this->size_;
854 return 0; // Well, what will cause errors here?
857 template <class T> int
858 ACE_Double_Linked_List<T>::remove_element (T *item)
860 // Notice that you have to ensure that item is an element of this
861 // list. We can't do much checking here.
863 if (item == this->head_ || item->next_ == 0
864 || item->prev_ == 0 || this->size () == 0) // Can't remove head
865 return -1;
867 item->prev_->next_ = item->next_;
868 item->next_->prev_ = item->prev_;
869 item->next_ = item->prev_ = 0; // reset pointers to prevent double removal.
870 --this->size_;
871 return 0;
874 //--------------------------------------------------
875 ACE_ALLOC_HOOK_DEFINE_Tcs(ACE_Fixed_Set)
877 template <class T, size_t ACE_SIZE> size_t
878 ACE_Fixed_Set<T, ACE_SIZE>::size () const
880 ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::size");
881 return this->cur_size_;
884 template <class T, size_t ACE_SIZE> void
885 ACE_Fixed_Set<T, ACE_SIZE>::dump () const
887 #if defined (ACE_HAS_DUMP)
888 ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::dump");
889 #endif /* ACE_HAS_DUMP */
892 template <class T, size_t ACE_SIZE>
893 ACE_Fixed_Set<T, ACE_SIZE>::~ACE_Fixed_Set ()
895 ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::~ACE_Fixed_Set");
896 this->cur_size_ = 0;
899 template <class T, size_t ACE_SIZE>
900 ACE_Fixed_Set<T, ACE_SIZE>::ACE_Fixed_Set (const ACE_Fixed_Set<T, ACE_SIZE> &fs)
901 : cur_size_ (fs.cur_size_)
903 ACE_TRACE ("ACE_Fixed_Set<T>::ACE_Fixed_Set");
905 for (size_t i = 0, j = 0; i < fs.max_size_ && j < this->cur_size_; ++i)
906 if (fs.search_structure_[i].is_free_ == 0)
907 this->search_structure_[j++] = fs.search_structure_[i];
910 template <class T, size_t ACE_SIZE> void
911 ACE_Fixed_Set<T, ACE_SIZE>::operator= (const ACE_Fixed_Set<T, ACE_SIZE> &fs)
913 ACE_TRACE ("ACE_Fixed_Set<T>::operator=");
915 if (this != &fs)
917 this->cur_size_ = fs.cur_size_;
919 for (size_t i = 0, j = 0; i < fs.max_size_ && j < this->cur_size_; ++i)
920 if (fs.search_structure_[i].is_free_ == 0)
921 this->search_structure_[j++] = fs.search_structure_[i];
925 template <class T, size_t ACE_SIZE>
926 ACE_Fixed_Set<T, ACE_SIZE>::ACE_Fixed_Set ()
927 : cur_size_ (0),
928 max_size_ (ACE_SIZE)
930 ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::ACE_Fixed_Set");
931 for (size_t i = 0; i < this->max_size_; i++)
932 this->search_structure_[i].is_free_ = 1;
935 template <class T, size_t ACE_SIZE> int
936 ACE_Fixed_Set<T, ACE_SIZE>::find (const T &item) const
938 ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::find");
940 for (size_t i = 0, j = 0; i < this->max_size_ && j < this->cur_size_; ++i)
941 if (this->search_structure_[i].is_free_ == 0)
943 if (this->search_structure_[i].item_ == item)
944 return 0;
945 ++j;
948 return -1;
951 template <class T, size_t ACE_SIZE> int
952 ACE_Fixed_Set<T, ACE_SIZE>::insert (const T &item)
954 ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::insert");
955 ssize_t first_free = -1; // Keep track of first free slot.
956 size_t i;
958 for (i = 0;
959 i < this->max_size_ && first_free == -1;
960 ++i)
962 // First, make sure we don't allow duplicates.
964 if (this->search_structure_[i].is_free_ == 0)
966 if (this->search_structure_[i].item_ == item)
967 return 1;
969 else
970 first_free = static_cast<ssize_t> (i);
972 // If we found a free spot let's reuse it.
974 if (first_free > -1)
976 this->search_structure_[first_free].item_ = item;
977 this->search_structure_[first_free].is_free_ = 0;
978 this->cur_size_++;
979 return 0;
981 else /* No more room! */
983 errno = ENOMEM;
984 return -1;
988 template <class T, size_t ACE_SIZE> int
989 ACE_Fixed_Set<T, ACE_SIZE>::remove (const T &item)
991 ACE_TRACE ("ACE_Fixed_Set<T, ACE_SIZE>::remove");
993 for (size_t i = 0, j = 0;
994 i < this->max_size_ && j < this->cur_size_;
995 ++i)
996 if (this->search_structure_[i].is_free_ == 0)
998 if (this->search_structure_[i].item_ == item)
1000 // Mark this entry as being free.
1001 this->search_structure_[i].is_free_ = 1;
1003 --this->cur_size_;
1004 return 0;
1006 else
1007 ++j;
1010 return -1;
1013 //--------------------------------------------------
1014 ACE_ALLOC_HOOK_DEFINE_Tcs(ACE_Fixed_Set_Iterator_Base)
1016 template <class T, size_t ACE_SIZE> void
1017 ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::dump_i () const
1019 #if defined (ACE_HAS_DUMP)
1020 ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::dump_i");
1021 #endif /* ACE_HAS_DUMP */
1024 template <class T, size_t ACE_SIZE>
1025 ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::ACE_Fixed_Set_Iterator_Base (ACE_Fixed_Set<T, ACE_SIZE> &s)
1026 : s_ (s),
1027 next_ (-1),
1028 iterated_items_ (0)
1030 ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::ACE_Fixed_Set_Iterator_Base");
1031 this->advance ();
1034 template <class T, size_t ACE_SIZE> int
1035 ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::advance ()
1037 ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::advance");
1039 if (this->iterated_items_ < this->s_.cur_size_)
1041 for (++this->next_;
1042 static_cast<size_t> (this->next_) < this->s_.max_size_;
1043 ++this->next_)
1044 if (this->s_.search_structure_[this->next_].is_free_ == 0)
1046 ++this->iterated_items_;
1047 return 1;
1050 else
1051 ++this->next_;
1053 return 0;
1056 template <class T, size_t ACE_SIZE> int
1057 ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::first ()
1059 ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::first");
1061 next_ = -1;
1062 iterated_items_ = 0;
1063 return this->advance ();
1066 template <class T, size_t ACE_SIZE> int
1067 ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::done () const
1069 ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::done");
1071 return ! (this->iterated_items_ < this->s_.cur_size_);
1074 template <class T, size_t ACE_SIZE> int
1075 ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::next_i (T *&item)
1077 ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::next_i");
1079 if (static_cast<size_t> (this->next_) < this->s_.max_size_)
1082 if (this->s_.search_structure_[this->next_].is_free_ == 0)
1084 item = &this->s_.search_structure_[this->next_].item_;
1085 this->advance ();
1086 return 1;
1089 while (this->advance () == 1);
1091 return 0;
1094 //--------------------------------------------------
1095 ACE_ALLOC_HOOK_DEFINE_Tcs(ACE_Fixed_Set_Iterator)
1097 template <class T, size_t ACE_SIZE> void
1098 ACE_Fixed_Set_Iterator<T, ACE_SIZE>::dump () const
1100 #if defined (ACE_HAS_DUMP)
1101 this->dump_i ();
1102 #endif /* ACE_HAS_DUMP */
1105 template <class T, size_t ACE_SIZE>
1106 ACE_Fixed_Set_Iterator<T, ACE_SIZE>::ACE_Fixed_Set_Iterator (ACE_Fixed_Set<T, ACE_SIZE> &s)
1107 : ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE> (s)
1109 ACE_TRACE ("ACE_Fixed_Set_Iterator<T, ACE_SIZE>::ACE_Fixed_Set_Iterator");
1112 template <class T, size_t ACE_SIZE> int
1113 ACE_Fixed_Set_Iterator<T, ACE_SIZE>::next (T *&item)
1115 ACE_TRACE ("ACE_Fixed_Set_Iterator<T, ACE_SIZE>::next");
1116 return this->next_i (item);
1119 template <class T, size_t ACE_SIZE> int
1120 ACE_Fixed_Set_Iterator<T, ACE_SIZE>::remove (T *&item)
1122 ACE_TRACE ("ACE_Fixed_Set_Iterator<T, ACE_SIZE>::remove");
1124 if (this->s_.search_structure_[this->next_].is_free_ == 0)
1126 item = &this->s_.search_structure_[this->next_].item_;
1127 this->s_.remove (*item);
1128 --(this->iterated_items_);
1129 return 1;
1132 return 0;
1135 template <class T, size_t ACE_SIZE> T&
1136 ACE_Fixed_Set_Iterator<T, ACE_SIZE>::operator* ()
1138 T *retv = 0;
1140 if (this->s_.search_structure_[this->next_].is_free_ == 0)
1141 retv = &this->s_.search_structure_[this->next_].item_;
1143 ACE_ASSERT (retv != 0);
1145 return *retv;
1148 //--------------------------------------------------
1149 ACE_ALLOC_HOOK_DEFINE_Tcs(ACE_Fixed_Set_Const_Iterator)
1151 template <class T, size_t ACE_SIZE> void
1152 ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>::dump () const
1154 #if defined (ACE_HAS_DUMP)
1155 this->dump_i ();
1156 #endif /* ACE_HAS_DUMP */
1159 template <class T, size_t ACE_SIZE>
1160 ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>::ACE_Fixed_Set_Const_Iterator (const ACE_Fixed_Set<T, ACE_SIZE> &s)
1161 : ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE> (s)
1163 ACE_TRACE ("ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>::ACE_Fixed_Set_Const_Iterator");
1166 template <class T, size_t ACE_SIZE> int
1167 ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>::next (const T *&item)
1169 ACE_TRACE ("ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>::next");
1171 return this->next_i (item);
1174 template <class T, size_t ACE_SIZE> const T&
1175 ACE_Fixed_Set_Const_Iterator<T, ACE_SIZE>::operator* () const
1177 const T *retv = 0;
1179 if (this->s_.search_structure_[this->next_].is_free_ == 0)
1180 retv = &this->s_.search_structure_[this->next_].item_;
1182 ACE_ASSERT (retv != 0);
1184 return *retv;
1187 //--------------------------------------------------
1188 ACE_ALLOC_HOOK_DEFINE_Tc(ACE_Bounded_Set)
1190 template <class T> void
1191 ACE_Bounded_Set<T>::dump () const
1193 #if defined (ACE_HAS_DUMP)
1194 ACE_TRACE ("ACE_Bounded_Set<T>::dump");
1195 #endif /* ACE_HAS_DUMP */
1198 template <class T>
1199 ACE_Bounded_Set<T>::~ACE_Bounded_Set ()
1201 ACE_TRACE ("ACE_Bounded_Set<T>::~ACE_Bounded_Set");
1202 delete [] this->search_structure_;
1205 template <class T>
1206 ACE_Bounded_Set<T>::ACE_Bounded_Set ()
1207 : cur_size_ (0),
1208 max_size_ (static_cast<size_t> (ACE_Bounded_Set<T>::DEFAULT_SIZE))
1210 ACE_TRACE ("ACE_Bounded_Set<T>::ACE_Bounded_Set");
1212 ACE_NEW (this->search_structure_,
1213 typename ACE_Bounded_Set<T>::Search_Structure[this->max_size_]);
1215 for (size_t i = 0; i < this->max_size_; ++i)
1216 this->search_structure_[i].is_free_ = 1;
1219 template <class T> size_t
1220 ACE_Bounded_Set<T>::size () const
1222 ACE_TRACE ("ACE_Bounded_Set<T>::size");
1223 return this->cur_size_;
1226 template <class T>
1227 ACE_Bounded_Set<T>::ACE_Bounded_Set (const ACE_Bounded_Set<T> &bs)
1228 : cur_size_ (bs.cur_size_),
1229 max_size_ (bs.max_size_)
1231 ACE_TRACE ("ACE_Bounded_Set<T>::ACE_Bounded_Set");
1233 ACE_NEW (this->search_structure_,
1234 typename ACE_Bounded_Set<T>::Search_Structure[this->max_size_]);
1236 for (size_t i = 0; i < this->cur_size_; i++)
1237 this->search_structure_[i] = bs.search_structure_[i];
1240 template <class T> void
1241 ACE_Bounded_Set<T>::operator= (const ACE_Bounded_Set<T> &bs)
1243 ACE_TRACE ("ACE_Bounded_Set<T>::operator=");
1245 if (this != &bs)
1247 if (this->max_size_ < bs.cur_size_)
1249 delete [] this->search_structure_;
1250 ACE_NEW (this->search_structure_,
1251 typename ACE_Bounded_Set<T>::Search_Structure[bs.cur_size_]);
1252 this->max_size_ = bs.cur_size_;
1255 this->cur_size_ = bs.cur_size_;
1257 for (size_t i = 0; i < this->cur_size_; i++)
1258 this->search_structure_[i] = bs.search_structure_[i];
1262 template <class T>
1263 ACE_Bounded_Set<T>::ACE_Bounded_Set (size_t size)
1264 : cur_size_ (0),
1265 max_size_ (size)
1267 ACE_TRACE ("ACE_Bounded_Set<T>::ACE_Bounded_Set");
1268 ACE_NEW (this->search_structure_,
1269 typename ACE_Bounded_Set<T>::Search_Structure[size]);
1271 for (size_t i = 0; i < this->max_size_; i++)
1272 this->search_structure_[i].is_free_ = 1;
1275 template <class T> int
1276 ACE_Bounded_Set<T>::find (const T &item) const
1278 ACE_TRACE ("ACE_Bounded_Set<T>::find");
1280 for (size_t i = 0; i < this->cur_size_; i++)
1281 if (this->search_structure_[i].item_ == item
1282 && this->search_structure_[i].is_free_ == 0)
1283 return 0;
1285 return -1;
1288 template <class T> int
1289 ACE_Bounded_Set<T>::insert (const T &item)
1291 ACE_TRACE ("ACE_Bounded_Set<T>::insert");
1292 int first_free = -1; // Keep track of first free slot.
1293 size_t i;
1295 for (i = 0; i < this->cur_size_; i++)
1296 // First, make sure we don't allow duplicates.
1298 if (this->search_structure_[i].item_ == item
1299 && this->search_structure_[i].is_free_ == 0)
1300 return 1;
1301 else if (this->search_structure_[i].is_free_ && first_free == -1)
1302 first_free = static_cast<int> (i);
1304 if (first_free > -1) // If we found a free spot let's reuse it.
1306 this->search_structure_[first_free].item_ = item;
1307 this->search_structure_[first_free].is_free_ = 0;
1308 return 0;
1310 else if (i < this->max_size_) // Insert at the end of the active portion.
1312 this->search_structure_[i].item_ = item;
1313 this->search_structure_[i].is_free_ = 0;
1314 this->cur_size_++;
1315 return 0;
1317 else /* No more room! */
1319 errno = ENOMEM;
1320 return -1;
1324 template <class T> int
1325 ACE_Bounded_Set<T>::remove (const T &item)
1327 ACE_TRACE ("ACE_Bounded_Set<T>::remove");
1328 for (size_t i = 0; i < this->cur_size_; i++)
1329 if (this->search_structure_[i].item_ == item)
1331 // Mark this entry as being free.
1332 this->search_structure_[i].is_free_ = 1;
1334 // If we just unbound the highest entry, then we need to
1335 // figure out where the next highest active entry is.
1336 if (i + 1 == this->cur_size_)
1338 while (i > 0 && this->search_structure_[--i].is_free_)
1339 continue;
1341 if (i == 0 && this->search_structure_[i].is_free_)
1342 this->cur_size_ = 0;
1343 else
1344 this->cur_size_ = i + 1;
1346 return 0;
1349 return -1;
1352 ACE_ALLOC_HOOK_DEFINE_Tc(ACE_Bounded_Set_Iterator)
1354 template <class T> void
1355 ACE_Bounded_Set_Iterator<T>::dump () const
1357 #if defined (ACE_HAS_DUMP)
1358 ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::dump");
1359 #endif /* ACE_HAS_DUMP */
1362 template <class T>
1363 ACE_Bounded_Set_Iterator<T>::ACE_Bounded_Set_Iterator (ACE_Bounded_Set<T> &s)
1364 : s_ (s),
1365 next_ (-1)
1367 ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::ACE_Bounded_Set_Iterator");
1368 this->advance ();
1371 template <class T> int
1372 ACE_Bounded_Set_Iterator<T>::advance ()
1374 ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::advance");
1376 for (++this->next_;
1377 static_cast<size_t> (this->next_) < this->s_.cur_size_
1378 && this->s_.search_structure_[this->next_].is_free_;
1379 ++this->next_)
1380 continue;
1382 return static_cast<size_t> (this->next_) < this->s_.cur_size_;
1385 template <class T> int
1386 ACE_Bounded_Set_Iterator<T>::first ()
1388 ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::first");
1390 next_ = -1;
1391 return this->advance ();
1394 template <class T> int
1395 ACE_Bounded_Set_Iterator<T>::done () const
1397 ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::done");
1399 return static_cast<size_t> (this->next_) >=
1400 this->s_.cur_size_;
1403 template <class T> int
1404 ACE_Bounded_Set_Iterator<T>::next (T *&item)
1406 ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::next");
1407 if (static_cast<size_t> (this->next_) < this->s_.cur_size_)
1409 item = &this->s_.search_structure_[this->next_].item_;
1410 return 1;
1412 else
1413 return 0;
1416 ACE_ALLOC_HOOK_DEFINE_Tc(ACE_DNode)
1418 template <class T>
1419 ACE_DNode<T>::ACE_DNode (const T &i, ACE_DNode<T> *n, ACE_DNode<T> *p)
1420 : next_ (n), prev_ (p), item_ (i)
1424 template <class T>
1425 ACE_DNode<T>::~ACE_DNode ()
1429 // ****************************************************************
1431 template <class T> void
1432 ACE_Unbounded_Stack_Iterator<T>::dump () const
1434 #if defined (ACE_HAS_DUMP)
1435 // ACE_TRACE ("ACE_Unbounded_Stack_Iterator<T>::dump");
1436 #endif /* ACE_HAS_DUMP */
1439 template <class T>
1440 ACE_Unbounded_Stack_Iterator<T>::ACE_Unbounded_Stack_Iterator (ACE_Unbounded_Stack<T> &q)
1441 : current_ (q.head_->next_),
1442 stack_ (q)
1444 // ACE_TRACE ("ACE_Unbounded_Stack_Iterator<T>::ACE_Unbounded_Stack_Iterator");
1447 template <class T> int
1448 ACE_Unbounded_Stack_Iterator<T>::advance ()
1450 // ACE_TRACE ("ACE_Unbounded_Stack_Iterator<T>::advance");
1451 this->current_ = this->current_->next_;
1452 return this->current_ != this->stack_.head_;
1455 template <class T> int
1456 ACE_Unbounded_Stack_Iterator<T>::first ()
1458 // ACE_TRACE ("ACE_Unbounded_Stack_Iterator<T>::first");
1459 this->current_ = this->stack_.head_->next_;
1460 return this->current_ != this->stack_.head_;
1463 template <class T> int
1464 ACE_Unbounded_Stack_Iterator<T>::done () const
1466 ACE_TRACE ("ACE_Unbounded_Stack_Iterator<T>::done");
1468 return this->current_ == this->stack_.head_;
1471 template <class T> int
1472 ACE_Unbounded_Stack_Iterator<T>::next (T *&item)
1474 // ACE_TRACE ("ACE_Unbounded_Stack_Iterator<T>::next");
1475 if (this->current_ == this->stack_.head_)
1476 return 0;
1477 else
1479 item = &this->current_->item_;
1480 return 1;
1485 ACE_ALLOC_HOOK_DEFINE_Tc(ACE_Ordered_MultiSet)
1487 template <class T>
1488 ACE_Ordered_MultiSet<T>::ACE_Ordered_MultiSet (ACE_Allocator *alloc)
1489 : head_ (0)
1490 , tail_ (0)
1491 , cur_size_ (0)
1492 , allocator_ (alloc)
1494 // ACE_TRACE ("ACE_Ordered_MultiSet<T>::ACE_Ordered_MultiSet");
1496 if (this->allocator_ == 0)
1497 this->allocator_ = ACE_Allocator::instance ();
1500 template <class T>
1501 ACE_Ordered_MultiSet<T>::ACE_Ordered_MultiSet (const ACE_Ordered_MultiSet<T> &us)
1502 : head_ (0)
1503 , tail_ (0)
1504 , cur_size_ (0)
1505 , allocator_ (us.allocator_)
1507 ACE_TRACE ("ACE_Ordered_MultiSet<T>::ACE_Ordered_MultiSet");
1509 if (this->allocator_ == 0)
1510 this->allocator_ = ACE_Allocator::instance ();
1512 this->copy_nodes (us);
1515 template <class T>
1516 ACE_Ordered_MultiSet<T>::~ACE_Ordered_MultiSet ()
1518 // ACE_TRACE ("ACE_Ordered_MultiSet<T>::~ACE_Ordered_MultiSet");
1520 this->delete_nodes ();
1524 template <class T> void
1525 ACE_Ordered_MultiSet<T>::operator= (const ACE_Ordered_MultiSet<T> &us)
1527 ACE_TRACE ("ACE_Ordered_MultiSet<T>::operator=");
1529 if (this != &us)
1531 this->delete_nodes ();
1532 this->copy_nodes (us);
1537 template <class T> int
1538 ACE_Ordered_MultiSet<T>::insert (const T &item)
1540 // ACE_TRACE ("ACE_Ordered_MultiSet<T>::insert");
1542 return this->insert_from (item, this->head_, 0);
1545 template <class T> int
1546 ACE_Ordered_MultiSet<T>::insert (const T &new_item,
1547 ITERATOR &iter)
1549 // ACE_TRACE ("ACE_Ordered_MultiSet<T>::insert using iterator");
1551 return this->insert_from (new_item, iter.current_, &iter.current_);
1554 template <class T> int
1555 ACE_Ordered_MultiSet<T>::remove (const T &item)
1557 // ACE_TRACE ("ACE_Ordered_MultiSet<T>::remove");
1559 ACE_DNode<T> *node = 0;
1561 int result = locate (item, 0, node);
1563 // if we found the node, remove from list and free it
1564 if (node && (result == 0))
1566 if (node->prev_)
1567 node->prev_->next_ = node->next_;
1568 else
1569 head_ = node->next_;
1571 if (node->next_)
1572 node->next_->prev_ = node->prev_;
1573 else
1574 tail_ = node->prev_;
1576 --this->cur_size_;
1578 ACE_DES_FREE_TEMPLATE (node,
1579 this->allocator_->free,
1580 ACE_DNode,
1581 <T>);
1582 return 0;
1585 return -1;
1588 template <class T> int
1589 ACE_Ordered_MultiSet<T>::find (const T &item,
1590 ITERATOR &iter) const
1592 // search an occurrence of item, using iterator's current position as a hint
1593 ACE_DNode<T> *node = iter.current_;
1594 int const result = locate (item, node, node);
1596 // if we found the node, update the iterator and indicate success
1597 if (node && (result == 0))
1599 iter.current_ = node;
1600 return 0;
1603 return -1;
1607 template <class T> void
1608 ACE_Ordered_MultiSet<T>::reset ()
1610 ACE_TRACE ("reset");
1612 this->delete_nodes ();
1615 template <class T> void
1616 ACE_Ordered_MultiSet<T>::dump () const
1618 #if defined (ACE_HAS_DUMP)
1619 // ACE_TRACE ("ACE_Ordered_MultiSet<T>::dump");
1621 // ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
1622 // ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nhead_ = %u"), this->head_));
1623 // ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nhead_->next_ = %u"), this->head_->next_));
1624 // ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\ncur_size_ = %d\n"), this->cur_size_));
1626 // T *item = 0;
1627 // size_t count = 1;
1629 // for (ACE_Ordered_MultiSet_Iterator<T> iter (*(ACE_Ordered_MultiSet<T> *) this);
1630 // iter.next (item) != 0;
1631 // iter.advance ())
1632 // ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("count = %d\n"), count++));
1634 // ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
1635 #endif /* ACE_HAS_DUMP */
1638 template <class T> int
1639 ACE_Ordered_MultiSet<T>::insert_from (const T &item, ACE_DNode<T> *position,
1640 ACE_DNode<T> **new_position)
1642 // ACE_TRACE ("ACE_Ordered_MultiSet<T>::insert_from");
1644 // create a new node
1645 ACE_DNode<T> *temp = 0;
1646 ACE_NEW_MALLOC_RETURN (temp,
1647 static_cast<ACE_DNode<T>*> (this->allocator_->malloc (sizeof (ACE_DNode<T>))),
1648 ACE_DNode<T> (item),
1649 -1);
1650 // obtain approximate location of the node
1651 int result = locate (item, position, position);
1653 // if there are nodes in the multiset
1654 if (position)
1656 switch (result)
1658 // insert after the approximate position
1659 case -1:
1661 // if there is a following node
1662 if (position->next_)
1664 // link up with the following node
1665 position->next_->prev_ = temp;
1666 temp->next_ = position->next_;
1668 else
1669 // appending to the end of the set
1670 tail_ = temp;
1672 // link up with the preceeding node
1673 temp->prev_ = position;
1674 position->next_ = temp;
1676 break;
1678 // insert before the position
1679 case 0:
1680 case 1:
1682 // if there is a preceeding node
1683 if (position->prev_)
1685 // link up with the preceeding node
1686 position->prev_->next_ = temp;
1687 temp->prev_ = position->prev_;
1689 else
1690 // prepending to the start of the set
1691 head_ = temp;
1693 // link up with the preceeding node
1694 temp->next_ = position;
1695 position->prev_ = temp;
1697 break;
1699 default:
1700 return -1;
1703 else
1705 // point the head and tail to the new node.
1706 this->head_ = temp;
1707 this->tail_ = temp;
1710 ++this->cur_size_;
1711 if (new_position)
1712 *new_position = temp;
1714 return 0;
1717 template <class T> int
1718 ACE_Ordered_MultiSet<T>::locate (const T &item, ACE_DNode<T> *start_position,
1719 ACE_DNode<T> *&new_position) const
1721 if (! start_position)
1722 start_position = this->head_;
1724 // If starting before the item, move forward until at or just before
1725 // item.
1726 while (start_position && start_position->item_ < item &&
1727 start_position->next_)
1728 start_position = start_position->next_;
1730 // If starting after the item, move back until at or just after item
1731 while (start_position && item < start_position->item_ &&
1732 start_position->prev_)
1733 start_position = start_position->prev_;
1735 // Save the (approximate) location in the passed pointer.
1736 new_position = start_position;
1738 // Show the location is after (1), before (-1) , or at (0) the item
1739 if (!new_position)
1740 return 1;
1741 else if (item < new_position->item_)
1742 return 1;
1743 else if (new_position->item_ < item)
1744 return -1;
1745 else
1746 return 0;
1749 // Looks for first occurrence of <item> in the ordered set, using the
1750 // passed starting position as a hint: if there is such an instance,
1751 // it updates the new_position pointer to point to one such node and
1752 // returns 0; if there is no such node, then if there is a node before
1753 // where the item would have been, it updates the new_position pointer
1754 // to point to this node and returns -1; if there is no such node,
1755 // then if there is a node after where the item would have been, it
1756 // updates the new_position pointer to point to this node (or 0 if
1757 // there is no such node) and returns 1;
1759 template <class T> void
1760 ACE_Ordered_MultiSet<T>::copy_nodes (const ACE_Ordered_MultiSet<T> &us)
1762 ACE_DNode<T> *insertion_point = this->head_;
1764 for (ACE_DNode<T> *curr = us.head_;
1765 curr != 0;
1766 curr = curr->next_)
1767 this->insert_from (curr->item_, insertion_point, &insertion_point);
1770 template <class T> void
1771 ACE_Ordered_MultiSet<T>::delete_nodes ()
1773 // iterate through list, deleting nodes
1774 for (ACE_DNode<T> *curr = this->head_;
1775 curr != 0;
1778 ACE_DNode<T> *temp = curr;
1779 curr = curr->next_;
1780 ACE_DES_FREE_TEMPLATE (temp,
1781 this->allocator_->free,
1782 ACE_DNode,
1783 <T>);
1786 this->head_ = 0;
1787 this->tail_ = 0;
1788 this->cur_size_ = 0;
1791 ACE_ALLOC_HOOK_DEFINE_Tc(ACE_Ordered_MultiSet_Iterator)
1793 template <class T>
1794 ACE_Ordered_MultiSet_Iterator<T>::ACE_Ordered_MultiSet_Iterator (ACE_Ordered_MultiSet<T> &s)
1795 : current_ (s.head_),
1796 set_ (s)
1798 // ACE_TRACE ("ACE_Ordered_MultiSet_Iterator<T>::ACE_Ordered_MultiSet_Iterator");
1801 template <class T> int
1802 ACE_Ordered_MultiSet_Iterator<T>::next (T *&item) const
1804 // ACE_TRACE ("ACE_Ordered_MultiSet_Iterator<T>::next");
1805 if (this->current_)
1807 item = &this->current_->item_;
1808 return 1;
1811 return 0;
1814 template <class T> T&
1815 ACE_Ordered_MultiSet_Iterator<T>::operator* ()
1817 //ACE_TRACE ("ACE_Ordered_MultiSet_Iterator<T>::operator*");
1818 T *retv = 0;
1820 int const result = this->next (retv);
1821 ACE_ASSERT (result != 0);
1822 ACE_UNUSED_ARG (result);
1824 return *retv;
1827 template <class T> T *
1828 ACE_DLList<T>::insert_tail (T *new_item)
1830 ACE_DLList_Node *temp1 = 0;
1831 ACE_NEW_MALLOC_RETURN (temp1,
1832 static_cast<ACE_DLList_Node *> (this->allocator_->malloc (sizeof (ACE_DLList_Node))),
1833 ACE_DLList_Node (new_item),
1835 ACE_DLList_Node *temp2 = ACE_DLList_Base::insert_tail (temp1);
1836 return (T *) (temp2 ? temp2->item_ : 0);
1839 template <class T> T *
1840 ACE_DLList<T>::insert_head (T *new_item)
1842 ACE_DLList_Node *temp1 = 0;
1843 ACE_NEW_MALLOC_RETURN (temp1,
1844 (ACE_DLList_Node *) this->allocator_->malloc (sizeof (ACE_DLList_Node)),
1845 ACE_DLList_Node (new_item), 0);
1846 ACE_DLList_Node *temp2 = ACE_DLList_Base::insert_head (temp1);
1847 return (T *) (temp2 ? temp2->item_ : 0);
1850 template <class T> T *
1851 ACE_DLList<T>::delete_head ()
1853 ACE_DLList_Node *temp1 = ACE_DLList_Base::delete_head ();
1854 T *temp2 = (T *) (temp1 ? temp1->item_ : 0);
1855 ACE_DES_FREE (temp1,
1856 this->allocator_->free,
1857 ACE_DLList_Node);
1859 return temp2;
1862 template <class T> T *
1863 ACE_DLList<T>::delete_tail ()
1865 ACE_DLList_Node *temp1 = ACE_DLList_Base::delete_tail ();
1866 T *temp2 = (T *) (temp1 ? temp1->item_ : 0);
1867 ACE_DES_FREE (temp1,
1868 this->allocator_->free,
1869 ACE_DLList_Node);
1870 return temp2;
1873 // ****************************************************************
1875 // Compare this array with <s> for equality.
1877 template <class T> bool
1878 ACE_Array<T>::operator== (const ACE_Array<T> &s) const
1880 if (this == &s)
1881 return true;
1882 else if (this->size () != s.size ())
1883 return false;
1885 const size_t len = s.size ();
1886 for (size_t slot = 0; slot < len; ++slot)
1887 if ((*this)[slot] != s[slot])
1888 return false;
1890 return true;
1893 // ****************************************************************
1895 ACE_END_VERSIONED_NAMESPACE_DECL
1897 #endif /* ACE_CONTAINERS_T_CPP */