diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:30 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:30 +0000 |
commit | c44379cc7d9c7aa113989237ab0f56db12aa5219 (patch) | |
tree | 66a84b20d47f2269d8bdc6e0323f338763424d3a /ACE/examples/Smart_Pointers/Widget_Impl.h | |
parent | 3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c (diff) | |
download | ATCD-c44379cc7d9c7aa113989237ab0f56db12aa5219.tar.gz |
Repo restructuring
Diffstat (limited to 'ACE/examples/Smart_Pointers/Widget_Impl.h')
-rw-r--r-- | ACE/examples/Smart_Pointers/Widget_Impl.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/ACE/examples/Smart_Pointers/Widget_Impl.h b/ACE/examples/Smart_Pointers/Widget_Impl.h new file mode 100644 index 00000000000..4933841f912 --- /dev/null +++ b/ACE/examples/Smart_Pointers/Widget_Impl.h @@ -0,0 +1,68 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Widget_Impl.h + * + * $Id$ + * + * @author Christopher Kohlhoff <chris@kohlhoff.com> + */ +//============================================================================= + +#ifndef WIDGET_IMPL_H +#define WIDGET_IMPL_H + +#include "Widget.h" +#include "Widget_Part.h" + +#include "ace/Unbounded_Queue.h" +#include "ace/Refcounted_Auto_Ptr.h" +#include "ace/Synch_Traits.h" +#include "ace/Thread_Mutex.h" + +/** + * @class Widget_Impl + * + * @brief An implementation of the Widget interface. + */ +class Widget_Impl : public Widget +{ +public: + /// Constructor. + Widget_Impl (void); + + /// Destructor. + virtual ~Widget_Impl (void); + + /// Add a new part to the widget. The widget takes ownership of the part + /// object. + virtual void add_part (Widget_Part *part); + + /// Remove a random part from the widget. Ownership of the part is returned + /// to the caller. + virtual Widget_Part *remove_part (void); + + /// Ask the widget to print information about the parts that it contains. + virtual void list_parts (void); + +private: + /// The parts which make up this widget. The set actually contains instances + /// of ACE_Refcounted_Auto_Ptr to automatically manage the lifetimes of the + /// constituent parts. + /// + /// Some things to note about the choice of ACE_Refcounted_Auto_Ptr: + /// - We cannot use auto_ptr to manage the objects, since auto_ptr does not + /// support the copying and assignment semantics necessary for storage in + /// a container. + /// - The ACE_Strong_Bound_Ptr reference counted pointer could be used to + /// store objects in a container, however (for reasons of safety) it + /// provides no way to release ownership of the object from the smart + /// pointer. We need to be able to release ownership to implement the + /// remove_part method. + /// - ACE_Refcounted_Ptr can both be stored in containers and allows us to + /// release ownership of the pointer that it contains. + ACE_Unbounded_Queue<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> > parts_; +}; + +#endif /* WIDGET_IMPL_H */ |