summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_sequence/cdr_op_cs.cpp
blob: a0a8a3d77977c653bef0f0a6d78c96a48d7d5c37 (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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317

//=============================================================================
/**
 *  @file    cdr_op_cs.cpp
 *
 *  Visitor for code generation of Sequences for the CDR operators
 *  in the client stubs.
 *
 *  @author Aniruddha Gokhale
 */
//=============================================================================

#include "sequence.h"

// ***************************************************************************
// Sequence visitor for generating CDR operator declarations in the client
// stubs file.
// ***************************************************************************

be_visitor_sequence_cdr_op_cs::be_visitor_sequence_cdr_op_cs (
    be_visitor_context *ctx
  )
  : be_visitor_decl (ctx)
{
}

be_visitor_sequence_cdr_op_cs::~be_visitor_sequence_cdr_op_cs ()
{
}

int
be_visitor_sequence_cdr_op_cs::visit_sequence (be_sequence *node)
{
  if (this->ctx_->alias ())
    {
      // We are here because the base type of the sequence node is
      // itself a sequence i.e., this is a case of sequence of
      // typedef'd sequence. For the case of sequence of
      // anonymous sequence, see comment below.
      return this->visit_node (node);
    }

  if (node->cli_stub_cdr_op_gen ()
      || node->imported ()
      || node->is_local ())
    {
      return 0;
    }

  if (idl_global->dcps_sequence_type_defined (node->full_name ()))
    {
      return 0;
    }

  TAO_OutStream *os = this->ctx_->stream ();

  be_type *bt =
    dynamic_cast<be_type*> (node->base_type ());

  if (!bt)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "be_visitor_sequence_cdr_op_cs::"
                         "visit_sequence - "
                         "Bad base type\n"),
                        -1);
    }

  // Generate the CDR << and >> operator defns.

  // Save the sequence node for further use.
  this->ctx_->node (node);

  // If our element type is an anonymous sequence, generate code for it here.
  if (bt->node_type () == AST_Decl::NT_sequence)
    {
      int status =
          this->gen_anonymous_base_type (
              bt,
              TAO_CodeGen::TAO_ROOT_CDR_OP_CS);

      if (status == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_array_cdr_op_cs::"
                             "visit_sequence - "
                             "gen_anonymous_base_type failed\n"),
                            -1);
        }
    }

  TAO_INSERT_COMMENT (os);

  *os << "#if !defined _TAO_CDR_OP_"
      << node->flat_name () << "_CPP_" << be_nl
      << "#define _TAO_CDR_OP_" << node->flat_name () << "_CPP_"
      << be_nl;

  bool alt = be_global->alt_mapping ();

  *os << be_global->core_versioning_begin () << be_nl;

  //  Set the sub state as generating code for the output operator.
  this->ctx_->sub_state (TAO_CodeGen::TAO_CDR_OUTPUT);

  if (alt)
    {
      *os << "::CORBA::Boolean operator<< (" << be_idt_nl
          << "TAO_OutputCDR &strm," << be_nl
          << "const std::vector<" << bt->full_name ()
          << "> &_tao_vector)"
          << be_uidt_nl
          << "{" << be_idt_nl
          << "::CORBA::ULong length = _tao_vector.size ();"
          << be_nl
          << "strm << length;" << be_nl_2
          << "for ( ::CORBA::ULong i = 0UL; i < length; ++i)"
          << be_idt_nl
          << "{" << be_idt_nl
          << "if (! (strm << _tao_vector[i]))" << be_idt_nl
          << "{" << be_idt_nl
          << "return false;" << be_uidt_nl
          << "}" << be_uidt << be_uidt_nl
          << "}" << be_uidt_nl << be_nl
          << "return true;" << be_uidt_nl
          << "}" << be_nl_2;
    }
  else
    {
      *os << "::CORBA::Boolean operator<< ("
          << be_idt << be_idt_nl
          << "TAO_OutputCDR &strm," << be_nl
          << "const " << node->name () << " &_tao_sequence)"
          << be_uidt
          << be_uidt_nl
          << "{" << be_idt_nl
          << "return TAO::marshal_sequence(strm, _tao_sequence);"
          << be_uidt_nl
          << "}" << be_nl_2;
        }

  //  Set the sub state as generating code for the input operator.
  this->ctx_->sub_state(TAO_CodeGen::TAO_CDR_INPUT);

  if (alt)
    {
      *os << "::CORBA::Boolean operator>> (" << be_idt_nl
          << "TAO_InputCDR &strm," << be_nl
          << "std::vector<" << bt->full_name ()
          << "> &_tao_vector)" << be_uidt_nl
          << "{" << be_idt_nl
          << "::CORBA::ULong length = 0UL;" << be_nl
          << bt->full_name ();

      if (bt->size_type () == AST_Type::VARIABLE)
        {
          *os << " *";
        }

      *os << " tmp;" << be_nl_2
          << "if (! (strm >> length))" << be_idt_nl
          << "{" << be_idt_nl
          << "return false;" << be_uidt_nl
          << "}" << be_uidt_nl << be_nl
          << "_tao_vector.resize (length);" << be_nl_2
          << "for ( ::CORBA::ULong i = 0UL; i < length; ++i)"
          << be_idt_nl
          << "{" << be_idt_nl
          << "if (! (strm >> tmp))" << be_idt_nl
          << "{" << be_idt_nl
          << "return false;" << be_uidt_nl
          << "}" << be_uidt_nl << be_nl
          << "_tao_vector[i] = tmp;" << be_uidt_nl
          << "}" << be_uidt_nl << be_nl
          << "return true;" << be_uidt_nl
          << "}" << be_nl;
    }
  else
    {
      *os << "::CORBA::Boolean operator>> ("
          << be_idt << be_idt_nl
          << "TAO_InputCDR &strm"
          << "," << be_nl
          << node->name ()
          << " &_tao_sequence)"
          << be_uidt
          << be_uidt_nl
          << "{" << be_idt_nl
          << "return TAO::demarshal_sequence(strm, _tao_sequence);"
          << be_uidt_nl
          << "}" << be_nl;
    }

  if (be_global->gen_ostream_operators ())
    {
      node->gen_ostream_operator (os, false);
    }

  *os << be_nl << be_global->core_versioning_end ();

  *os << be_nl
      << "#endif /* _TAO_CDR_OP_"
      << node->flat_name () << "_CPP_ */";

  node->cli_stub_cdr_op_gen (true);
  return 0;
}

