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)
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 */
31 ACE_Bounded_Stack
<T
>::ACE_Bounded_Stack (size_t size
)
35 ACE_NEW (this->stack_
,
37 ACE_TRACE ("ACE_Bounded_Stack<T>::ACE_Bounded_Stack");
41 ACE_Bounded_Stack
<T
>::ACE_Bounded_Stack (const ACE_Bounded_Stack
<T
> &s
)
45 ACE_NEW (this->stack_
,
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=");
61 if (this->size_
< s
.size_
)
63 delete [] this->stack_
;
64 ACE_NEW (this->stack_
,
66 this->size_
= s
.size_
;
70 for (size_t i
= 0; i
< this->top_
; i
++)
71 this->stack_
[i
] = s
.stack_
[i
];
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 ()
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
)
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=");
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 */
145 ACE_Unbounded_Stack
<T
>::ACE_Unbounded_Stack (ACE_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
>)),
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
,
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_
;
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
));
198 this->cur_size_
= s
.cur_size_
;
202 ACE_Unbounded_Stack
<T
>::ACE_Unbounded_Stack (const ACE_Unbounded_Stack
<T
> &s
)
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
>)),
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=");
226 this->delete_all_nodes ();
227 this->copy_all_nodes (s
);
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
,
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_
),
254 this->head_
->next_
= temp
;
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 ())
268 ACE_Node
<T
> *temp
= this->head_
->next_
;
270 this->head_
->next_
= temp
->next_
;
272 ACE_DES_FREE_TEMPLATE (temp
,
273 this->allocator_
->free
,
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
))
294 // If we found the dummy node then it's not really there, otherwise,
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)
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
))
323 if (curr
->next_
== this->head_
)
324 return -1; // Item was not found.
327 ACE_Node
<T
> *temp
= curr
->next_
;
328 // Skip over the node that we're deleting.
329 curr
->next_
= temp
->next_
;
331 ACE_DES_FREE_TEMPLATE (temp
,
332 this->allocator_
->free
,
339 //--------------------------------------------------
340 ACE_ALLOC_HOOK_DEFINE_Tc(ACE_Double_Linked_List_Iterator_Base
)
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
)
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_
)
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 ();
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
)
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_
;
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 ();
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 ();
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
)
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
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
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
)
489 item
= this->next ();
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
);
499 template <class T
> void
500 ACE_Double_Linked_List_Iterator
<T
>::dump () const
502 #if defined (ACE_HAS_DUMP)
504 #endif /* ACE_HAS_DUMP */
510 ACE_Double_Linked_List_Iterator
<T
> &
511 ACE_Double_Linked_List_Iterator
<T
>::operator++ ()
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);
533 ACE_Double_Linked_List_Iterator
<T
> &
534 ACE_Double_Linked_List_Iterator
<T
>::operator-- ()
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);
553 //--------------------------------------------------
554 ACE_ALLOC_HOOK_DEFINE_Tc(ACE_Double_Linked_List_Reverse_Iterator
)
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
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
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
)
596 item
= this->next ();
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
);
606 template <class T
> void
607 ACE_Double_Linked_List_Reverse_Iterator
<T
>::dump () const
609 #if defined (ACE_HAS_DUMP)
611 #endif /* ACE_HAS_DUMP */
617 ACE_Double_Linked_List_Reverse_Iterator
<T
> &
618 ACE_Double_Linked_List_Reverse_Iterator
<T
>::operator++ ()
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);
640 ACE_Double_Linked_List_Reverse_Iterator
<T
> &
641 ACE_Double_Linked_List_Reverse_Iterator
<T
>::operator-- ()
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);
660 ACE_ALLOC_HOOK_DEFINE_Tc(ACE_Double_Linked_List
)
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
)),
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
)),
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
)
695 this->delete_nodes ();
696 this->copy_nodes (cx
);
701 ACE_Double_Linked_List
<T
>::~ACE_Double_Linked_List ()
703 this->delete_nodes ();
706 this->allocator_
->free
,
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);
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.
739 template <class T
> T
*
740 ACE_Double_Linked_List
<T
>::delete_head ()
742 if (this->is_empty ())
745 T
*temp
= static_cast<T
*> (this->head_
->next_
);
746 // Detach it from the list.
747 this->remove_element (temp
);
751 template <class T
> T
*
752 ACE_Double_Linked_List
<T
>::delete_tail ()
754 if (this->is_empty ())
757 T
*temp
= static_cast <T
*> (this->head_
->prev_
);
758 // Detach it from the list.
759 this->remove_element (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);
775 i
< slot
&& !iter
.done ();
780 return item
? 0 : -1;
783 template <class T
> size_t
784 ACE_Double_Linked_List
<T
>::size () const
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
);
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
);
824 ACE_NEW_MALLOC (temp
,
825 (T
*)this->allocator_
->malloc (sizeof (T
)),
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
,
844 old_item
= this->head_
;
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
;
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
867 item
->prev_
->next_
= item
->next_
;
868 item
->next_
->prev_
= item
->prev_
;
869 item
->next_
= item
->prev_
= 0; // reset pointers to prevent double removal.
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");
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=");
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 ()
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
)
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.
959 i
< this->max_size_
&& first_free
== -1;
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
)
970 first_free
= static_cast<ssize_t
> (i
);
972 // If we found a free spot let's reuse it.
976 this->search_structure_
[first_free
].item_
= item
;
977 this->search_structure_
[first_free
].is_free_
= 0;
981 else /* No more room! */
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_
;
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;
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
)
1030 ACE_TRACE ("ACE_Fixed_Set_Iterator_Base<T, ACE_SIZE>::ACE_Fixed_Set_Iterator_Base");
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_
)
1042 static_cast<size_t> (this->next_
) < this->s_
.max_size_
;
1044 if (this->s_
.search_structure_
[this->next_
].is_free_
== 0)
1046 ++this->iterated_items_
;
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");
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_
;
1089 while (this->advance () == 1);
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)
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_
);
1135 template <class T
, size_t ACE_SIZE
> T
&
1136 ACE_Fixed_Set_Iterator
<T
, ACE_SIZE
>::operator* ()
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);
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)
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
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);
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 */
1199 ACE_Bounded_Set
<T
>::~ACE_Bounded_Set ()
1201 ACE_TRACE ("ACE_Bounded_Set<T>::~ACE_Bounded_Set");
1202 delete [] this->search_structure_
;
1206 ACE_Bounded_Set
<T
>::ACE_Bounded_Set ()
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_
;
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=");
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
];
1263 ACE_Bounded_Set
<T
>::ACE_Bounded_Set (size_t 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)
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.
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)
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;
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;
1317 else /* No more room! */
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_
)
1341 if (i
== 0 && this->search_structure_
[i
].is_free_
)
1342 this->cur_size_
= 0;
1344 this->cur_size_
= i
+ 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 */
1363 ACE_Bounded_Set_Iterator
<T
>::ACE_Bounded_Set_Iterator (ACE_Bounded_Set
<T
> &s
)
1367 ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::ACE_Bounded_Set_Iterator");
1371 template <class T
> int
1372 ACE_Bounded_Set_Iterator
<T
>::advance ()
1374 ACE_TRACE ("ACE_Bounded_Set_Iterator<T>::advance");
1377 static_cast<size_t> (this->next_
) < this->s_
.cur_size_
1378 && this->s_
.search_structure_
[this->next_
].is_free_
;
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");
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_
) >=
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_
;
1416 ACE_ALLOC_HOOK_DEFINE_Tc(ACE_DNode
)
1419 ACE_DNode
<T
>::ACE_DNode (const T
&i
, ACE_DNode
<T
> *n
, ACE_DNode
<T
> *p
)
1420 : next_ (n
), prev_ (p
), item_ (i
)
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 */
1440 ACE_Unbounded_Stack_Iterator
<T
>::ACE_Unbounded_Stack_Iterator (ACE_Unbounded_Stack
<T
> &q
)
1441 : current_ (q
.head_
->next_
),
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_
)
1479 item
= &this->current_
->item_
;
1485 ACE_ALLOC_HOOK_DEFINE_Tc(ACE_Ordered_MultiSet
)
1488 ACE_Ordered_MultiSet
<T
>::ACE_Ordered_MultiSet (ACE_Allocator
*alloc
)
1492 , allocator_ (alloc
)
1494 // ACE_TRACE ("ACE_Ordered_MultiSet<T>::ACE_Ordered_MultiSet");
1496 if (this->allocator_
== 0)
1497 this->allocator_
= ACE_Allocator::instance ();
1501 ACE_Ordered_MultiSet
<T
>::ACE_Ordered_MultiSet (const ACE_Ordered_MultiSet
<T
> &us
)
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
);
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=");
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
,
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))
1567 node
->prev_
->next_
= node
->next_
;
1569 head_
= node
->next_
;
1572 node
->next_
->prev_
= node
->prev_
;
1574 tail_
= node
->prev_
;
1578 ACE_DES_FREE_TEMPLATE (node
,
1579 this->allocator_
->free
,
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
;
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_));
1627 // size_t count = 1;
1629 // for (ACE_Ordered_MultiSet_Iterator<T> iter (*(ACE_Ordered_MultiSet<T> *) this);
1630 // iter.next (item) != 0;
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
),
1650 // obtain approximate location of the node
1651 int result
= locate (item
, position
, position
);
1653 // if there are nodes in the multiset
1658 // insert after the approximate position
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_
;
1669 // appending to the end of the set
1672 // link up with the preceeding node
1673 temp
->prev_
= position
;
1674 position
->next_
= temp
;
1678 // insert before the position
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_
;
1690 // prepending to the start of the set
1693 // link up with the preceeding node
1694 temp
->next_
= position
;
1695 position
->prev_
= temp
;
1705 // point the head and tail to the new node.
1712 *new_position
= temp
;
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
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
1741 else if (item
< new_position
->item_
)
1743 else if (new_position
->item_
< item
)
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_
;
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_
;
1778 ACE_DNode
<T
> *temp
= curr
;
1780 ACE_DES_FREE_TEMPLATE (temp
,
1781 this->allocator_
->free
,
1788 this->cur_size_
= 0;
1791 ACE_ALLOC_HOOK_DEFINE_Tc(ACE_Ordered_MultiSet_Iterator
)
1794 ACE_Ordered_MultiSet_Iterator
<T
>::ACE_Ordered_MultiSet_Iterator (ACE_Ordered_MultiSet
<T
> &s
)
1795 : current_ (s
.head_
),
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");
1807 item
= &this->current_
->item_
;
1814 template <class T
> T
&
1815 ACE_Ordered_MultiSet_Iterator
<T
>::operator* ()
1817 //ACE_TRACE ("ACE_Ordered_MultiSet_Iterator<T>::operator*");
1820 int const result
= this->next (retv
);
1821 ACE_ASSERT (result
!= 0);
1822 ACE_UNUSED_ARG (result
);
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
,
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
,
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
1882 else if (this->size () != s
.size ())
1885 const size_t len
= s
.size ();
1886 for (size_t slot
= 0; slot
< len
; ++slot
)
1887 if ((*this)[slot
] != s
[slot
])
1893 // ****************************************************************
1895 ACE_END_VERSIONED_NAMESPACE_DECL
1897 #endif /* ACE_CONTAINERS_T_CPP */