2 //=============================================================================
4 * @file Gadget_Part_Impl.cpp
6 * @author Christopher Kohlhoff <chris@kohlhoff.com>
8 //=============================================================================
10 #include "Gadget_Part_Impl.h"
12 #include "ace/Log_Msg.h"
13 #include "ace/Unbounded_Queue.h"
15 Gadget_Part_Impl::Gadget_Part_Impl (Gadget_ptr owner
,
19 name_ (ACE::strnew (name
)),
22 ACE_DEBUG ((LM_DEBUG
, "Gadget_Part_Impl constructor\n"));
25 Gadget_Part_Impl::~Gadget_Part_Impl ()
27 ACE_DEBUG ((LM_DEBUG
, "Gadget_Part_Impl destructor\n"));
32 void Gadget_Part_Impl::print_info ()
34 ACE_DEBUG ((LM_INFO
, "Gadget part: name=%s size=%d\n", name_
, size_
));
37 void Gadget_Part_Impl::remove_from_owner ()
39 // Need to guarantee the existence of the owner for the duration of this call.
40 Gadget_var owner
= owner_
;
42 // Weak pointers are automatically set to NULL if the object they refer to
43 // is deleted. We can use this fact to check that our owner still exists.
47 // Take all existing parts from the owner and build up a temporary list. If
48 // we find ourselves then we won't add ourselves to the list.
49 ACE_Unbounded_Queue
<Gadget_Part_var
> parts
;
52 Gadget_Part_var part
= owner
->remove_part ();
56 parts
.enqueue_tail (part
);
59 // Add the remaining parts back to the gadget.
60 while (!parts
.is_empty ())
63 parts
.dequeue_head (part
);
64 owner
->add_part (part
);