int
be_visitor_sequence_cdr_op_cs::visit_array (be_array *node)
{
  return this->visit_node (node);
}

int
be_visitor_sequence_cdr_op_cs::visit_enum (be_enum *node)
{
  return this->visit_node (node);
}

int
be_visitor_sequence_cdr_op_cs::visit_interface (be_interface *node)
{
  return this->visit_node (node);
}

int
be_visitor_sequence_cdr_op_cs::visit_interface_fwd (be_interface_fwd *node)
{
  return this->visit_node (node);
}

int
be_visitor_sequence_cdr_op_cs::visit_component (be_component *node)
{
  return this->visit_node (node);
}

int
be_visitor_sequence_cdr_op_cs::visit_component_fwd (be_component_fwd *node)
{
  return this->visit_node (node);
}

int
be_visitor_sequence_cdr_op_cs::visit_home (be_home *node)
{
  return this->visit_node (node);
}

int
be_visitor_sequence_cdr_op_cs::visit_valuebox (be_valuebox *node)
{
  return this->visit_node (node);
}

int
be_visitor_sequence_cdr_op_cs::visit_valuetype (be_valuetype *node)
{
  return this->visit_node (node);
}

int
be_visitor_sequence_cdr_op_cs::visit_valuetype_fwd (be_valuetype_fwd *node)
{
  return this->visit_node (node);
}

int
be_visitor_sequence_cdr_op_cs::visit_eventtype (be_eventtype *node)
{
  return this->visit_node (node);
}

int
be_visitor_sequence_cdr_op_cs::visit_eventtype_fwd (be_eventtype_fwd *node)
{
  return this->visit_node (node);
}

int
be_visitor_sequence_cdr_op_cs::visit_predefined_type (
    be_predefined_type *node
  )
{
  return this->visit_node (node);
}

int
be_visitor_sequence_cdr_op_cs::visit_string (be_string *node)
{
  return this->visit_node (node);
}

int
be_visitor_sequence_cdr_op_cs::visit_structure (be_structure *node)
{
  return this->visit_node (node);
}

int
be_visitor_sequence_cdr_op_cs::visit_union (be_union *node)
{
  return this->visit_node (node);
}

int
be_visitor_sequence_cdr_op_cs::visit_typedef (be_typedef *node)
{
  return this->visit_node (node);
}

int
be_visitor_sequence_cdr_op_cs::visit_node (be_type *)
{
  return 0;
}