diff options
Diffstat (limited to 'examples/Smart_Pointers')
30 files changed, 0 insertions, 1188 deletions
diff --git a/examples/Smart_Pointers/.cvsignore b/examples/Smart_Pointers/.cvsignore deleted file mode 100644 index f309b7d5f8b..00000000000 --- a/examples/Smart_Pointers/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -Widget -gadget diff --git a/examples/Smart_Pointers/Gadget.cpp b/examples/Smart_Pointers/Gadget.cpp deleted file mode 100644 index 180fe0107cc..00000000000 --- a/examples/Smart_Pointers/Gadget.cpp +++ /dev/null @@ -1,16 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Gadget.cpp - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#include "Gadget.h" - -Gadget::~Gadget (void) -{ -} diff --git a/examples/Smart_Pointers/Gadget.h b/examples/Smart_Pointers/Gadget.h deleted file mode 100644 index 65b1fb0a34e..00000000000 --- a/examples/Smart_Pointers/Gadget.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Gadget.h - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#ifndef GADGET_H -#define GADGET_H - -#include "ace/Bound_Ptr.h" -#include "Gadget_Part.h" - -/** - * @class Gadget - * - * @brief An interface for some high-level application object. - */ -class Gadget -{ -public: - /// Destructor. - virtual ~Gadget (void); - - /// Add a new part to the gadget. The gadget automatically takes shared - /// responsibility for the ownership of the part object since we are passing - /// a Gadget_Part_var. - virtual void add_part (Gadget_Part_var part) = 0; - - /// Remove a random part from the gadget. Responsibility for ownership of the - /// part is automatically returned to the caller since we are returning a - /// Gadget_Part_var. - virtual Gadget_Part_var remove_part (void) = 0; - - /// Ask the gadget to print information about the parts that it contains. - virtual void list_parts (void) = 0; -}; - -// The Gadget_var smart pointer has shared (reference counted) ownership -// semantics. -typedef ACE_Strong_Bound_Ptr<Gadget, ACE_SYNCH_MUTEX> Gadget_var; - -// The Gadget_ptr smart pointer has no ownership semantics, but supports -// conversion back into a Gadget_var. -typedef ACE_Weak_Bound_Ptr<Gadget, ACE_SYNCH_MUTEX> Gadget_ptr; - -#endif /* GADGET_H */ diff --git a/examples/Smart_Pointers/Gadget_Factory.cpp b/examples/Smart_Pointers/Gadget_Factory.cpp deleted file mode 100644 index 054237169f2..00000000000 --- a/examples/Smart_Pointers/Gadget_Factory.cpp +++ /dev/null @@ -1,18 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Gadget_Factory.cpp - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#include "Gadget_Factory.h" -#include "Gadget_Impl.h" - -Gadget_var Gadget_Factory::create_gadget (void) -{ - return Gadget_var (new Gadget_Impl); -} diff --git a/examples/Smart_Pointers/Gadget_Factory.h b/examples/Smart_Pointers/Gadget_Factory.h deleted file mode 100644 index dd3c17e7975..00000000000 --- a/examples/Smart_Pointers/Gadget_Factory.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Gadget_Factory.h - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#ifndef GADGET_FACTORY_H -#define GADGET_FACTORY_H - -#include "Gadget.h" - -/** - * @class Gadget_Factory - * - * @brief Used to create Gadget instances. - */ -class Gadget_Factory -{ -public: - /// Create an instance of a gadget. Ownership of the object is automatically - /// transferred to the caller since we return a Gadget_var. This also means - /// that the object will be deleted automatically if the caller "forgets" to - /// collect the return value. - static Gadget_var create_gadget (void); -}; - -#endif /* GADGET_FACTORY_H */ diff --git a/examples/Smart_Pointers/Gadget_Impl.cpp b/examples/Smart_Pointers/Gadget_Impl.cpp deleted file mode 100644 index 03dd94f8838..00000000000 --- a/examples/Smart_Pointers/Gadget_Impl.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Gadget_Impl.cpp - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#include "Gadget_Impl.h" -#include "ace/Log_Msg.h" - -Gadget_Impl::Gadget_Impl (void) -{ - ACE_DEBUG ((LM_DEBUG, "Gadget_Impl constructor\n")); -} - -Gadget_Impl::~Gadget_Impl (void) -{ - ACE_DEBUG ((LM_DEBUG, "Gadget_Impl destructor\n")); -} - -void Gadget_Impl::add_part (Gadget_Part_var part) -{ - parts_.enqueue_tail (part); -} - -Gadget_Part_var Gadget_Impl::remove_part (void) -{ - Gadget_Part_var removed_part; - if (parts_.dequeue_head (removed_part) == -1) - return Gadget_Part_var(); - return removed_part; -} - -void Gadget_Impl::list_parts (void) -{ - ACE_Unbounded_Queue_Iterator<Gadget_Part_var> iter (parts_); - Gadget_Part_var *current_part; - while (iter.next (current_part)) - { - (*current_part)->print_info (); - iter.advance (); - } -} diff --git a/examples/Smart_Pointers/Gadget_Impl.h b/examples/Smart_Pointers/Gadget_Impl.h deleted file mode 100644 index ed4faf27ca4..00000000000 --- a/examples/Smart_Pointers/Gadget_Impl.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Gadget_Impl.h - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#ifndef GADGET_IMPL_H -#define GADGET_IMPL_H - -#include "ace/Unbounded_Queue.h" -#include "Gadget.h" -#include "Gadget_Part.h" - -/** - * @class Gadget_Impl - * - * @brief An implementation of the Gadget interface. - */ -class Gadget_Impl : public Gadget -{ -public: - /// Constructor. - Gadget_Impl (void); - - /// Destructor. - virtual ~Gadget_Impl (void); - - /// Add a new part to the gadget. The gadget takes ownership of the part - /// object. - virtual void add_part (Gadget_Part_var part); - - /// Remove a random part from the gadget. Ownership of the part is returned - /// to the caller. - virtual Gadget_Part_var remove_part (void); - - /// Ask the gadget to print information about the parts that it contains. - virtual void list_parts (void); - -private: - /// The parts which make up this gadget. The set actually contains instances - /// of Gadget_Part_var to automatically manage the lifetimes of the - /// constituent parts. - ACE_Unbounded_Queue<Gadget_Part_var> parts_; -}; - -#endif /* GADGET_IMPL_H */ diff --git a/examples/Smart_Pointers/Gadget_Part.cpp b/examples/Smart_Pointers/Gadget_Part.cpp deleted file mode 100644 index 9f08f2a61e7..00000000000 --- a/examples/Smart_Pointers/Gadget_Part.cpp +++ /dev/null @@ -1,16 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Gadget_Part.cpp - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#include "Gadget_Part.h" - -Gadget_Part::~Gadget_Part (void) -{ -} diff --git a/examples/Smart_Pointers/Gadget_Part.h b/examples/Smart_Pointers/Gadget_Part.h deleted file mode 100644 index cef4277168a..00000000000 --- a/examples/Smart_Pointers/Gadget_Part.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Gadget_Part.h - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#ifndef GADGET_PART_H -#define GADGET_PART_H - -#include "ace/Bound_Ptr.h" -#include "ace/Synch_Traits.h" -#include "ace/Thread_Mutex.h" - -/** - * @class Gadget_Part - * - * @brief An interface for some high-level application object. - */ -class Gadget_Part -{ -public: - /// Destructor. - virtual ~Gadget_Part (void); - - /// Ask the part to print information about itself. - virtual void print_info (void) = 0; - - /// Ask the part to remove itself from the gadget that contains it. - virtual void remove_from_owner (void) = 0; -}; - -// The Gadget_Part_var smart pointer has shared (reference counted) ownership -// semantics. -typedef ACE_Strong_Bound_Ptr<Gadget_Part, ACE_SYNCH_MUTEX> Gadget_Part_var; - -// The Gadget_Part_ptr smart pointer has no ownership semantics, but supports -// conversion back into a Gadget_var. -typedef ACE_Weak_Bound_Ptr<Gadget_Part, ACE_SYNCH_MUTEX> Gadget_Part_ptr; - -#endif /* GADGET_PART_H */ diff --git a/examples/Smart_Pointers/Gadget_Part_Factory.cpp b/examples/Smart_Pointers/Gadget_Part_Factory.cpp deleted file mode 100644 index caf546fffce..00000000000 --- a/examples/Smart_Pointers/Gadget_Part_Factory.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Gadget_Part_Factory.cpp - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#include "Gadget_Part_Factory.h" -#include "Gadget_Part_Impl.h" - -Gadget_Part_var Gadget_Part_Factory::create_gadget_part (Gadget_ptr owner, - const char* name, - int size) -{ - return Gadget_Part_var (new Gadget_Part_Impl (owner, name, size)); -} diff --git a/examples/Smart_Pointers/Gadget_Part_Factory.h b/examples/Smart_Pointers/Gadget_Part_Factory.h deleted file mode 100644 index a7bc5cb38bd..00000000000 --- a/examples/Smart_Pointers/Gadget_Part_Factory.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Gadget_Part_Factory.h - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#ifndef GADGET_PART_FACTORY_H -#define GADGET_PART_FACTORY_H - -#include "Gadget_Part.h" -#include "Gadget.h" - -/** - * @class Gadget_Part_Factory - * - * @brief Used to create Gadget_Part instances. - */ -class Gadget_Part_Factory -{ -public: - /// Create an instance of a gadget. Ownership of the object is automatically - /// transferred to the caller since we return a Gadget_Part_var. This also - /// means that the object will be deleted automatically if the caller - /// "forgets" to collect the return value. - static Gadget_Part_var create_gadget_part (Gadget_ptr owner, - const char *name, - int size); -}; - -#endif /* GADGET_PART_FACTORY_H */ diff --git a/examples/Smart_Pointers/Gadget_Part_Impl.cpp b/examples/Smart_Pointers/Gadget_Part_Impl.cpp deleted file mode 100644 index aeda00711bb..00000000000 --- a/examples/Smart_Pointers/Gadget_Part_Impl.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Gadget_Part_Impl.cpp - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#include "Gadget_Part_Impl.h" -#include "ace/ACE.h" -#include "ace/Log_Msg.h" -#include "ace/Unbounded_Queue.h" - -Gadget_Part_Impl::Gadget_Part_Impl (Gadget_ptr owner, - const char* name, - int size) - : owner_ (owner), - name_ (ACE::strnew (name)), - size_ (size) -{ - ACE_DEBUG ((LM_DEBUG, "Gadget_Part_Impl constructor\n")); -} - -Gadget_Part_Impl::~Gadget_Part_Impl (void) -{ - ACE_DEBUG ((LM_DEBUG, "Gadget_Part_Impl destructor\n")); - - delete [] name_; -} - -void Gadget_Part_Impl::print_info (void) -{ - ACE_DEBUG ((LM_INFO, "Gadget part: name=%s size=%d\n", name_, size_)); -} - -void Gadget_Part_Impl::remove_from_owner (void) -{ - // Need to guarantee the existence of the owner for the duration of this call. - Gadget_var owner = owner_; - - // Weak pointers are automatically set to NULL if the object they refer to - // is deleted. We can use this fact to check that our owner still exists. - if (owner == 0) - return; - - // Take all existing parts from the owner and build up a temporary list. If - // we find ourselves then we won't add ourselves to the list. - ACE_Unbounded_Queue<Gadget_Part_var> parts; - for (;;) - { - Gadget_Part_var part = owner->remove_part (); - if (part == 0) - break; - if (part != this) - parts.enqueue_tail (part); - } - - // Add the remaining parts back to the gadget. - while (!parts.is_empty ()) - { - Gadget_Part_var part; - parts.dequeue_head (part); - owner->add_part (part); - } -} diff --git a/examples/Smart_Pointers/Gadget_Part_Impl.h b/examples/Smart_Pointers/Gadget_Part_Impl.h deleted file mode 100644 index bcacb84f0c9..00000000000 --- a/examples/Smart_Pointers/Gadget_Part_Impl.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Gadget_Part_Impl.h - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#ifndef GADGET_PART_IMPL_H -#define GADGET_PART_IMPL_H - -#include "Gadget_Part.h" -#include "Gadget.h" - -/** - * @class Gadget_Part_Impl - * - * @brief An implementation of the Gadget_Part interface. - */ -class Gadget_Part_Impl : public Gadget_Part -{ -public: - /// Constructor. - Gadget_Part_Impl (Gadget_ptr owner, const char* name, int size); - - /// Destructor. - virtual ~Gadget_Part_Impl (void); - - /// Ask the part to print information about itself. - virtual void print_info (void); - - /// Ask the part to remove itself from the gadget that contains it. - virtual void remove_from_owner (void); - -private: - /// The gadget that contains this part. - /// - /// Some things to note about the choice of ACE_Weak_Bound_Ptr (from the - /// typedef for Gadget_ptr): - /// - We cannot use an ACE_Strong_Bound_Ptr (Gadget_var) since that would - /// result in circular ownership. - /// - If we use a raw pointer we have no circular ownership problems, but we - /// are unable to guarantee the lifetime of the owner object for the - /// duration of the remove_from_owner call. This may not be a problem in - /// this limited example, but in multithreaded programs remove_from_owner - /// may be called from a different thread to the thread which manages the - /// owner's lifetime. - /// - ACE_Weak_Bound_Ptr (Gadget_ptr) has no ownership semantics, so we have - /// no circular ownership problems. Weak pointers can also be converted - /// back into strong ones, so it is possible to guarantee the lifetime of - /// the owner object for the duration of the remove_from_owner call. - Gadget_ptr owner_; - - /// The name of this part. - char *name_; - - /// The size of this part. - int size_; -}; - -#endif /* GADGET_PART_IMPL_H */ diff --git a/examples/Smart_Pointers/Makefile.am b/examples/Smart_Pointers/Makefile.am deleted file mode 100644 index f782b585f04..00000000000 --- a/examples/Smart_Pointers/Makefile.am +++ /dev/null @@ -1,70 +0,0 @@ -## Process this file with automake to create Makefile.in -## -## $Id$ -## -## This file was generated by MPC. Any changes made directly to -## this file will be lost the next time it is generated. -## -## MPC Command: -## /acebuilds/ACE_wrappers-repository/bin/mwc.pl -include /acebuilds/MPC/config -include /acebuilds/MPC/templates -feature_file /acebuilds/ACE_wrappers-repository/local.features -noreldefs -type automake -exclude build,Kokyu - -ACE_BUILDDIR = $(top_builddir) -ACE_ROOT = $(top_srcdir) - -## Makefile.Smart_Pointers_Gadget.am -noinst_PROGRAMS = gadget - -gadget_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -gadget_SOURCES = \ - Gadget.cpp \ - Gadget_Factory.cpp \ - Gadget_Impl.cpp \ - Gadget_Part.cpp \ - Gadget_Part_Factory.cpp \ - Gadget_Part_Impl.cpp \ - gadget_test.cpp \ - Gadget.h \ - Gadget_Factory.h \ - Gadget_Impl.h \ - Gadget_Part.h \ - Gadget_Part_Factory.h \ - Gadget_Part_Impl.h - -gadget_LDADD = \ - $(top_builddir)/ace/libACE.la - -## Makefile.Smart_Pointers_Widget.am -noinst_PROGRAMS += Widget - -Widget_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -Widget_SOURCES = \ - Widget.cpp \ - Widget_Factory.cpp \ - Widget_Impl.cpp \ - Widget_Part.cpp \ - Widget_Part_Factory.cpp \ - Widget_Part_Impl.cpp \ - widget_test.cpp \ - Widget.h \ - Widget_Factory.h \ - Widget_Impl.h \ - Widget_Part.h \ - Widget_Part_Factory.h \ - Widget_Part_Impl.h - -Widget_LDADD = \ - $(top_builddir)/ace/libACE.la - -## Clean up template repositories, etc. -clean-local: - -rm -f *~ *.bak *.rpo *.sym lib*.*_pure_* core core.* - -rm -f gcctemp.c gcctemp so_locations *.ics - -rm -rf cxx_repository ptrepository ti_files - -rm -rf templateregistry ir.out - -rm -rf ptrepository SunWS_cache Templates.DB diff --git a/examples/Smart_Pointers/README b/examples/Smart_Pointers/README deleted file mode 100644 index a23ea1eb828..00000000000 --- a/examples/Smart_Pointers/README +++ /dev/null @@ -1,29 +0,0 @@ -$Id$ - -Smart Pointers Example ----------------------- - -This example shows the use of the various smart pointer classes -available in ACE. - -There are two programs in this example. Each program implements a -similar set of classes, but with a different style of using smart -pointers. - -The Widget example is written such that objects may only pass raw -pointers between them, and use smart pointers to manage the object -lifetimes. An advantage of this style is the fine-grained control -over the type of smart pointer used in each situation. For example, -if you know that in a particular section of code there is no -concurrency involved, you can strategise ACE_Refcounted_Auto_Ptr on -ACE_Null_Mutex to eliminate locking overhead. Disadvantages of this -style include greater programming complexity and certain ownership -use cases not being easily supported. - -The Gadget example is written such that objects are always passed -around using one of the ACE_Strong_Bound_Ptr/ACE_Weak_Bound_Ptr -pair of smart pointers. The advantage of this style is the -reduction in complexity of object lifetime management (almost as -"good" as Java ;-) The disadvantage is that you pay a cost for the -reference counting and locking overhead even in situations where it -may not be strictly necessary. diff --git a/examples/Smart_Pointers/Smart_Pointers.mpc b/examples/Smart_Pointers/Smart_Pointers.mpc deleted file mode 100644 index fc2fc781a78..00000000000 --- a/examples/Smart_Pointers/Smart_Pointers.mpc +++ /dev/null @@ -1,28 +0,0 @@ -// -*- MPC -*- -// $Id$ - -project(*Gadget) : aceexe { - exename = gadget - Source_Files { - Gadget.cpp - Gadget_Factory.cpp - Gadget_Impl.cpp - Gadget_Part.cpp - Gadget_Part_Factory.cpp - Gadget_Part_Impl.cpp - gadget_test.cpp - } -} - -project(*Widget) : aceexe { - exename = Widget - Source_Files { - Widget.cpp - Widget_Factory.cpp - Widget_Impl.cpp - Widget_Part.cpp - Widget_Part_Factory.cpp - Widget_Part_Impl.cpp - widget_test.cpp - } -} diff --git a/examples/Smart_Pointers/Widget.cpp b/examples/Smart_Pointers/Widget.cpp deleted file mode 100644 index 28d01b54461..00000000000 --- a/examples/Smart_Pointers/Widget.cpp +++ /dev/null @@ -1,16 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Widget.cpp - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#include "Widget.h" - -Widget::~Widget (void) -{ -} diff --git a/examples/Smart_Pointers/Widget.h b/examples/Smart_Pointers/Widget.h deleted file mode 100644 index a38245ca999..00000000000 --- a/examples/Smart_Pointers/Widget.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Widget.h - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#ifndef WIDGET_H -#define WIDGET_H - -#include "Widget_Part.h" - -/** - * @class Widget - * - * @brief An interface for some high-level application object. - */ -class Widget -{ -public: - /// Destructor. - virtual ~Widget (void); - - /// Add a new part to the widget. The widget takes ownership of the part - /// object. - virtual void add_part (Widget_Part *part) = 0; - - /// Remove a random part from the widget. Ownership of the part is returned - /// to the caller. - virtual Widget_Part *remove_part (void) = 0; - - /// Ask the widget to print information about the parts that it contains. - virtual void list_parts (void) = 0; -}; - -#endif /* WIDGET_H */ diff --git a/examples/Smart_Pointers/Widget_Factory.cpp b/examples/Smart_Pointers/Widget_Factory.cpp deleted file mode 100644 index 18fec0c23f4..00000000000 --- a/examples/Smart_Pointers/Widget_Factory.cpp +++ /dev/null @@ -1,18 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Widget_Factory.cpp - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#include "Widget_Factory.h" -#include "Widget_Impl.h" - -Widget *Widget_Factory::create_widget (void) -{ - return new Widget_Impl; -} diff --git a/examples/Smart_Pointers/Widget_Factory.h b/examples/Smart_Pointers/Widget_Factory.h deleted file mode 100644 index adf0613a3fe..00000000000 --- a/examples/Smart_Pointers/Widget_Factory.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Widget_Factory.h - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#ifndef WIDGET_FACTORY_H -#define WIDGET_FACTORY_H - -#include "Widget.h" - -/** - * @class Widget_Factory - * - * @brief Used to create Widget instances. - */ -class Widget_Factory -{ -public: - /// Create an instance of a widget. Ownership of the newly created object is - /// transferred to the caller. - static Widget *create_widget (void); -}; - -#endif /* WIDGET_FACTORY_H */ diff --git a/examples/Smart_Pointers/Widget_Impl.cpp b/examples/Smart_Pointers/Widget_Impl.cpp deleted file mode 100644 index 2d3ab404804..00000000000 --- a/examples/Smart_Pointers/Widget_Impl.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Widget_Impl.cpp - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#include "Widget_Impl.h" -#include "ace/Log_Msg.h" - -Widget_Impl::Widget_Impl (void) -{ - ACE_DEBUG ((LM_DEBUG, "Widget_Impl constructor\n")); -} - -Widget_Impl::~Widget_Impl (void) -{ - ACE_DEBUG ((LM_DEBUG, "Widget_Impl destructor\n")); -} - -void Widget_Impl::add_part (Widget_Part *part) -{ - // Take ownership of the part object using a ACE_Refcounted_Auto_Ptr. - ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> new_part (part); - - parts_.enqueue_tail (new_part); -} - -Widget_Part *Widget_Impl::remove_part (void) -{ - ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> removed_part; - if (parts_.dequeue_head (removed_part) == -1) - return 0; - - // Ownership of the part object is released and transferred to the caller. - return removed_part.release(); -} - -void Widget_Impl::list_parts (void) -{ - ACE_Unbounded_Queue_Iterator<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> > iter (parts_); - ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> *current_part; - while (iter.next (current_part)) - { - (*current_part)->print_info (); - iter.advance (); - } -} diff --git a/examples/Smart_Pointers/Widget_Impl.h b/examples/Smart_Pointers/Widget_Impl.h deleted file mode 100644 index 4933841f912..00000000000 --- a/examples/Smart_Pointers/Widget_Impl.h +++ /dev/null @@ -1,68 +0,0 @@ -// -*- 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 */ diff --git a/examples/Smart_Pointers/Widget_Part.cpp b/examples/Smart_Pointers/Widget_Part.cpp deleted file mode 100644 index 7a74447cff9..00000000000 --- a/examples/Smart_Pointers/Widget_Part.cpp +++ /dev/null @@ -1,16 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Widget_Part.cpp - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#include "Widget_Part.h" - -Widget_Part::~Widget_Part (void) -{ -} diff --git a/examples/Smart_Pointers/Widget_Part.h b/examples/Smart_Pointers/Widget_Part.h deleted file mode 100644 index 7e1f0b575a9..00000000000 --- a/examples/Smart_Pointers/Widget_Part.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Widget_Part.h - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#ifndef WIDGET_PART_H -#define WIDGET_PART_H - -/** - * @class Widget_Part - * - * @brief An interface for some high-level application object. - */ -class Widget_Part -{ -public: - /// Destructor. - virtual ~Widget_Part (void); - - /// Ask the part to print information about itself. - virtual void print_info (void) = 0; - - /// Ask the part to remove itself from the widget that contains it. - virtual void remove_from_owner (void) = 0; -}; - -#endif /* WIDGET_PART_H */ diff --git a/examples/Smart_Pointers/Widget_Part_Factory.cpp b/examples/Smart_Pointers/Widget_Part_Factory.cpp deleted file mode 100644 index 501cdbc745c..00000000000 --- a/examples/Smart_Pointers/Widget_Part_Factory.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Widget_Part_Factory.cpp - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#include "Widget_Part_Factory.h" -#include "Widget_Part_Impl.h" - -Widget_Part *Widget_Part_Factory::create_widget_part (Widget *owner, - const char* name, - int size) -{ - return new Widget_Part_Impl (owner, name, size); -} diff --git a/examples/Smart_Pointers/Widget_Part_Factory.h b/examples/Smart_Pointers/Widget_Part_Factory.h deleted file mode 100644 index 4902ab91c40..00000000000 --- a/examples/Smart_Pointers/Widget_Part_Factory.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Widget_Part_Factory.h - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#ifndef WIDGET_PART_FACTORY_H -#define WIDGET_PART_FACTORY_H - -#include "Widget_Part.h" -#include "Widget.h" - -/** - * @class Widget_Part_Factory - * - * @brief Used to create Widget_Part instances. - */ -class Widget_Part_Factory -{ -public: - /// Create an instance of a widget part. Ownership of the newly created - /// object is transferred to the caller. - static Widget_Part *create_widget_part (Widget *owner, const char *name, int size); -}; - -#endif /* WIDGET_PART_FACTORY_H */ diff --git a/examples/Smart_Pointers/Widget_Part_Impl.cpp b/examples/Smart_Pointers/Widget_Part_Impl.cpp deleted file mode 100644 index 0e4e496f180..00000000000 --- a/examples/Smart_Pointers/Widget_Part_Impl.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Widget_Part_Impl.cpp - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#include "Widget_Part_Impl.h" -#include "ace/ACE.h" -#include "ace/Log_Msg.h" -#include "ace/Refcounted_Auto_Ptr.h" -#include "ace/Unbounded_Queue.h" -#include "ace/Null_Mutex.h" - -Widget_Part_Impl::Widget_Part_Impl (Widget *owner, const char* name, int size) - : owner_ (owner), - name_ (ACE::strnew (name)), - size_ (size) -{ - ACE_DEBUG ((LM_DEBUG, "Widget_Part_Impl constructor\n")); -} - -Widget_Part_Impl::~Widget_Part_Impl (void) -{ - ACE_DEBUG ((LM_DEBUG, "Widget_Part_Impl destructor\n")); - - delete [] name_; -} - -void Widget_Part_Impl::print_info (void) -{ - ACE_DEBUG ((LM_INFO, "Widget part: name=%s size=%d\n", name_, size_)); -} - -void Widget_Part_Impl::remove_from_owner (void) -{ - // Since we only have a raw pointer to refer to the owner, we have no way of - // checking whether the owner still exists, and if it does guaranteeing that - // it will continue to exist for the duration of this call. This is not an - // issue in this limited example program, but in multithreaded applications - // this function may be called from a different thread to that managing the - // lifetime of the owner object. See the Gadget example for how - // ACE_Strong_Bound_Ptr/ACE_Weak_Bound_Ptr can be used to address the problem. - - // Take all existing parts from the owner and build up a temporary queue. If - // we find ourselves then we won't add ourselves to the queue. We will - // actually store ACE_Refcounted_Auto_Ptr instances in the queue, and since we - // know that there is only one thread involved we can use ACE_Null_Mutex to - // eliminate the locking overhead. - ACE_Unbounded_Queue<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_Null_Mutex> > parts; - for (;;) - { - ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_Null_Mutex> part (owner_->remove_part ()); - if (part.null ()) - break; - if (part.get () == this) - // Someone else will be responsible for our lifetime. - part.release(); - else - parts.enqueue_tail (part); - } - - // Add the remaining parts back to the gadget. - while (!parts.is_empty ()) - { - ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_Null_Mutex> part; - parts.dequeue_head (part); - owner_->add_part (part.release ()); - } -} diff --git a/examples/Smart_Pointers/Widget_Part_Impl.h b/examples/Smart_Pointers/Widget_Part_Impl.h deleted file mode 100644 index dbb1d4c714c..00000000000 --- a/examples/Smart_Pointers/Widget_Part_Impl.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Widget_Part_Impl.h - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#ifndef WIDGET_PART_IMPL_H -#define WIDGET_PART_IMPL_H - -#include "Widget_Part.h" -#include "Widget.h" - -/** - * @class Widget_Part_Impl - * - * @brief An implementation of the Widget_Part interface. - */ -class Widget_Part_Impl : public Widget_Part -{ -public: - /// Constructor. - Widget_Part_Impl (Widget *owner, const char* name, int size); - - /// Destructor. - virtual ~Widget_Part_Impl (void); - - /// Ask the part to print information about itself. - virtual void print_info (void); - - /// Ask the part to remove itself from the widget that contains it. - virtual void remove_from_owner (void); - -private: - /// The widget that contains this part. - Widget *owner_; - - /// The name of this part. - char *name_; - - /// The size of this part. - int size_; -}; - -#endif /* WIDGET_PART_IMPL_H */ diff --git a/examples/Smart_Pointers/gadget_test.cpp b/examples/Smart_Pointers/gadget_test.cpp deleted file mode 100644 index 74df2248dc3..00000000000 --- a/examples/Smart_Pointers/gadget_test.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file gadget_test.cpp - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#include "ace/Auto_Ptr.h" -#include "ace/Refcounted_Auto_Ptr.h" -#include "ace/Unbounded_Queue.h" -#include "Gadget.h" -#include "Gadget_Factory.h" -#include "Gadget_Part.h" -#include "Gadget_Part_Factory.h" - -int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) -{ - ACE_UNUSED_ARG (argc); - ACE_UNUSED_ARG (argv); - - Gadget_var g1 = Gadget_Factory::create_gadget (); - g1->add_part (Gadget_Part_Factory::create_gadget_part (g1, "part1", 1)); - g1->add_part (Gadget_Part_Factory::create_gadget_part (g1, "part2", 2)); - g1->add_part (Gadget_Part_Factory::create_gadget_part (g1, "part3", 3)); - - g1->list_parts (); - - Gadget_Part_var p1 = g1->remove_part (); - p1->print_info (); - - // Oops, we forgot to collect the return value! No worries, the temporary - // Gadget_var returned by the function call will clean it up automatically. - g1->remove_part (); - - g1->list_parts (); - - Gadget_var g2 = Gadget_Factory::create_gadget (); - g2->add_part (Gadget_Part_Factory::create_gadget_part (g2, "part4", 4)); - Gadget_Part_var p2 = Gadget_Part_Factory::create_gadget_part (g2, "part5", 5); - g2->add_part (p2); - p2->remove_from_owner (); - - g2->list_parts (); - - return 0; -} - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class ACE_Bound_Ptr_Counter<ACE_SYNCH_MUTEX>; -template class ACE_Strong_Bound_Ptr<Gadget, ACE_SYNCH_MUTEX>; -template class ACE_Weak_Bound_Ptr<Gadget, ACE_SYNCH_MUTEX>; -template class ACE_Strong_Bound_Ptr<Gadget_Part, ACE_SYNCH_MUTEX>; -template class ACE_Weak_Bound_Ptr<Gadget_Part, ACE_SYNCH_MUTEX>; -template class ACE_Node<Gadget_Part_var>; -template class ACE_Unbounded_Queue<Gadget_Part_var>; -template class ACE_Unbounded_Queue_Iterator<Gadget_Part_var>; -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate ACE_Bound_Ptr_Counter<ACE_SYNCH_MUTEX> -#pragma instantiate ACE_Strong_Bound_Ptr<Gadget, ACE_SYNCH_MUTEX> -#pragma instantiate ACE_Weak_Bound_Ptr<Gadget, ACE_SYNCH_MUTEX> -#pragma instantiate ACE_Strong_Bound_Ptr<Gadget_Part, ACE_SYNCH_MUTEX> -#pragma instantiate ACE_Weak_Bound_Ptr<Gadget_Part, ACE_SYNCH_MUTEX> -#pragma instantiate ACE_Node<Gadget_Part_var> -#pragma instantiate ACE_Unbounded_Queue<Gadget_Part_var> -#pragma instantiate ACE_Unbounded_Queue_Iterator<Gadget_Part_var> -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ - diff --git a/examples/Smart_Pointers/widget_test.cpp b/examples/Smart_Pointers/widget_test.cpp deleted file mode 100644 index 978b33d5bec..00000000000 --- a/examples/Smart_Pointers/widget_test.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file widget_test.cpp - * - * $Id$ - * - * @author Christopher Kohlhoff <chris@kohlhoff.com> - */ -//============================================================================= - -#include "ace/Auto_Ptr.h" -#include "ace/Refcounted_Auto_Ptr.h" -#include "ace/Unbounded_Queue.h" -#include "ace/Synch_Traits.h" -#include "ace/Thread_Mutex.h" -#include "ace/Null_Mutex.h" -#include "Widget.h" -#include "Widget_Factory.h" -#include "Widget_Part.h" -#include "Widget_Part_Factory.h" - -int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) -{ - ACE_UNUSED_ARG (argc); - ACE_UNUSED_ARG (argv); - - auto_ptr<Widget> w1 (Widget_Factory::create_widget ()); - w1->add_part (Widget_Part_Factory::create_widget_part (w1.get(), "part1", 1)); - w1->add_part (Widget_Part_Factory::create_widget_part (w1.get(), "part2", 2)); - w1->add_part (Widget_Part_Factory::create_widget_part (w1.get(), "part3", 3)); - - w1->list_parts (); - - auto_ptr<Widget_Part> p1 (w1->remove_part ()); - p1->print_info (); - auto_ptr<Widget_Part> p2 (w1->remove_part ()); - - w1->list_parts (); - - auto_ptr<Widget> w2 (Widget_Factory::create_widget ()); - w2->add_part (Widget_Part_Factory::create_widget_part (w2.get(), "part4", 4)); - Widget_Part *p3 = Widget_Part_Factory::create_widget_part (w2.get(), "part5", 5); - w2->add_part (p3); - p3->remove_from_owner (); - - w2->list_parts (); - - return 0; -} - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class ACE_Auto_Basic_Ptr<Widget>; -template class auto_ptr<Widget>; -template class ACE_Auto_Basic_Ptr<Widget_Part>; -template class auto_ptr<Widget_Part>; -template class ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX>; -template class ACE_Node<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> >; -template class ACE_Unbounded_Queue<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> >; -template class ACE_Unbounded_Queue_Iterator<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> >; -template class ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_Null_Mutex>; -template class ACE_Node<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_Null_Mutex> >; -template class ACE_Unbounded_Queue<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_Null_Mutex> >; -template class ACE_Unbounded_Queue_Iterator<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_Null_Mutex> >; -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate ACE_Auto_Basic_Ptr<Widget> -#pragma instantiate auto_ptr<Widget> -#pragma instantiate ACE_Auto_Basic_Ptr<Widget_Part> -#pragma instantiate auto_ptr<Widget_Part> -#pragma instantiate ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> -#pragma instantiate ACE_Node<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> > -#pragma instantiate ACE_Unbounded_Queue<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> > -#pragma instantiate ACE_Unbounded_Queue_Iterator<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> > -#pragma instantiate ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_Null_Mutex> -#pragma instantiate ACE_Node<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_Null_Mutex> > -#pragma instantiate ACE_Unbounded_Queue<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_Null_Mutex> > -#pragma instantiate ACE_Unbounded_Queue_Iterator<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_Null_Mutex> > -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ |