summaryrefslogtreecommitdiff
path: root/TAO/tao/AnyTypeCode/Any_Impl.cpp
blob: b1867d468e3fbfcf03bcd9f9928bbcebeb0bd1d1 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// -*- C++ -*-
#include "tao/AnyTypeCode/Any_Impl.h"
#include "tao/AnyTypeCode/TypeCode.h"
#include "tao/AnyTypeCode/Marshal.h"
#include "tao/ORB_Core.h"
#include "tao/Valuetype_Adapter.h"

#include "tao/CORBA_String.h"
#include "tao/SystemException.h"

#include "ace/Guard_T.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

TAO::Any_Impl::Any_Impl (_tao_destructor destructor,
                         CORBA::TypeCode_ptr tc,
                         bool encoded)
  : value_destructor_ (destructor)
  , type_ (CORBA::TypeCode::_duplicate (tc))
  , encoded_ (encoded)
  , refcount_ (1)
{
}

TAO::Any_Impl::~Any_Impl ()
{
}

CORBA::Boolean
TAO::Any_Impl::marshal (TAO_OutputCDR &cdr)
{
  CORBA::ValueBase * vb = 0;
  if (this->to_value (vb) && vb)
    {
      // Since we ARE a value type, we need to
      // send the ACTUAL derived typecode for
      // the type we are marshaling NOT the
      // typecode of the base pointer that may
      // have been inserted into the any.
      if ((cdr << TAO_ORB_Core_instance ()
                  ->valuetype_adapter()
                  ->derived_type (vb)) == 0)
        {
          return false;
        }
    }
  // Otherwise send the typecode of the inserted type.
  else if ((cdr << this->type_) == 0)
    {
      return false;
    }

  // Once the typecode has been marshaled send the actual
  // value (this is polymorphic for valuetypes)
  return this->marshal_value (cdr);
}

void
TAO::Any_Impl::free_value ()
{
  // We always have to do this.
  ::CORBA::release (this->type_);
}

CORBA::TypeCode_ptr
TAO::Any_Impl::type () const
{
  return CORBA::TypeCode::_duplicate (this->type_);
}

CORBA::TypeCode_ptr
TAO::Any_Impl::_tao_get_typecode () const
{
  return this->type_;
}

void
TAO::Any_Impl::type (CORBA::TypeCode_ptr tc)
{
  ::CORBA::release (this->type_);
  this->type_ = CORBA::TypeCode::_duplicate (tc);
}

int
TAO::Any_Impl::_tao_byte_order () const
{
  return TAO_ENCAP_BYTE_ORDER;
}

void
TAO::Any_Impl::_tao_any_string_destructor (void *x)
{
  char *tmp = static_cast<char *> (x);
  CORBA::string_free (tmp);
}

void
TAO::Any_Impl::_tao_any_wstring_destructor (void *x)
{
  CORBA::WChar *tmp = static_cast<CORBA::WChar *> (x);
  CORBA::wstring_free (tmp);
}

void
TAO::Any_Impl::_add_ref ()
{
  ++this->refcount_;
}

void
TAO::Any_Impl::_remove_ref ()
{
  CORBA::ULong const new_count = --this->refcount_;

  if (new_count != 0)
    return;

  this->free_value ();

  delete this;
}

void
TAO::Any_Impl::_tao_decode (TAO_InputCDR &)
{
  throw ::CORBA::NO_IMPLEMENT ();
}

CORBA::Boolean
TAO::Any_Impl::to_object (CORBA::Object_ptr &) const
{
  return false;
}

CORBA::Boolean
TAO::Any_Impl::to_value (CORBA::ValueBase *&) const
{
  return false;
}

CORBA::Boolean
TAO::Any_Impl::to_abstract_base (CORBA::AbstractBase_ptr &) const
{
  return false;
}

bool
TAO::Any_Impl::encoded () const
{
  return this->encoded_;
}

TAO_END_VERSIONED_NAMESPACE_DECL