summaryrefslogtreecommitdiff
path: root/TAO/tao/Valuetype/AbstractBase_T.cpp
blob: 97e62fb07c14a3d16c4d5c496131bfe226531bc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// $Id$
#ifndef TAO_ABSTRACT_BASE_T_C
#define TAO_ABSTRACT_BASE_T_C

#include "AbstractBase_T.h"
#include "AbstractBase.h"
#include "Stub.h"

ACE_RCSID (Valuetype,
           Abstractbase_T,
           "$Id$")
namespace TAO
{
  template<typename T> T *
  AbstractBase_Narrow_Utils<T>::narrow (
      CORBA::AbstractBase_ptr obj,
      const char *repo_id,
      Proxy_Broker_Factory pbf
      ACE_ENV_ARG_DECL)
  {
    if (CORBA::AbstractBase::is_nil (obj))
      {
        return T::_nil ();
      }

    CORBA::Boolean is_it =
      obj->_is_a (
          repo_id
          ACE_ENV_ARG_PARAMETER
        );
    ACE_CHECK_RETURN (T::_nil ());

    if (is_it == 0)
      {
        return T::_nil ();
      }

    return AbstractBase_Narrow_Utils<T>::unchecked_narrow (obj,
                                                           pbf);
  }

  template<typename T>  T *
  AbstractBase_Narrow_Utils<T>::unchecked_narrow (
      CORBA::AbstractBase_ptr obj,
      Proxy_Broker_Factory pbf)
  {
    if (CORBA::AbstractBase::is_nil (obj))
      {
        return T::_nil ();
      }

    T_ptr proxy = T::_nil ();

    if (obj->_is_objref ())
      {
        TAO_Stub* stub = obj->_stubobj ();

        bool collocated =
          !CORBA::is_nil (stub->servant_orb_var ().ptr ())
          && stub->servant_orb_var ()->orb_core ()->optimize_collocation_objects ()
          && obj->_is_collocated ()
          && pbf != 0;

        ACE_NEW_RETURN (proxy,
                        T (obj->_stubobj (),
                           collocated ? 1 : 0,
                           obj->_servant ()),
                        T::_nil ());
      }
    else
      {
        proxy = T::_downcast (obj);
        proxy->_add_ref ();
      }

    return proxy;
  }
}