diff options
author | coryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2002-07-08 20:32:03 +0000 |
---|---|---|
committer | coryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2002-07-08 20:32:03 +0000 |
commit | 4c63359d4a42dfed62327cda39f123479ff642b1 (patch) | |
tree | e653d54edcf1872fcfcf482354e848c61e4729bd | |
parent | 8a51b3da1846aa0af3869a3defcc33540eb97949 (diff) | |
download | ATCD-4c63359d4a42dfed62327cda39f123479ff642b1.tar.gz |
ChangeLogTag:Mon Jul 8 16:29:16 2002 Carlos O'Ryan <coryan@atdesk.com>
-rw-r--r-- | TAO/ChangeLog | 36 | ||||
-rw-r--r-- | TAO/tao/Utils/Auto_Functor.cpp | 43 | ||||
-rw-r--r-- | TAO/tao/Utils/Auto_Functor.h | 114 | ||||
-rw-r--r-- | TAO/tao/Utils/Auto_Functor.inl | 141 | ||||
-rw-r--r-- | TAO/tao/Utils/Implicit_Deactivator.cpp | 26 | ||||
-rw-r--r-- | TAO/tao/Utils/Implicit_Deactivator.h | 47 | ||||
-rw-r--r-- | TAO/tao/Utils/Makefile | 366 | ||||
-rw-r--r-- | TAO/tao/Utils/ORB_Destroyer.cpp | 26 | ||||
-rw-r--r-- | TAO/tao/Utils/ORB_Destroyer.h | 48 | ||||
-rw-r--r-- | TAO/tao/Utils/PolicyList_Destroyer.cpp | 33 | ||||
-rw-r--r-- | TAO/tao/Utils/PolicyList_Destroyer.h | 39 | ||||
-rw-r--r-- | TAO/tao/Utils/PolicyList_Destroyer.inl | 7 | ||||
-rw-r--r-- | TAO/tao/Utils/RIR_Narrow.cpp | 49 | ||||
-rw-r--r-- | TAO/tao/Utils/RIR_Narrow.h | 56 | ||||
-rw-r--r-- | TAO/tao/Utils/Servant_Var.cpp | 18 | ||||
-rw-r--r-- | TAO/tao/Utils/Servant_Var.h | 158 | ||||
-rw-r--r-- | TAO/tao/Utils/Servant_Var.inl | 192 |
17 files changed, 1399 insertions, 0 deletions
diff --git a/TAO/ChangeLog b/TAO/ChangeLog index 2dbd640bb12..82fcd82ad12 100644 --- a/TAO/ChangeLog +++ b/TAO/ChangeLog @@ -1,3 +1,39 @@ +Mon Jul 8 16:29:16 2002 Carlos O'Ryan <coryan@atdesk.com> + + * tao/Utils/Makefile: + Add new library with helper classes and templates that make + type-safe, exception-safe CORBA programming significantly + easier. + + * tao/Utils/Auto_Functor.h: + * tao/Utils/Auto_Functor.inl: + * tao/Utils/Auto_Functor.cpp: + Policy-based auto_ptr<>-like helper class. + + * tao/Utils/Implicit_Deactivator.h: + * tao/Utils/Implicit_Deactivator.cpp: + Automatically deactivate an implicitly activated (i.e. via + _this()) servant. + + * tao/Utils/ORB_Destroyer.h: + * tao/Utils/ORB_Destroyer.cpp: + Automatically call orb->destroy() + + * tao/Utils/PolicyList_Destroyer.h: + * tao/Utils/PolicyList_Destroyer.inl: + * tao/Utils/PolicyList_Destroyer.cpp: + Automatically destroy all the policies in a policy list. + + * tao/Utils/RIR_Narrow.h: + * tao/Utils/RIR_Narrow.cpp: + Call resolve_initial_references() and then narrow. + + * tao/Utils/Servant_Var.h: + * tao/Utils/Servant_Var.inl: + * tao/Utils/Servant_Var.cpp: + Automatically manage the reference count on a Servant, like + ServantBase_var, but type-safe. + Mon Jul 8 15:16:34 2002 Jeff Parsons <parsons@cs.wustl.edu> * tests/DynAny_Test/Makefile: diff --git a/TAO/tao/Utils/Auto_Functor.cpp b/TAO/tao/Utils/Auto_Functor.cpp new file mode 100644 index 00000000000..eeaa3ec3a28 --- /dev/null +++ b/TAO/tao/Utils/Auto_Functor.cpp @@ -0,0 +1,43 @@ +#ifndef Auto_Functor__cpp_ +#define Auto_Functor__cpp_ +/** + * @file Auto_Functor.cpp + * + * $Id$ + * + * @author Carlos O'Ryan <coryan@atdesk.com> + */ + +#include "Auto_Functor.h" + +#if !defined(__ACE_INLINE__) +# include "Auto_Functor.inl" +#endif /* __ACE_INLINE__ */ + +template<typename X, typename Functor> +TAO::Utils::Auto_Functor<X,Functor>:: +~Auto_Functor() throw() +{ + reset(0); +} + +template<typename X, typename Functor> +void TAO::Utils::Auto_Functor<X,Functor>:: +reset (X * p) throw() +{ + if(p_ != 0) + { + f_(p_); + } + p_ = p; +} + +template<typename X, typename Functor> +void TAO::Utils::Auto_Functor<X,Functor>:: +reset (X * p, Functor f) throw() +{ + reset(p); + f_ = f; +} + +#endif // Auto_Functor__cpp_ diff --git a/TAO/tao/Utils/Auto_Functor.h b/TAO/tao/Utils/Auto_Functor.h new file mode 100644 index 00000000000..352bf66a0e5 --- /dev/null +++ b/TAO/tao/Utils/Auto_Functor.h @@ -0,0 +1,114 @@ +#ifndef Auto_Functor__h_ +#define Auto_Functor__h_ + +/** + * @file Auto_Functor.h + * + * $Id$ + * + * @author Carlos O'Ryan <coryan@atdesk.com> + */ + +#include <ace/config-all.h> + +namespace TAO +{ +namespace Utils +{ + +/** + * @class Auto_Functor_Ref + * + * @brief Helper class to implement assignment and copy-construction + * as expected + */ +template<typename X, typename Functor> +struct Auto_Functor_Ref +{ + X * p_; + Functor f_; + + Auto_Functor_Ref(X * p, Functor f); +}; + +/** + * @class Auto_Functor + * + * @brief Helper template to implement auto_ptr<>-like classes, but + * executing a functor in the destructor, instead of always + * deleting things. + * + * The functor is called in the destructor, and it must implement: + * + * Functor() throw();<BR> + * Functor(Functor const &) throw();<BR> + * Functor & operator=(Functor const &) throw();<BR> + * void operator()(X * p) throw();<BR> + * + */ +template<typename X, typename Functor> +class Auto_Functor +{ +public: + typedef X element_type; + typedef Functor functor_type; + + /// Constructor + explicit Auto_Functor(X * p = 0, Functor functor = Functor()) + throw(); + + Auto_Functor(Auto_Functor & rhs) throw(); + Auto_Functor<X,Functor>& operator=(Auto_Functor & rhs) + throw(); + +#if !defined(ACE_LACKS_MEMBER_TEMPLATES) + template<typename Y> + Auto_Functor(Auto_Functor<Y,Functor>& rhs) + throw(); + template<typename Y> + Auto_Functor<X,Functor>& operator=(Auto_Functor<Y,Functor>& rhs) + throw(); +#endif /* ACE_LACKS_MEMBER_TEMPLATES */ + + ~Auto_Functor() throw(); + + X & operator*() const throw(); + X * operator->() const throw(); + X * get() throw(); + X * release() throw(); + void reset (X * p = 0) throw(); + void reset (X * p, Functor f) throw(); + + Functor const & functor() const throw(); + + Auto_Functor(Auto_Functor_Ref<X,Functor> rhs) + throw(); + + Auto_Functor<X,Functor> & operator=(Auto_Functor_Ref<X,Functor> rhs) + throw(); + +#if !defined(ACE_LACKS_MEMBER_TEMPLATES) + template<typename Y> operator Auto_Functor_Ref<Y,Functor>() throw(); + template<typename Y> operator Auto_Functor<Y,Functor>() throw(); +#else + operator Auto_Functor_Ref<X,Functor>() throw(); +#endif /* ACE_LACKS_MEMBER_TEMPLATES */ + +private: + X * p_; + + Functor f_; +}; + +} // namespace Utils +} // namespace TAO + +#if defined(__ACE_INLINE__) +# include "Auto_Functor.inl" +#endif /* __ACE_INLINE__ */ + +#if defined(ACE_TEMPLATES_REQUIRE_SOURCE) +# include "Auto_Functor.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#endif // Auto_Functor__hpp_ diff --git a/TAO/tao/Utils/Auto_Functor.inl b/TAO/tao/Utils/Auto_Functor.inl new file mode 100644 index 00000000000..86452f7fefb --- /dev/null +++ b/TAO/tao/Utils/Auto_Functor.inl @@ -0,0 +1,141 @@ +// $Id$ + +template<typename X, typename Functor> +ACE_INLINE TAO::Utils::Auto_Functor_Ref<X,Functor>:: +Auto_Functor_Ref(X * p, Functor f) + : p_(p) + , f_(f) +{ +} + +template<typename X, typename Functor> +ACE_INLINE TAO::Utils::Auto_Functor<X,Functor>:: +Auto_Functor(X * p, Functor f) throw() + : p_(p) + , f_(f) +{ +} + +template<typename X, typename Functor> +ACE_INLINE TAO::Utils::Auto_Functor<X,Functor>:: +Auto_Functor(Auto_Functor & rhs) throw() + : p_(rhs.release()) + , f_(rhs.f_) +{ +} + +template<typename X, typename Functor> +ACE_INLINE TAO::Utils::Auto_Functor<X,Functor>& +TAO::Utils::Auto_Functor<X,Functor>:: +operator=(Auto_Functor & rhs) throw() +{ + reset(rhs.release()); + f_ = rhs.f_; + return *this; +} + +#if !defined(ACE_LACKS_MEMBER_TEMPLATES) +template<typename X, typename Functor> template<typename Y> +ACE_INLINE TAO::Utils::Auto_Functor<X,Functor>:: +Auto_Functor(Auto_Functor<Y,Functor>& rhs) + throw() + : p_(rhs.release()) + , f_(rhs.f_) +{ +} + +template<typename X, typename Functor> template<typename Y> +ACE_INLINE TAO::Utils::Auto_Functor<X,Functor>& +TAO::Utils::Auto_Functor<X,Functor>:: +operator=(Auto_Functor<Y,Functor>& rhs) + throw() +{ + reset(rhs.release()); + return *this; +} +#endif /* ACE_LACKS_MEMBER_TEMPLATES */ + +template<typename X, typename Functor> +ACE_INLINE X & TAO::Utils::Auto_Functor<X,Functor>:: +operator*() const throw() +{ + return *p_; +} + +template<typename X, typename Functor> +ACE_INLINE X * TAO::Utils::Auto_Functor<X,Functor>:: +operator->() const throw() +{ + return p_; +} + +template<typename X, typename Functor> +ACE_INLINE X * TAO::Utils::Auto_Functor<X,Functor>:: +get() throw() +{ + return p_; +} + +template<typename X, typename Functor> +ACE_INLINE X * TAO::Utils::Auto_Functor<X,Functor>:: +release() throw() +{ + X * tmp = p_; + p_ = 0; + return tmp; +} + +template<typename X, typename Functor> +ACE_INLINE Functor const & TAO::Utils::Auto_Functor<X,Functor>:: +functor() const throw() +{ + return f_; +} + +template<typename X, typename Functor> +ACE_INLINE TAO::Utils::Auto_Functor<X,Functor>:: +Auto_Functor(Auto_Functor_Ref<X,Functor> rhs) throw() + : p_(rhs.p_) + , f_(rhs.f_) +{ +} + +template<typename X, typename Functor> +ACE_INLINE TAO::Utils::Auto_Functor<X,Functor> & +TAO::Utils::Auto_Functor<X,Functor>:: +operator=(Auto_Functor_Ref<X,Functor> rhs) throw() +{ + if(rhs.p_ != p_) + { + reset(rhs.p_); + f_ = rhs.f_; + } + return *this; +} + +#if !defined(ACE_LACKS_MEMBER_TEMPLATES) + +template<typename X, typename Functor> template<typename Y> +ACE_INLINE TAO::Utils::Auto_Functor<X,Functor>:: +operator TAO::Utils::Auto_Functor_Ref<Y,Functor>() throw() +{ + return TAO::Utils::Auto_Functor_Ref<Y,Functor>(release(), f_); +} + +template<typename X, typename Functor> template<typename Y> +ACE_INLINE TAO::Utils::Auto_Functor<X,Functor>:: +operator TAO::Utils::Auto_Functor<Y,Functor>() throw() +{ + return TAO::Utils::Auto_Functor<Y,Functor>(release(), f_); +} + +#else + +template<typename X, typename Functor> +ACE_INLINE TAO::Utils::Auto_Functor<X,Functor>:: +operator TAO::Utils::Auto_Functor_Ref<X,Functor>() throw() +{ + return TAO::Utils::Auto_Functor_Ref<X,Functor>(release(), f_); +} + +#endif /* ACE_LACKS_MEMBER_TEMPLATES */ diff --git a/TAO/tao/Utils/Implicit_Deactivator.cpp b/TAO/tao/Utils/Implicit_Deactivator.cpp new file mode 100644 index 00000000000..685f5d54fe1 --- /dev/null +++ b/TAO/tao/Utils/Implicit_Deactivator.cpp @@ -0,0 +1,26 @@ +/** + * @file Implicit_Deactivator.cpp + * + * $Id$ + * + * @author Carlos O'Ryan <coryan@atdesk.com> + */ + +#include "Implicit_Deactivator.h" + +#include <tao/PortableServer/Servant_Base.h> + +void TAO::Utils::Implicit_Deactivation_Functor:: +operator() (PortableServer::ServantBase * servant) throw() +{ + try + { + PortableServer::POA_var poa(servant->_default_POA()); + PortableServer::ObjectId_var id(poa->servant_to_id(servant)); + poa->deactivate_object(id.in()); + } + catch(...) + { + // @@ Cannot let exceptions escape, yet we need to log them! + } +} diff --git a/TAO/tao/Utils/Implicit_Deactivator.h b/TAO/tao/Utils/Implicit_Deactivator.h new file mode 100644 index 00000000000..d40a47fb9a3 --- /dev/null +++ b/TAO/tao/Utils/Implicit_Deactivator.h @@ -0,0 +1,47 @@ +/** + * @file Implicit_Deactivator.h + * + * $Id$ + * + * @author Carlos O'Ryan <coryan@atdesk.com> + */ +#ifndef Implicit_Deactivator__h_ +#define Implicit_Deactivator__h_ + +#include "Auto_Functor.h" + +#include "tao/PortableServer/PortableServer.h" + +namespace TAO +{ +namespace Utils +{ + +/** + * @struct Implicit_Deactivation_Functor + * + * @brief Implements a functor for the Implicit_Deactivator class. + */ +struct Implicit_Deactivation_Functor +{ + typedef PortableServer::ServantBase * argument; + + // Deactivate an implicitly activated servant + void operator() (PortableServer::ServantBase * servant) throw(); +}; + +/** + * @class Implicit_Deactivator + * + * @brief Helper class to deactivate implicitly activated servants. + * + */ +typedef Auto_Functor< + PortableServer::ServantBase, + Implicit_Deactivation_Functor> + Implicit_Deactivator; + +} // namespace Utils +} // namespace TAO + +#endif // Implicit_Deactivator__h_ diff --git a/TAO/tao/Utils/Makefile b/TAO/tao/Utils/Makefile new file mode 100644 index 00000000000..7e6c790be5b --- /dev/null +++ b/TAO/tao/Utils/Makefile @@ -0,0 +1,366 @@ +#---------------------------------------------------------------------------- +# +# $Id$ +# +#---------------------------------------------------------------------------- +ifndef TAO_ROOT + TAO_ROOT = $(ACE_ROOT)/TAO +endif # ! TAO_ROOT + +MAKEFILE = Makefile +LIBNAME = libTAO_Utils +LIB = $(LIBNAME).a +SHLIB = $(LIBNAME).$(SOEXT) + +ACE_SHLIBS = -lTAO_PortableServer -lTAO -lACE + +CPP_SRCS += \ + ORB_Destroyer \ + Implicit_Deactivator \ + PolicyList_Destroyer + +TEMPLATE_FILES = \ + Auto_Functor \ + RIR_Narrow \ + Servant_Var + +FILES = $(CPP_SRCS) +DEFS = $(addsuffix .h,$(FILES)) +LSRC = $(addsuffix .cpp,$(FILES)) + +#---------------------------------------------------------------------------- +# Include macros and targets +#---------------------------------------------------------------------------- + +include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU +include $(TAO_ROOT)/rules.tao.GNU +include $(ACE_ROOT)/include/makeinclude/macros.GNU +include $(ACE_ROOT)/include/makeinclude/rules.common.GNU +include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU +include $(ACE_ROOT)/include/makeinclude/rules.lib.GNU +include $(ACE_ROOT)/include/makeinclude/rules.bin.GNU +include $(ACE_ROOT)/include/makeinclude/rules.local.GNU + +#---------------------------------------------------------------------------- +# Local targets (and local hacks) +#---------------------------------------------------------------------------- + +LDFLAGS += -L$(TAO_ROOT)/tao +CPPFLAGS += -I$(TAO_ROOT) + +#---------------------------------------------------------------------------- +# Dependencies +#---------------------------------------------------------------------------- + +# DO NOT DELETE THIS LINE -- g++dep uses it. +# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. + + +.obj/ORB_Destroyer.o .obj/ORB_Destroyer.so .shobj/ORB_Destroyer.o .shobj/ORB_Destroyer.so: ORB_Destroyer.cpp ORB_Destroyer.h Auto_Functor.h \ + $(ACE_ROOT)/ace/post.h \ + $(ACE_ROOT)/ace/ace_wchar.h \ + $(ACE_ROOT)/ace/ace_wchar.inl \ + Auto_Functor.cpp Auto_Functor.inl \ + $(TAO_ROOT)/tao/ORB.h \ + $(TAO_ROOT)/tao/corbafwd.h \ + $(ACE_ROOT)/ace/CDR_Base.h \ + $(ACE_ROOT)/ace/Basic_Types.h \ + $(ACE_ROOT)/ace/ACE_export.h \ + $(ACE_ROOT)/ace/Message_Block.h \ + $(ACE_ROOT)/ace/OS.h \ + $(ACE_ROOT)/ace/OS_Dirent.h \ + $(ACE_ROOT)/ace/OS_Export.h \ + $(ACE_ROOT)/ace/OS_Errno.h \ + $(ACE_ROOT)/ace/OS_String.h \ + $(ACE_ROOT)/ace/OS_Memory.h \ + $(ACE_ROOT)/ace/OS_TLI.h \ + $(ACE_ROOT)/ace/Time_Value.h \ + $(ACE_ROOT)/ace/Default_Constants.h \ + $(ACE_ROOT)/ace/Global_Macros.h \ + $(ACE_ROOT)/ace/Min_Max.h \ + $(ACE_ROOT)/ace/streams.h \ + $(ACE_ROOT)/ace/Trace.h \ + $(ACE_ROOT)/ace/Message_Block_T.h \ + $(ACE_ROOT)/ace/Message_Block_T.cpp \ + $(ACE_ROOT)/ace/Message_Block_T.i \ + $(ACE_ROOT)/ace/CORBA_macros.h \ + $(TAO_ROOT)/tao/orbconf.h \ + $(TAO_ROOT)/tao/varbase.h \ + $(TAO_ROOT)/tao/TAO_Export.h \ + $(TAO_ROOT)/tao/Exception.h \ + $(ACE_ROOT)/ace/SString.h \ + $(ACE_ROOT)/ace/String_Base.h \ + $(ACE_ROOT)/ace/ACE.h \ + $(ACE_ROOT)/ace/Flag_Manip.h \ + $(ACE_ROOT)/ace/Flag_Manip.i \ + $(ACE_ROOT)/ace/Handle_Ops.h \ + $(ACE_ROOT)/ace/Handle_Ops.i \ + $(ACE_ROOT)/ace/Lib_Find.h \ + $(ACE_ROOT)/ace/Lib_Find.i \ + $(ACE_ROOT)/ace/Init_ACE.h \ + $(ACE_ROOT)/ace/Init_ACE.i \ + $(ACE_ROOT)/ace/Sock_Connect.h \ + $(ACE_ROOT)/ace/Sock_Connect.i \ + $(ACE_ROOT)/ace/ACE.i \ + $(ACE_ROOT)/ace/String_Base_Const.h \ + $(ACE_ROOT)/ace/String_Base.cpp \ + $(ACE_ROOT)/ace/Malloc.h \ + $(ACE_ROOT)/ace/Log_Msg.h \ + $(ACE_ROOT)/ace/Log_Priority.h \ + $(ACE_ROOT)/ace/OS_Log_Msg_Attributes.h \ + $(ACE_ROOT)/ace/Malloc_T.h \ + $(ACE_ROOT)/ace/Synch.h \ + $(ACE_ROOT)/ace/Synch_T.h \ + $(ACE_ROOT)/ace/Synch_T.cpp \ + $(ACE_ROOT)/ace/Thread.h \ + $(ACE_ROOT)/ace/Thread_Adapter.h \ + $(ACE_ROOT)/ace/Base_Thread_Adapter.h \ + $(ACE_ROOT)/ace/Synch_T.i \ + $(ACE_ROOT)/ace/Malloc_Allocator.h \ + $(ACE_ROOT)/ace/Malloc_Base.h \ + $(ACE_ROOT)/ace/Free_List.h \ + $(ACE_ROOT)/ace/Free_List.cpp \ + $(ACE_ROOT)/ace/Free_List.i \ + $(ACE_ROOT)/ace/Malloc_T.cpp \ + $(ACE_ROOT)/ace/Malloc_T.i \ + $(ACE_ROOT)/ace/Memory_Pool.h \ + $(ACE_ROOT)/ace/Event_Handler.h \ + $(ACE_ROOT)/ace/Signal.h \ + $(ACE_ROOT)/ace/Mem_Map.h \ + $(ACE_ROOT)/ace/SV_Semaphore_Complex.h \ + $(ACE_ROOT)/ace/SV_Semaphore_Simple.h \ + $(ACE_ROOT)/ace/SV_Semaphore_Simple.i \ + $(ACE_ROOT)/ace/SV_Semaphore_Complex.i \ + $(ACE_ROOT)/ace/Unbounded_Set.h \ + $(ACE_ROOT)/ace/Node.h \ + $(ACE_ROOT)/ace/Node.cpp \ + $(ACE_ROOT)/ace/Unbounded_Set.cpp \ + $(ACE_ROOT)/ace/Unbounded_Set.inl \ + $(ACE_ROOT)/ace/Auto_Ptr.h \ + $(ACE_ROOT)/ace/Auto_Ptr.cpp \ + $(ACE_ROOT)/ace/Auto_Ptr.i \ + $(ACE_ROOT)/ace/String_Base.i \ + $(TAO_ROOT)/tao/Services.h \ + $(TAO_ROOT)/tao/Sequence.h \ + $(TAO_ROOT)/tao/Managed_Types.h \ + $(TAO_ROOT)/tao/Sequence_T.h \ + $(TAO_ROOT)/tao/Sequence_T.cpp \ + $(TAO_ROOT)/tao/Environment.h \ + $(TAO_ROOT)/tao/Sequence_T.i \ + $(TAO_ROOT)/tao/CORBA_String.h \ + $(TAO_ROOT)/tao/objectid.h \ + $(TAO_ROOT)/tao/PolicyC.h \ + $(TAO_ROOT)/tao/CurrentC.h \ + $(TAO_ROOT)/tao/Object.h \ + $(TAO_ROOT)/tao/Policy_ForwardC.h \ + $(TAO_ROOT)/tao/CDR.h \ + $(ACE_ROOT)/ace/CDR_Stream.h \ + $(TAO_ROOT)/tao/Remote_Object_Proxy_Impl.h \ + $(TAO_ROOT)/tao/Object_Proxy_Impl.h \ + $(TAO_ROOT)/tao/Encodable.h + +.obj/Implicit_Deactivator.o .obj/Implicit_Deactivator.so .shobj/Implicit_Deactivator.o .shobj/Implicit_Deactivator.so: Implicit_Deactivator.cpp Implicit_Deactivator.h \ + $(ACE_ROOT)/ace/post.h \ + $(ACE_ROOT)/ace/ace_wchar.h \ + $(ACE_ROOT)/ace/ace_wchar.inl \ + Auto_Functor.cpp Auto_Functor.inl \ + $(TAO_ROOT)/tao/PortableServer/PortableServer.h \ + $(TAO_ROOT)/tao/PortableServer/portableserver_export.h \ + $(TAO_ROOT)/tao/corbafwd.h \ + $(ACE_ROOT)/ace/CDR_Base.h \ + $(ACE_ROOT)/ace/Basic_Types.h \ + $(ACE_ROOT)/ace/ACE_export.h \ + $(ACE_ROOT)/ace/Message_Block.h \ + $(ACE_ROOT)/ace/OS.h \ + $(ACE_ROOT)/ace/OS_Dirent.h \ + $(ACE_ROOT)/ace/OS_Export.h \ + $(ACE_ROOT)/ace/OS_Errno.h \ + $(ACE_ROOT)/ace/OS_String.h \ + $(ACE_ROOT)/ace/OS_Memory.h \ + $(ACE_ROOT)/ace/OS_TLI.h \ + $(ACE_ROOT)/ace/Time_Value.h \ + $(ACE_ROOT)/ace/Default_Constants.h \ + $(ACE_ROOT)/ace/Global_Macros.h \ + $(ACE_ROOT)/ace/Min_Max.h \ + $(ACE_ROOT)/ace/streams.h \ + $(ACE_ROOT)/ace/Trace.h \ + $(ACE_ROOT)/ace/Message_Block_T.h \ + $(ACE_ROOT)/ace/Message_Block_T.cpp \ + $(ACE_ROOT)/ace/Message_Block_T.i \ + $(ACE_ROOT)/ace/CORBA_macros.h \ + $(TAO_ROOT)/tao/orbconf.h \ + $(TAO_ROOT)/tao/varbase.h \ + $(TAO_ROOT)/tao/TAO_Export.h \ + $(TAO_ROOT)/tao/PortableServer/PortableServerC.h \ + $(TAO_ROOT)/tao/CurrentC.h \ + $(TAO_ROOT)/tao/Object.h \ + $(TAO_ROOT)/tao/Policy_ForwardC.h \ + $(TAO_ROOT)/tao/Sequence.h \ + $(TAO_ROOT)/tao/Managed_Types.h \ + $(ACE_ROOT)/ace/Log_Msg.h \ + $(ACE_ROOT)/ace/Log_Priority.h \ + $(ACE_ROOT)/ace/OS_Log_Msg_Attributes.h \ + $(TAO_ROOT)/tao/Sequence_T.h \ + $(TAO_ROOT)/tao/Sequence_T.cpp \ + $(TAO_ROOT)/tao/Environment.h \ + $(TAO_ROOT)/tao/Sequence_T.i \ + $(TAO_ROOT)/tao/CDR.h \ + $(ACE_ROOT)/ace/CDR_Stream.h \ + $(ACE_ROOT)/ace/SString.h \ + $(ACE_ROOT)/ace/String_Base.h \ + $(ACE_ROOT)/ace/ACE.h \ + $(ACE_ROOT)/ace/Flag_Manip.h \ + $(ACE_ROOT)/ace/Flag_Manip.i \ + $(ACE_ROOT)/ace/Handle_Ops.h \ + $(ACE_ROOT)/ace/Handle_Ops.i \ + $(ACE_ROOT)/ace/Lib_Find.h \ + $(ACE_ROOT)/ace/Lib_Find.i \ + $(ACE_ROOT)/ace/Init_ACE.h \ + $(ACE_ROOT)/ace/Init_ACE.i \ + $(ACE_ROOT)/ace/Sock_Connect.h \ + $(ACE_ROOT)/ace/Sock_Connect.i \ + $(ACE_ROOT)/ace/ACE.i \ + $(ACE_ROOT)/ace/String_Base_Const.h \ + $(ACE_ROOT)/ace/String_Base.cpp \ + $(ACE_ROOT)/ace/Malloc.h \ + $(ACE_ROOT)/ace/Malloc_T.h \ + $(ACE_ROOT)/ace/Synch.h \ + $(ACE_ROOT)/ace/Synch_T.h \ + $(ACE_ROOT)/ace/Synch_T.cpp \ + $(ACE_ROOT)/ace/Thread.h \ + $(ACE_ROOT)/ace/Thread_Adapter.h \ + $(ACE_ROOT)/ace/Base_Thread_Adapter.h \ + $(ACE_ROOT)/ace/Synch_T.i \ + $(ACE_ROOT)/ace/Malloc_Allocator.h \ + $(ACE_ROOT)/ace/Malloc_Base.h \ + $(ACE_ROOT)/ace/Free_List.h \ + $(ACE_ROOT)/ace/Free_List.cpp \ + $(ACE_ROOT)/ace/Free_List.i \ + $(ACE_ROOT)/ace/Malloc_T.cpp \ + $(ACE_ROOT)/ace/Malloc_T.i \ + $(ACE_ROOT)/ace/Memory_Pool.h \ + $(ACE_ROOT)/ace/Event_Handler.h \ + $(ACE_ROOT)/ace/Signal.h \ + $(ACE_ROOT)/ace/Mem_Map.h \ + $(ACE_ROOT)/ace/SV_Semaphore_Complex.h \ + $(ACE_ROOT)/ace/SV_Semaphore_Simple.h \ + $(ACE_ROOT)/ace/SV_Semaphore_Simple.i \ + $(ACE_ROOT)/ace/SV_Semaphore_Complex.i \ + $(ACE_ROOT)/ace/Unbounded_Set.h \ + $(ACE_ROOT)/ace/Node.h \ + $(ACE_ROOT)/ace/Node.cpp \ + $(ACE_ROOT)/ace/Unbounded_Set.cpp \ + $(ACE_ROOT)/ace/Unbounded_Set.inl \ + $(ACE_ROOT)/ace/Auto_Ptr.h \ + $(ACE_ROOT)/ace/Auto_Ptr.cpp \ + $(ACE_ROOT)/ace/Auto_Ptr.i \ + $(ACE_ROOT)/ace/String_Base.i \ + $(TAO_ROOT)/tao/Exception.h \ + $(TAO_ROOT)/tao/PolicyC.h \ + $(TAO_ROOT)/tao/Remote_Object_Proxy_Impl.h \ + $(TAO_ROOT)/tao/Object_Proxy_Impl.h \ + $(TAO_ROOT)/tao/Encodable.h \ + $(TAO_ROOT)/tao/Abstract_Servant_Base.h \ + $(ACE_ROOT)/ace/Atomic_Op.h \ + $(ACE_ROOT)/ace/Atomic_Op.cpp \ + $(ACE_ROOT)/ace/Atomic_Op.i + +.obj/PolicyList_Destroyer.o .obj/PolicyList_Destroyer.so .shobj/PolicyList_Destroyer.o .shobj/PolicyList_Destroyer.so: PolicyList_Destroyer.cpp PolicyList_Destroyer.h \ + $(TAO_ROOT)/tao/corbafwd.h \ + $(ACE_ROOT)/ace/CDR_Base.h \ + $(ACE_ROOT)/ace/post.h \ + $(ACE_ROOT)/ace/ace_wchar.h \ + $(ACE_ROOT)/ace/ace_wchar.inl \ + $(ACE_ROOT)/ace/Basic_Types.h \ + $(ACE_ROOT)/ace/ACE_export.h \ + $(ACE_ROOT)/ace/Message_Block.h \ + $(ACE_ROOT)/ace/OS.h \ + $(ACE_ROOT)/ace/OS_Dirent.h \ + $(ACE_ROOT)/ace/OS_Export.h \ + $(ACE_ROOT)/ace/OS_Errno.h \ + $(ACE_ROOT)/ace/OS_String.h \ + $(ACE_ROOT)/ace/OS_Memory.h \ + $(ACE_ROOT)/ace/OS_TLI.h \ + $(ACE_ROOT)/ace/Time_Value.h \ + $(ACE_ROOT)/ace/Default_Constants.h \ + $(ACE_ROOT)/ace/Global_Macros.h \ + $(ACE_ROOT)/ace/Min_Max.h \ + $(ACE_ROOT)/ace/streams.h \ + $(ACE_ROOT)/ace/Trace.h \ + $(ACE_ROOT)/ace/Message_Block_T.h \ + $(ACE_ROOT)/ace/Message_Block_T.cpp \ + $(ACE_ROOT)/ace/Message_Block_T.i \ + $(ACE_ROOT)/ace/CORBA_macros.h \ + $(TAO_ROOT)/tao/orbconf.h \ + $(TAO_ROOT)/tao/varbase.h \ + $(TAO_ROOT)/tao/TAO_Export.h \ + $(TAO_ROOT)/tao/CurrentC.h \ + $(TAO_ROOT)/tao/Object.h \ + $(TAO_ROOT)/tao/Policy_ForwardC.h \ + $(TAO_ROOT)/tao/Sequence.h \ + $(TAO_ROOT)/tao/Managed_Types.h \ + $(ACE_ROOT)/ace/Log_Msg.h \ + $(ACE_ROOT)/ace/Log_Priority.h \ + $(ACE_ROOT)/ace/OS_Log_Msg_Attributes.h \ + $(TAO_ROOT)/tao/Sequence_T.h \ + $(TAO_ROOT)/tao/Sequence_T.cpp \ + $(TAO_ROOT)/tao/Environment.h \ + $(TAO_ROOT)/tao/Sequence_T.i \ + $(TAO_ROOT)/tao/CDR.h \ + $(ACE_ROOT)/ace/CDR_Stream.h \ + $(ACE_ROOT)/ace/SString.h \ + $(ACE_ROOT)/ace/String_Base.h \ + $(ACE_ROOT)/ace/ACE.h \ + $(ACE_ROOT)/ace/Flag_Manip.h \ + $(ACE_ROOT)/ace/Flag_Manip.i \ + $(ACE_ROOT)/ace/Handle_Ops.h \ + $(ACE_ROOT)/ace/Handle_Ops.i \ + $(ACE_ROOT)/ace/Lib_Find.h \ + $(ACE_ROOT)/ace/Lib_Find.i \ + $(ACE_ROOT)/ace/Init_ACE.h \ + $(ACE_ROOT)/ace/Init_ACE.i \ + $(ACE_ROOT)/ace/Sock_Connect.h \ + $(ACE_ROOT)/ace/Sock_Connect.i \ + $(ACE_ROOT)/ace/ACE.i \ + $(ACE_ROOT)/ace/String_Base_Const.h \ + $(ACE_ROOT)/ace/String_Base.cpp \ + $(ACE_ROOT)/ace/Malloc.h \ + $(ACE_ROOT)/ace/Malloc_T.h \ + $(ACE_ROOT)/ace/Synch.h \ + $(ACE_ROOT)/ace/Synch_T.h \ + $(ACE_ROOT)/ace/Synch_T.cpp \ + $(ACE_ROOT)/ace/Thread.h \ + $(ACE_ROOT)/ace/Thread_Adapter.h \ + $(ACE_ROOT)/ace/Base_Thread_Adapter.h \ + $(ACE_ROOT)/ace/Synch_T.i \ + $(ACE_ROOT)/ace/Malloc_Allocator.h \ + $(ACE_ROOT)/ace/Malloc_Base.h \ + $(ACE_ROOT)/ace/Free_List.h \ + $(ACE_ROOT)/ace/Free_List.cpp \ + $(ACE_ROOT)/ace/Free_List.i \ + $(ACE_ROOT)/ace/Malloc_T.cpp \ + $(ACE_ROOT)/ace/Malloc_T.i \ + $(ACE_ROOT)/ace/Memory_Pool.h \ + $(ACE_ROOT)/ace/Event_Handler.h \ + $(ACE_ROOT)/ace/Signal.h \ + $(ACE_ROOT)/ace/Mem_Map.h \ + $(ACE_ROOT)/ace/SV_Semaphore_Complex.h \ + $(ACE_ROOT)/ace/SV_Semaphore_Simple.h \ + $(ACE_ROOT)/ace/SV_Semaphore_Simple.i \ + $(ACE_ROOT)/ace/SV_Semaphore_Complex.i \ + $(ACE_ROOT)/ace/Unbounded_Set.h \ + $(ACE_ROOT)/ace/Node.h \ + $(ACE_ROOT)/ace/Node.cpp \ + $(ACE_ROOT)/ace/Unbounded_Set.cpp \ + $(ACE_ROOT)/ace/Unbounded_Set.inl \ + $(ACE_ROOT)/ace/Auto_Ptr.h \ + $(ACE_ROOT)/ace/Auto_Ptr.cpp \ + $(ACE_ROOT)/ace/Auto_Ptr.i \ + $(ACE_ROOT)/ace/String_Base.i \ + $(TAO_ROOT)/tao/Exception.h \ + $(TAO_ROOT)/tao/Remote_Object_Proxy_Impl.h \ + $(TAO_ROOT)/tao/Object_Proxy_Impl.h \ + $(TAO_ROOT)/tao/Encodable.h \ + PolicyList_Destroyer.inl + +# IF YOU PUT ANYTHING HERE IT WILL GO AWAY diff --git a/TAO/tao/Utils/ORB_Destroyer.cpp b/TAO/tao/Utils/ORB_Destroyer.cpp new file mode 100644 index 00000000000..bab6686e046 --- /dev/null +++ b/TAO/tao/Utils/ORB_Destroyer.cpp @@ -0,0 +1,26 @@ +/** + * @file ORB_Destroyer.cpp + * + * $Id$ + * + * @author Marina Spivak <marina@atdesk.com> + */ + +#include "ORB_Destroyer.h" + +void +TAO::Utils::ORB_Destroyer_Functor::operator() (CORBA::ORB_ptr orb) + ACE_THROW_SPEC (()) +{ + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + orb->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHALL + { + // @@ Cannot let exceptions escape, yet we need to log them! + } + ACE_ENDTRY; +} diff --git a/TAO/tao/Utils/ORB_Destroyer.h b/TAO/tao/Utils/ORB_Destroyer.h new file mode 100644 index 00000000000..35378ab12ac --- /dev/null +++ b/TAO/tao/Utils/ORB_Destroyer.h @@ -0,0 +1,48 @@ +/** + * @file ORB_Destroyer.h + * + * $Id$ + * + * @author Marina Spivak <marina@atdesk.com> + */ +#ifndef ORB_DESTROYER__H_ +#define ORB_DESTROYER__H_ + +#include "Auto_Functor.h" + +#include "tao/ORB.h" + +namespace TAO +{ +namespace Utils +{ + +/** + * @struct ORB_Destroyer_Functor + * + * @brief Implements a functor for the ORB_Destroyer class. + */ +struct ORB_Destroyer_Functor +{ + typedef CORBA::ORB_ptr argument; + + /// Destroy the ORB + void operator() (CORBA::ORB_ptr orb) + ACE_THROW_SPEC (()); +}; + +/** + * @class ORB_Destroyer + * + * @brief Helper class to destroy an ORB. + * + */ +typedef Auto_Functor< + CORBA::ORB, + ORB_Destroyer_Functor> + ORB_Destroyer; + +} // namespace Utils +} // namespace TAO + +#endif // ORB_DESTROYER__H_ diff --git a/TAO/tao/Utils/PolicyList_Destroyer.cpp b/TAO/tao/Utils/PolicyList_Destroyer.cpp new file mode 100644 index 00000000000..eda299c455c --- /dev/null +++ b/TAO/tao/Utils/PolicyList_Destroyer.cpp @@ -0,0 +1,33 @@ +/** + * @file PolicyList_Destroyer.cpp + * + * $Id$ + * + * @author Carlos O'Ryan <coryan@atdesk.com> + */ +#include "PolicyList_Destroyer.h" + +#if !defined (__ACE_INLINE__) +# include "PolicyList_Destroyer.inl" +#endif /* __ACE_INLINE__ */ + +TAO::Utils::PolicyList_Destroyer:: +~PolicyList_Destroyer() +{ + for (CORBA::ULong i = 0; i != length(); ++i) + { + CORBA::Policy_ptr policy = (*this)[i]; + if (CORBA::is_nil(policy)) + { + continue; + } + try + { + policy->destroy(); + } + catch (...) + { + } + (*this)[i] = CORBA::Policy::_nil(); + } +} diff --git a/TAO/tao/Utils/PolicyList_Destroyer.h b/TAO/tao/Utils/PolicyList_Destroyer.h new file mode 100644 index 00000000000..c605c1ff2d8 --- /dev/null +++ b/TAO/tao/Utils/PolicyList_Destroyer.h @@ -0,0 +1,39 @@ +/** + * @file PolicyList_Destroyer.hpp + * + * $Id$ + * + * @author Carlos O'Ryan <coryan@atdesk.com> + */ +#ifndef PolicyList_Destroyer__hpp_ +#define PolicyList_Destroyer__hpp_ + +#include <tao/PolicyC.h> + +namespace TAO +{ +namespace Utils +{ + +/** + * @class PolicyList_Destroyer + * + * @brief Automatically destroy all the policies set in a PolicyList + * + */ +class PolicyList_Destroyer + : public CORBA::PolicyList +{ +public: + PolicyList_Destroyer(CORBA::ULong length_hint); + ~PolicyList_Destroyer(); +}; + +} // namespace Utils +} // namespace TAO + +#if defined (__ACE_INLINE__) +# include "PolicyList_Destroyer.inl" +#endif /* __ACE_INLINE__ */ + +#endif // PolicyList_Destroyer__hpp_ diff --git a/TAO/tao/Utils/PolicyList_Destroyer.inl b/TAO/tao/Utils/PolicyList_Destroyer.inl new file mode 100644 index 00000000000..98ed1107638 --- /dev/null +++ b/TAO/tao/Utils/PolicyList_Destroyer.inl @@ -0,0 +1,7 @@ +// $Id$ + +ACE_INLINE TAO::Utils::PolicyList_Destroyer:: +PolicyList_Destroyer(CORBA::ULong length_hint) + : CORBA::PolicyList(length_hint) +{ +} diff --git a/TAO/tao/Utils/RIR_Narrow.cpp b/TAO/tao/Utils/RIR_Narrow.cpp new file mode 100644 index 00000000000..7376b253e4b --- /dev/null +++ b/TAO/tao/Utils/RIR_Narrow.cpp @@ -0,0 +1,49 @@ +/** + * @file RIR_Narrow.cpp + * + * $Id$ + * + * @author Carlos O'Ryan <coryan@atdesk.com> + */ +#ifndef RIR_Narrow__cpp_ +#define RIR_Narrow__cpp_ + +#include "RIR_Narrow.h" +#include <stdexcept> + +template<class T> TAO::Utils::RIR_Narrow<T>::_ptr_type +TAO::Utils::RIR_Narrow<T>::narrow (CORBA::ORB_ptr orb, + char const * id, + CORBA::Environment &ACE_TRY_ENV) +{ + CORBA::Object_var object = + orb->resolve_initial_references (id, ACE_TRY_ENV); + ACE_CHECK_RETURN (T::_nil ()); + + return RIR_Narrow<T>::narrow_object (object.in (), ACE_TRY_ENV); +} + +template<class T> TAO::Utils::RIR_Narrow<T>::_ptr_type +TAO::Utils::RIR_Narrow<T>::narrow (PortableInterceptor::ORBInitInfo_ptr info, + char const * id) +{ + CORBA::Object_var object = + info->resolve_initial_references (id); + return RIR_Narrow<T>::narrow_object (object.in ()); +} + +template<class T> TAO::Utils::RIR_Narrow<T>::_ptr_type +TAO::Utils::RIR_Narrow<T>::narrow_object (CORBA::Object_ptr object, + CORBA::Environment &ACE_TRY_ENV) +{ + _var_type narrowed_object = T::_narrow (object, ACE_TRY_ENV); + ACE_CHECK_RETURN (T::_nil ()); + + if (CORBA::is_nil (narrowed_object.in ())) + { + ACE_THROW (CORBA::INV_OBJREF ()); + } + return narrowed_object._retn (); +} + +#endif // RIR_Narrow__cpp_ diff --git a/TAO/tao/Utils/RIR_Narrow.h b/TAO/tao/Utils/RIR_Narrow.h new file mode 100644 index 00000000000..8152ddc526d --- /dev/null +++ b/TAO/tao/Utils/RIR_Narrow.h @@ -0,0 +1,56 @@ +/** + * @file RIR_Narrow.hpp + * + * $Id$ + * + * @author Carlos O'Ryan <coryan@atdesk.com> + */ +#ifndef RIR_Narrow__h_ +#define RIR_Narrow__h_ + +#include <tao/ORB.h> +#include <tao/PortableInterceptorC.h> + +namespace TAO +{ +namespace Utils +{ + +/** + * @class RIR_Narrow + * + * @brief Helper class to obtain an initial reference and narrow it + * to the proper object reference. + */ +template<class T> class RIR_Narrow +{ +public: + typedef typename T::_ptr_type _ptr_type; + typedef typename T::_var_type _var_type; + + /// Use resolve_initial_references to find an object and then + /// narrow it. + static _ptr_type narrow (CORBA::ORB_ptr orb, + char const * id, + CORBA::Environment &ACE_TRY_ENV = + TAO_default_environment ()); + + /// Use resolve_initial_references to find an object and then + /// narrow it. + static _ptr_type narrow (PortableInterceptor::ORBInitInfo_ptr orb, + char const * id); + +private: + static _ptr_type narrow_object (CORBA::Object_ptr object, + CORBA::Environment &ACE_TRY_ENV = + TAO_default_environment ()); +}; + +} // namespace Utils +} // namespace TAO + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +# include "RIR_Narrow.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#endif // RIR_Narrow__h_ diff --git a/TAO/tao/Utils/Servant_Var.cpp b/TAO/tao/Utils/Servant_Var.cpp new file mode 100644 index 00000000000..074b6f2429b --- /dev/null +++ b/TAO/tao/Utils/Servant_Var.cpp @@ -0,0 +1,18 @@ +/** + * @file Servant_Var.h + * + * $Id$ + * + * @author Jody Hagins <jody@atdesk.com> + * @author Carlos O'Ryan <coryan@atdesk.com> + */ +#ifndef Servant_Var__cpp_ +#define Servant_Var__cpp_ + +#include "Servant_Var.h" + +#if !defined (__ACE_INLINE__) +# include "Servant_Var.inl" +#endif /* __ACE_INLINE__ */ + +#endif // Servant_Var__cpp_ diff --git a/TAO/tao/Utils/Servant_Var.h b/TAO/tao/Utils/Servant_Var.h new file mode 100644 index 00000000000..4f1424c7dd4 --- /dev/null +++ b/TAO/tao/Utils/Servant_Var.h @@ -0,0 +1,158 @@ +/** + * @file Servant_Var.h + * + * $Id$ + * + * @author Jody Hagins <jody@atdesk.com> + * @author Carlos O'Ryan <coryan@atdesk.com> + */ +#ifndef Servant_Var__hpp_ +#define Servant_Var__hpp_ + +#include "ace/config-all.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +namespace TAO +{ +namespace Utils +{ + +/** + * @class Servant_Var + * + * @brief Provides a type safe counted reference to servants. + * + * @author Jody Hagins + * + * @todo Life would be much easier if _add_ref() and _remove_ref() had + * throw specs of "throw ()", that can be hidden in static + * methods though. + */ +template<class T> +class Servant_Var +{ +public: + typedef T Servant_Type; + + /// Constructor. Assumes ownership of @c p. + Servant_Var(T * p = 0); + + /// Copy constructor. Adds reference to @c rhs. + Servant_Var(Servant_Var<T> const & rhs); + + /// Assignment operator. Adds reference to @c rhs. + Servant_Var<T> & operator=(Servant_Var<T> const & rhs); + + /// Destructor. Removes a reference from the underlying object, + /// possibly destroying it. + ~Servant_Var(); + + /// Assignment operator. Assumes ownership of @c p. + Servant_Var<T> & operator=(T * p); + +# if !defined(ACE_LACKS_MEMBER_TEMPLATES) + /// Template member constructor from a pointer that will implicitly + /// cast to type T. Assumes ownership of @c p. + /// This constructor allows constructs such as: + /// Servant_Base<Base> p(new Derived); + template <class Y> + Servant_Var(Y * p); + + /// Template member copy constructor from a Servant_Var<Y>, where + /// Y can be implicitly cast to type T. + template <class Y> + Servant_Var(Servant_Var<Y> const & rhs); + + /// Template member assignment operator from a Servant_Var<Y>, where + /// Y can be implicitly cast to type T. + template <class Y> + Servant_Var<T> & operator=(Servant_Var<Y> const & rhs); + + /// Template member assignment operator from a pointer to Y, where Y + /// can be implicitly cast to type T. + template <class Y> + Servant_Var<T> & operator=(Y * p); +# endif /* ACE_LACKS_MEMBER_TEMPLATES */ + + /// Smart pointer operator-> provides access to the underlying object. + T const * operator->() const; + + /// Smart pointer operator-> provides access to the underlying object. + T * operator->(); + + /// Dereference the underlying object. + T const & operator*() const; + + /// Dereference the underlying object. + T & operator*(); + + /// Return a void pointer to the underlying object. This allows + /// it to be used in conditional code and tested against 0. + operator void const * () const; + + /// As an IN parameter. + T * in() const; + + /// As an INOUT parameter. + T *& inout(); + + /// As an OUT parameter. + T *& out(); + + // Return a pointer to the underlying object, and this counted + // reference will no longer own the object. + T * _retn(); + + /// Increment the reference count and return the servant. + /** + * It is safe to pass in a null pointer, the pointer is simply + * returned in that case. + * + * @todo We might want to add a throw spec and catch all (potential) + * exceptions in _add_ref() + * + * @todo It might be useful to add an _release() method that handles + * any potential exceptions... + */ + static T * _duplicate (T *); + + /// Swap the contents of a Servant_Var<T> with another + /// Servant_Var<T> + /** + * Often used to implement strong exception safety. + */ + void swap(Servant_Var<T> & rhs) ACE_THROW_SPEC(()); + +private: + T * ptr_; +}; + +/// Compare two Servant_Vars for equivalence. +template <class X, class Y> +bool operator==(Servant_Var<X> const & x, + Servant_Var<Y> const & y); + +/// Compare two Servant_Vars for non-equivalence. +template <class X, class Y> +bool operator!=(Servant_Var<X> const & x, + Servant_Var<Y> const & y); + +} // namespace Utils +} // namespace TAO + +#if defined (__ACE_INLINE__) +# include "Servant_Var.inl" +#endif /* __ACE_INLINE__ */ + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "Servant_Var.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +// Don't use the pragma madness, the compiler(s?) that require it have +// not been supported for a long time (and they could not deal with +// namespace anyway!) + +#endif // Servant_Var__h_ diff --git a/TAO/tao/Utils/Servant_Var.inl b/TAO/tao/Utils/Servant_Var.inl new file mode 100644 index 00000000000..80138c6fae3 --- /dev/null +++ b/TAO/tao/Utils/Servant_Var.inl @@ -0,0 +1,192 @@ +// $Id$ + +#include "ace/Swap.h" + +template <class T> +ACE_INLINE T * TAO::Utils::Servant_Var<T>:: +_duplicate(T * p) +{ + if (p != 0) + { + p->_add_ref(); + } + return p; +} + +template <class T> +ACE_INLINE void +TAO::Utils::Servant_Var<T>::swap(Servant_Var<T> & rhs) ACE_THROW_SPEC(()) +{ + ACE_Swap<T*>::swap(this->ptr_, rhs.ptr_); +} + +template <class T> +ACE_INLINE TAO::Utils::Servant_Var<T>:: +Servant_Var(T * p) + : ptr_(p) +{ +} + +// If _add_ref throws, this object will not be completely constructed +// so the destructor will not be called. +template <class T> +ACE_INLINE TAO::Utils::Servant_Var<T>:: +Servant_Var(Servant_Var<T> const & rhs) + : ptr_(Servant_Var<T>::_duplicate(rhs.ptr_)) +{ +} + +template <class T> +ACE_INLINE TAO::Utils::Servant_Var<T> & TAO::Utils::Servant_Var<T>:: +operator=(Servant_Var<T> const & rhs) +{ + TAO::Utils::Servant_Var<T> tmp(rhs); + this->swap(tmp); + return *this; +} + +template <class T> +ACE_INLINE TAO::Utils::Servant_Var<T> & TAO::Utils::Servant_Var<T>:: +operator=(T * p) +{ + TAO::Utils::Servant_Var<T> tmp(p); + this->swap(tmp); + return *this; +} + +template <class T> +ACE_INLINE TAO::Utils::Servant_Var<T>:: +~Servant_Var() +{ + // Unfortunately, there is no throw spec on _remove_ref, so we + // can't assume that it will not throw. If it does, then we are in + // trouble. In any event, we can't let the exception escape our + // destructor. + if (ptr_ != 0) + { + try + { + ptr_->_remove_ref(); + } + catch (...) + { + } + } +} + +#if !defined(ACE_LACKS_MEMBER_TEMPLATES) +template <class T> template <class Y> +ACE_INLINE TAO::Utils::Servant_Var<T>:: +Servant_Var(Y * p) + : ptr_(p) +{ +} + +template <class T> template <class Y> +ACE_INLINE TAO::Utils::Servant_Var<T>:: +Servant_Var(Servant_Var<Y> const & rhs) + : ptr_(Servant_Var<T>::_duplicate(rhs.in())) +{ +} + +template <class T> template <class Y> +ACE_INLINE TAO::Utils::Servant_Var<T> & TAO::Utils::Servant_Var<T>:: +operator=(Servant_Var<Y> const & rhs) +{ + TAO::Utils::Servant_Var<T> tmp(rhs); + this->swap(tmp); + return *this; +} + +template <class T> template <class Y> +ACE_INLINE TAO::Utils::Servant_Var<T> & TAO::Utils::Servant_Var<T>:: +operator=(Y * p) +{ + TAO::Utils::Servant_Var<T> tmp(p); + this->swap(tmp); + return *this; +} +#endif /* ACE_LACKS_MEMBER_TEMPLATES */ + +template <class T> +ACE_INLINE T const * TAO::Utils::Servant_Var<T>:: +operator->() const +{ + return ptr_; +} + +template <class T> +ACE_INLINE T * TAO::Utils::Servant_Var<T>:: +operator->() +{ + return ptr_; +} + +template <class T> +ACE_INLINE T const & TAO::Utils::Servant_Var<T>:: +operator*() const +{ + return *ptr_; +} + +template <class T> +ACE_INLINE T & TAO::Utils::Servant_Var<T>:: +operator*() +{ + return *ptr_; +} + +template <class T> +ACE_INLINE TAO::Utils::Servant_Var<T>:: +operator void const * () const +{ + return ptr_; +} + +template <class T> +ACE_INLINE T * TAO::Utils::Servant_Var<T>:: +in() const +{ + return ptr_; +} + +template <class T> +ACE_INLINE T *& TAO::Utils::Servant_Var<T>:: +inout() +{ + return ptr_; +} + +template <class T> +ACE_INLINE T *& TAO::Utils::Servant_Var<T>:: +out() +{ + TAO::Utils::Servant_Var<T> tmp; + this->swap(tmp); + return ptr_; +} + +template <class T> +ACE_INLINE T * TAO::Utils::Servant_Var<T>:: +_retn() +{ + T * rval = ptr_; + ptr_ = 0; + return rval; +} + +template <class X, class Y> +ACE_INLINE bool +operator==(TAO::Utils::Servant_Var<X> const & x, + TAO::Utils::Servant_Var<Y> const & y) +{ + return x.in() == y.in(); +} + +template <class X, class Y> +ACE_INLINE bool +operator!=(TAO::Utils::Servant_Var<X> const & x, + TAO::Utils::Servant_Var<Y> const & y) +{ + return x.in() != y.in(); +} |