summaryrefslogtreecommitdiff
path: root/TAO/tao/AnyTypeCode/Recursive_Type_TypeCode.cpp
blob: e35d3bad7813c7a17a4d1967e88283c08dacaf41 (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
// $Id$

#include "tao/CDR.h"

#ifndef __ACE_INLINE__
# include "tao/AnyTypeCode/Recursive_Type_TypeCode.inl"
#endif  /* __ACE_INLINE__ */

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

template <class TypeCodeBase, typename TypeCodeType, typename MemberArrayType>
bool
TAO::TypeCode::Recursive_Type<TypeCodeBase,
                              TypeCodeType,
                              MemberArrayType>::tao_marshal (
  TAO_OutputCDR & cdr,
  CORBA::ULong offset) const
{
  ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
                    guard,
                    this->lock_,
                    false);

  // Top-level TypeCode case.
  if (!(this->in_recursion_))
    {
      this->in_recursion_ = true;

      // Starting offset should point to the CORBA::TCKind value.

      // Note that this doesn't need to take into account alignment
      // padding since CORBA::TCKind (encoded as a CORBA::ULong) is
      // already aligned on the appropriate boundary, and since the
      // CORBA::TCKind was the last thing marshaled into the CDR
      // stream before getting here.
      offset = sizeof (CORBA::ULong);

      // Reset recursion flag to false in an exception-safe manner once
      // marshaling is done.
      //
      // Only reset the recursion flag at the top-level.
      Reset flag (this->in_recursion_);

      return this->TypeCodeBase::tao_marshal (cdr, offset);
    }

  // Recursive/indirected TypeCode case.

//   ACE_ASSERT (offset > 4
//               && offset < static_cast<CORBA::ULong> (ACE_INT32_MAX));

  return (cdr << -static_cast<CORBA::Long> (offset));
}

template <class TypeCodeBase, typename TypeCodeType, typename MemberArrayType>
CORBA::Boolean
TAO::TypeCode::Recursive_Type<TypeCodeBase,
                              TypeCodeType,
                              MemberArrayType>::equal_i (
  CORBA::TypeCode_ptr tc
  ) const
{
  ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
                    guard,
                    this->lock_,
                    false);

  // Top-level TypeCode case.
  if (!(this->in_recursion_))
    {
      this->in_recursion_ = true;

      // Reset recursion flag to false in an exception-safe manner once
      // equality determination is done.
      //
      // Only reset the recursion flag at the top-level.
      Reset flag (this->in_recursion_);

      return this->TypeCodeBase::equal_i (tc
                                         );
    }

  // Nothing else to do.
  return true;
}

template <class TypeCodeBase, typename TypeCodeType, typename MemberArrayType>
CORBA::Boolean
TAO::TypeCode::Recursive_Type<TypeCodeBase,
                              TypeCodeType,
                              MemberArrayType>::equivalent_i (
  CORBA::TypeCode_ptr tc
  ) const
{
  ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
                    guard,
                    this->lock_,
                    false);

  // Top-level TypeCode case.
  if (!(this->in_recursion_))
    {
      this->in_recursion_ = true;

      // Reset recursion flag to false in an exception-safe manner once
      // equivalence determination is done.
      //
      // Only reset the recursion flag at the top-level.
      Reset flag (this->in_recursion_);

      return this->TypeCodeBase::equivalent_i (tc
                                              );
    }

  // Nothing else to do.
  return true;
}

template <class TypeCodeBase, typename TypeCodeType, typename MemberArrayType>
bool
TAO::TypeCode::Recursive_Type<TypeCodeBase,
                              TypeCodeType,
                              MemberArrayType>::tao_marshal_kind (
  TAO_OutputCDR & cdr) const
{
  ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
                    guard,
                    this->lock_,
                    false);

  // Top-level TypeCode case.
  if (!(this->in_recursion_))
    return this->::CORBA::TypeCode::tao_marshal_kind (cdr);

  // Recursive/indirected TypeCode case.
  CORBA::ULong const indirection_kind = 0xffffffff;

  return (cdr << indirection_kind);
}

TAO_END_VERSIONED_NAMESPACE_DECL