Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Object_T.cpp
blob359910e0dafb0aa8a82fbca27867c0304770b942
1 #ifndef TAO_OBJECT_T_CPP
2 #define TAO_OBJECT_T_CPP
4 #include "tao/Object_T.h"
5 #include "tao/Object.h"
6 #include "tao/Stub.h"
7 #include "tao/SystemException.h"
8 #include "ace/CORBA_macros.h"
10 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
12 namespace TAO
14 template<typename T>
15 T *
16 Narrow_Utils<T>::narrow (CORBA::Object_ptr obj,
17 const char *repo_id)
19 if (CORBA::is_nil (obj))
21 return T::_nil ();
24 if (!obj->_is_a (repo_id))
26 return T::_nil ();
29 return TAO::Narrow_Utils<T>::unchecked_narrow (obj);
32 template<typename T> T *
33 Narrow_Utils<T>::unchecked_narrow (CORBA::Object_ptr obj)
35 if (CORBA::is_nil (obj))
37 return T::_nil ();
40 if (obj->_is_local ())
42 return T::_duplicate (dynamic_cast<T *> (obj));
45 T_ptr proxy = T::_nil ();
46 try
48 proxy = Narrow_Utils<T>::lazy_evaluation (obj);
50 if (CORBA::is_nil (proxy))
52 TAO_Stub* stub = obj->_stubobj ();
54 if (stub != 0)
56 stub->_incr_refcnt ();
58 bool const collocated =
59 !CORBA::is_nil (stub->servant_orb_var ().in ())
60 && stub->optimize_collocation_objects ()
61 && obj->_is_collocated ();
63 ACE_NEW_RETURN (proxy,
64 T (stub,
65 collocated,
66 obj->_servant ()),
67 T::_nil ());
71 catch (const CORBA::Exception&)
73 // Swallow the exception
74 return T::_nil ();
77 return proxy;
80 template<typename T>
81 T *
82 Narrow_Utils<T>::lazy_evaluation (CORBA::Object_ptr obj)
84 T_ptr default_proxy = T::_nil ();
86 // Code for lazily evaluated IORs.
87 if (!obj->is_evaluated ())
89 ACE_NEW_RETURN (default_proxy,
90 T (obj->steal_ior (),
91 obj->orb_core ()),
92 T::_nil ());
95 return default_proxy;
99 TAO_END_VERSIONED_NAMESPACE_DECL
101 #endif /* TAO_OBJECT_T_CPP */