Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / Smart_Pointers / Widget_Impl.h
blob220c5f752fc67ab5ab96bc229dbe3a33957a1ac2
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Widget_Impl.h
7 * @author Christopher Kohlhoff <chris@kohlhoff.com>
8 */
9 //=============================================================================
11 #ifndef WIDGET_IMPL_H
12 #define WIDGET_IMPL_H
14 #include "Widget.h"
15 #include "Widget_Part.h"
17 #include "ace/Unbounded_Queue.h"
18 #include "ace/Refcounted_Auto_Ptr.h"
19 #include "ace/Synch_Traits.h"
20 #include "ace/Thread_Mutex.h"
22 /**
23 * @class Widget_Impl
25 * @brief An implementation of the Widget interface.
27 class Widget_Impl : public Widget
29 public:
30 /// Constructor.
31 Widget_Impl ();
33 /// Destructor.
34 virtual ~Widget_Impl ();
36 /// Add a new part to the widget. The widget takes ownership of the part
37 /// object.
38 virtual void add_part (Widget_Part *part);
40 /// Remove a random part from the widget. Ownership of the part is returned
41 /// to the caller.
42 virtual Widget_Part *remove_part ();
44 /// Ask the widget to print information about the parts that it contains.
45 virtual void list_parts ();
47 private:
48 /// The parts which make up this widget. The set actually contains instances
49 /// of ACE_Refcounted_Auto_Ptr to automatically manage the lifetimes of the
50 /// constituent parts.
51 ///
52 /// Some things to note about the choice of ACE_Refcounted_Auto_Ptr:
53 /// - We cannot use auto_ptr to manage the objects, since auto_ptr does not
54 /// support the copying and assignment semantics necessary for storage in
55 /// a container.
56 /// - The ACE_Strong_Bound_Ptr reference counted pointer could be used to
57 /// store objects in a container, however (for reasons of safety) it
58 /// provides no way to release ownership of the object from the smart
59 /// pointer. We need to be able to release ownership to implement the
60 /// remove_part method.
61 /// - ACE_Refcounted_Ptr can both be stored in containers and allows us to
62 /// release ownership of the pointer that it contains.
63 ACE_Unbounded_Queue<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> > parts_;
66 #endif /* WIDGET_IMPL_H */