Merge branch 'master' into jwi-bcc64xsingletonwarning
[ACE_TAO.git] / ACE / examples / Smart_Pointers / Widget_Impl.cpp
blobe62f3ccdd1cb01f589544d9783a97d37df564f0c
1 /* -*- C++ -*- */
2 //=============================================================================
3 /**
4 * @file Widget_Impl.cpp
6 * @author Christopher Kohlhoff <chris@kohlhoff.com>
7 */
8 //=============================================================================
10 #include "Widget_Impl.h"
11 #include "ace/Log_Msg.h"
13 Widget_Impl::Widget_Impl ()
15 ACE_DEBUG ((LM_DEBUG, "Widget_Impl constructor\n"));
18 Widget_Impl::~Widget_Impl ()
20 ACE_DEBUG ((LM_DEBUG, "Widget_Impl destructor\n"));
23 void Widget_Impl::add_part (Widget_Part *part)
25 // Take ownership of the part object using a ACE_Refcounted_Auto_Ptr.
26 ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> new_part (part);
28 parts_.enqueue_tail (new_part);
31 Widget_Part *Widget_Impl::remove_part ()
33 ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> removed_part;
34 if (parts_.dequeue_head (removed_part) == -1)
35 return 0;
37 // Ownership of the part object is released and transferred to the caller.
38 return removed_part.release();
41 void Widget_Impl::list_parts ()
43 ACE_Unbounded_Queue_Iterator<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> > iter (parts_);
44 ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> *current_part;
45 while (iter.next (current_part))
47 (*current_part)->print_info ();
48 iter.advance ();