summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_valuebox/valuebox_cs.cpp
blob: 91d897f3cd43e53b29cad3fbfb500ae8c6dd6866 (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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773

//=============================================================================
/**
 *  @file    valuebox_cs.cpp
 *
 *  Visitor generating code for valueboxes in the client stub file
 *
 *  @author Gary Maxey
 */
//=============================================================================

#include "valuebox.h"

be_visitor_valuebox_cs::be_visitor_valuebox_cs (be_visitor_context *ctx)
  : be_visitor_valuebox (ctx)
{
}

be_visitor_valuebox_cs::~be_visitor_valuebox_cs ()
{
}

int
be_visitor_valuebox_cs::visit_valuebox (be_valuebox *node)
{
  // Nothing to do if we are imported or code is already generated.
  if (node->cli_stub_gen () || node->imported ())
    {
      return 0;
    }

  if (be_global->tc_support ())
    {
      be_visitor_context ctx (*this->ctx_);
      TAO::be_visitor_alias_typecode visitor (&ctx);

      if (node->accept (&visitor) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_valuebox_cs::"
                             "visit_valuebox - "
                             "TypeCode definition failed\n"),
                            -1);
        }
    }

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

  this->ctx_->node (node); // save the node

  *os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl
      << "// " << __FILE__ << ":" << __LINE__;

  if (node->is_defined ())
    {
      *os << be_nl_2
          << "void" << be_nl
          << "TAO::Value_Traits<" << node->name  () << ">::add_ref ("
          << node->name () << " * p)"
          << be_nl
          << "{" << be_idt_nl
          << "::CORBA::add_ref (p);" << be_uidt_nl
          << "}";

      *os << be_nl_2
          << "void" << be_nl
          << "TAO::Value_Traits<" << node->name () << ">::remove_ref ("
          << node->name () << " * p)" << be_nl
          << "{" << be_idt_nl
          << "::CORBA::remove_ref (p);" << be_uidt_nl
          << "}";

      *os << be_nl_2
          << "void" << be_nl
          << "TAO::Value_Traits<" << node->name () << ">::release ("
          << node->name () << " * p)"  << be_nl
          << "{" << be_idt_nl
          << "::CORBA::remove_ref (p);" << be_uidt_nl
          << "}";
    }

  // The _downcast method.
  *os << be_nl_2
      << node->name () << " *" << be_nl
      << node->name () << "::_downcast ( ::CORBA::ValueBase *v)" << be_nl
      << "{" << be_idt_nl
      << "return dynamic_cast< ::" << node->name () << " * > (v);"
      << be_uidt_nl << "}" << be_nl_2;

  // _copy_value method
  *os << "::CORBA::ValueBase *" << be_nl
      << node->name () << "::_copy_value ()" << be_nl
      << "{" << be_idt_nl
      << "::CORBA::ValueBase *result = 0;" << be_nl
      << "ACE_NEW_RETURN (" << be_idt_nl
      << "result," << be_nl
      << node->local_name () << " (*this)," << be_nl
      << "0);" << be_nl << be_uidt_nl
      << "return result;" << be_uidt_nl
      << "}" << be_nl_2;

  // The _tao_obv_repository_id method.
  *os << "const char *" << be_nl
      << node->name () << "::_tao_obv_repository_id () const"
      << be_nl << "{" << be_idt_nl
      << "return this->_tao_obv_static_repository_id ();" << be_uidt_nl
      << "}" << be_nl_2;

  *os << "void" << be_nl
      << node->name ()
      << "::_tao_obv_truncatable_repo_ids (Repository_Id_List& ids) const"
      << be_nl
      << "{" << be_idt_nl
      << "ids.push_back (this->_tao_obv_static_repository_id ());"
      << be_uidt_nl
      << "}" << be_nl_2;

  // _tao_match_formal_type method.  Generated because ValueBase interface
  // requires it. Since value boxes do not support inheritence, this can
  // simply return true.
  *os << "::CORBA::Boolean" << be_nl
      << node->name ()
      << "::_tao_match_formal_type (ptrdiff_t) const" << be_nl
      << "{" << be_idt_nl
      << "return true;" << be_uidt_nl
      << "}" << be_nl_2;


  if (be_global->any_support ())
    {
      *os << "void" << be_nl
          << node->name ()
          << "::_tao_any_destructor (void *_tao_void_pointer)" << be_nl
          << "{" << be_idt_nl
          << node->local_name () << " *_tao_tmp_pointer =" << be_idt_nl
          << "static_cast<" << be_idt
          << node->local_name () << " *> ("
          << "_tao_void_pointer);" << be_uidt << be_uidt_nl
          << "::CORBA::remove_ref (_tao_tmp_pointer);" << be_uidt_nl
          << "}" << be_nl_2;
    }

  // Switch streams to the *A.cpp file if we are using this option.
  if (be_global->gen_anyop_files ())
    {
      os = tao_cg->anyop_source ();
    }

  if (be_global->tc_support ())
    {
      *os << "// TAO extension - the virtual _type method." << be_nl;
      *os << "::CORBA::TypeCode_ptr " << node->name ()
          << "::_tao_type () const" << be_nl;
      *os << "{" << be_idt_nl;
      *os << "return ::" << node->tc_name () << ";" << be_uidt_nl;
      *os << "}" << be_nl_2;
    }

  // Make sure we are generating to *C.cpp regardless of the above.
  os = tao_cg->client_stubs ();

  AST_Type * at = node->boxed_type()->unaliased_type();
  be_type *bt = dynamic_cast<be_type*> (at);

  if (!bt)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_valuebox_cs::"
                         "visit_valuebox - "
                         "Bad type\n"),
                        -1);
    }

  bool is_array = false;
  const char * unmarshal_arg;
  be_predefined_type *bpt = dynamic_cast<be_predefined_type*> (bt);

  if (bpt != nullptr)
    {
      switch (bpt->pt())
        {
        case AST_PredefinedType::PT_boolean:
          unmarshal_arg =
            "::ACE_InputCDR::to_boolean (vb_object->_pd_value)";
          break;

        case AST_PredefinedType::PT_char:
          unmarshal_arg =
            "::ACE_InputCDR::to_char (vb_object->_pd_value)";
          break;

        case AST_PredefinedType::PT_wchar:
          unmarshal_arg =
            "::ACE_InputCDR::to_wchar (vb_object->_pd_value)";
          break;

        case AST_PredefinedType::PT_octet:
          unmarshal_arg =
            "::ACE_InputCDR::to_octet (vb_object->_pd_value)";
          break;

        case AST_PredefinedType::PT_uint8:
          unmarshal_arg =
            "::ACE_InputCDR::to_uint8 (vb_object->_pd_value)";
          break;

        case AST_PredefinedType::PT_int8:
          unmarshal_arg =
            "::ACE_InputCDR::to_int8 (vb_object->_pd_value)";
          break;

        case AST_PredefinedType::PT_any:
          // We need to help the ">>" operator for "any" because
          // a conversion operator is not available.
          unmarshal_arg = "vb_object->_pd_value.inout ()";
          break;

        default:
          unmarshal_arg = "vb_object->_pd_value";
        }
    }
  else if (dynamic_cast<be_array*> (bt) != nullptr)
    {
      is_array = true;
      unmarshal_arg = "temp";
    }
  else
    {
      unmarshal_arg = "vb_object->_pd_value";
    }

  // The _tao_unmarshal method.
  *os << "::CORBA::Boolean" << be_nl
      << node->name () << "::_tao_unmarshal (" << be_idt << be_idt_nl
      << "TAO_InputCDR &strm," << be_nl
      << node->local_name () << " *&vb_object" << be_uidt_nl
      << ")" << be_uidt_nl
      << "{" << be_idt_nl
      << "::CORBA::Boolean is_null_object = false;" << be_nl
      << "::CORBA::Boolean is_indirected = false;" << be_nl
      << "TAO_InputCDR indrected_strm ((size_t) 0);" << be_nl
      << "if ( ::CORBA::ValueBase::_tao_validate_box_type (" << be_idt
      << be_idt << be_idt_nl
      << "strm, indrected_strm," << be_nl
      << node->local_name () << "::_tao_obv_static_repository_id (),"
      << be_nl
      << "is_null_object, is_indirected"
      << be_uidt_nl
      << ") == false)" << be_uidt_nl
      << "{" << be_idt_nl
      << "return false;" << be_uidt_nl
      << "}" << be_uidt_nl << be_nl
      << "vb_object = 0;" << be_nl
      << "if (is_null_object)"  << be_idt_nl
      << "{" << be_idt_nl
      << "return true;" << be_uidt_nl
      << "}" << be_uidt_nl << be_nl
      << "if (is_indirected)"  << be_idt_nl
      << "{" << be_idt_nl
      << "return " << node->name () << "::_tao_unmarshal (" << be_idt
      << be_idt << be_idt_nl
      << " indrected_strm, vb_object);"
      << be_uidt << be_uidt << be_uidt << be_uidt_nl
      << "}" << be_uidt_nl << be_nl
      << "ACE_NEW_RETURN (" << be_idt_nl
      << "vb_object," << be_nl
      << node->local_name () << "," << be_nl
      << "false);" << be_uidt_nl << be_nl;

  if (is_array)
    {
      *os << at->full_name()
          << "_forany temp (vb_object->_boxed_inout ());" << be_nl;
    }

  *os << "return (strm >> ";

  be_string *str = dynamic_cast<be_string*> (bt);
  if (str != nullptr &&
      str->max_size ()->ev ()->u.ulval != 0)
    {
      if (str->width () == (long) sizeof (char))
        {
          *os << "::ACE_InputCDR::to_string "
              << "(vb_object->_pd_value, "
              << str->max_size ()->ev ()->u.ulval << ")";
        }
      else
        {
          *os << "::ACE_InputCDR::to_wstring "
              << "(vb_object->_pd_value, "
              << str->max_size ()->ev ()->u.ulval << ")";
        }
    }
  else
    {
      *os << unmarshal_arg;
    }

  *os << ");" << be_uidt_nl
      << "}" << be_nl_2;

  // _tao_unmarshal_v method.  Generated because ValueBase interface
  // requires it.  But there is nothing for it to do in the valuebox
  // case.
  *os << "::CORBA::Boolean" << be_nl
      << node->name ()
      << "::_tao_unmarshal_v (TAO_InputCDR &)" << be_nl
      << "{" << be_idt_nl
      << "return true;" << be_uidt_nl
      << "}" << be_nl_2;

  // Emit the type specific elements.  The visit_* methods in this
  // module do that work.
  if (bt->accept (this) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         " (%N:%l) be_visitor_valuebox_cs::visit_valuebox - "
                         "type-specific valuebox code generation failed\n"),
                        -1);
    }

  // Indicate that code is already generated for this node.
  node->cli_stub_gen (true);

  return 0;
}

int
be_visitor_valuebox_cs::visit_array (be_array * node)
{
  TAO_OutStream & os = *this->ctx_->stream ();

  // Retrieve the node being visited by this be_visitor_valuebox_cs.
  be_decl * const vb_node = this->ctx_->node ();

  os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl
     << "// " << __FILE__ << ":" << __LINE__ << be_nl_2;

  this->emit_destructor ();

  // _tao_marshal_v method
  os << "::CORBA::Boolean" << be_nl
     << vb_node->name ()
     << "::_tao_marshal_v (TAO_OutputCDR & strm) const" << be_nl
     << "{" << be_idt_nl
     << node->name () << "_forany temp (this->_pd_value.ptr ());"
     << be_nl
     << "return (strm << temp);" << be_uidt_nl
     << "}" << be_nl_2;

  return 0;
}

int
be_visitor_valuebox_cs::visit_enum (be_enum *)
{
  TAO_OutStream & os = *this->ctx_->stream ();

  // Retrieve the node being visited by this be_visitor_valuebox_cs.
  be_decl * const vb_node = this->ctx_->node ();

  os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl
     << "// " << __FILE__ << ":" << __LINE__ << be_nl_2;

  this->emit_destructor ();

  static char const marshal_arg[] = "this->_pd_value";

  // _tao_marshal_v method
  os << "::CORBA::Boolean" << be_nl
     << vb_node->name ()
     << "::_tao_marshal_v (TAO_OutputCDR & strm) const" << be_nl
     << "{" << be_idt_nl
     << "return (strm << " << marshal_arg << ");" << be_uidt_nl
     << "}" << be_nl_2;

  return 0;
}


int
be_visitor_valuebox_cs::visit_interface (be_interface *)
{
  return this->emit_for_predef_enum ("this->_pd_value");
}

int
be_visitor_valuebox_cs::visit_predefined_type (be_predefined_type * node)
{
  char const * marshal_arg;

  switch (node->pt ())
    {
    case AST_PredefinedType::PT_boolean:
      marshal_arg =
        "::ACE_OutputCDR::from_boolean (this->_pd_value)";
      break;

    case AST_PredefinedType::PT_char:
      marshal_arg =
        "::ACE_OutputCDR::from_char (this->_pd_value)";
      break;

    case AST_PredefinedType::PT_wchar:
      marshal_arg =
        "::ACE_OutputCDR::from_wchar (this->_pd_value)";
      break;

    case AST_PredefinedType::PT_octet:
      marshal_arg =
        "::ACE_OutputCDR::from_octet (this->_pd_value)";
      break;

    case AST_PredefinedType::PT_uint8:
      marshal_arg =
        "::ACE_OutputCDR::from_uint8 (this->_pd_value)";
      break;

    case AST_PredefinedType::PT_int8:
      marshal_arg =
        "::ACE_OutputCDR::from_int8 (this->_pd_value)";
      break;

    case AST_PredefinedType::PT_any:
      marshal_arg = "this->_pd_value.in ()";
      break;

    default:
      marshal_arg = "this->_pd_value";
      break;
    }

  return this->emit_for_predef_enum (marshal_arg);
}

int
be_visitor_valuebox_cs::visit_sequence (be_sequence *node)
{
  TAO_OutStream *os = this->ctx_->stream ();

  // Retrieve the node being visited by this be_visitor_valuebox_cs.
  be_decl * vb_node = this->ctx_->node ();

  if (node->anonymous ())
    { // Our sequence is anonymous so we must generate a declaration
      // for it.
      be_visitor_context ctx (*this->ctx_);
      ctx.node (node);

      // First generate the sequence definition
      be_visitor_sequence_cs visitor (&ctx);

      if (node->accept (&visitor) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_valuebox_cs::"
                             "visit_sequence - "
                             "codegen failed\n"),
                            -1);
        }
    }

  // Retrieve the base type since we will need to do some code
  // generation for it.
  be_type *bt = dynamic_cast<be_type*> (node->base_type ());

  if (bt == nullptr)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_valuebox_cs::"
                         "visit_sequence - "
                         "Bad element type\n"),
                        -1);
    }
  be_visitor_context ctx (*this->ctx_);
  ctx.state (TAO_CodeGen::TAO_SEQUENCE_BUFFER_TYPE_CH);
  be_visitor_sequence_buffer_type bt_visitor (&ctx);

  *os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl
      << "// " << __FILE__ << ":" << __LINE__ << be_nl_2;

  if (node->unbounded ())
    {
      // Public constructor with one argument of type ULong
      *os << vb_node->name () << "::" << vb_node->local_name ()
          << " ( ::CORBA::ULong max)" << be_nl
          << "{" << be_idt_nl
          << node->full_name () << "* p;" << be_nl
          << "ACE_NEW (" << be_idt_nl
          << "p," << be_nl
          << node->full_name () << " (max));" << be_uidt_nl
          << "this->_pd_value = p;" << be_uidt_nl
          << "}" << be_nl_2;
    }

  // Public constructor for sequence with supplied buffer
  *os << vb_node->name () << "::" << vb_node->local_name ()
      << " (" << be_idt;

  if (node->unbounded ())
    {
      *os << be_nl << "::CORBA::ULong max,";
    }

  *os << be_nl << "::CORBA::ULong length," << be_nl;


  if (bt->accept (&bt_visitor) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_valuebox_cs::"
                         "visit_valuebox - "
                         "base type visit failed\n"),
                        -1);
    }

  *os << " * buf," << be_nl
      << "::CORBA::Boolean release)" << be_uidt_nl
      << "{" << be_idt_nl
      << node->full_name () << "* p;" << be_nl
      << "ACE_NEW (" << be_idt_nl
      << "p," << be_nl
      << node->full_name () << " (";

  if (node->unbounded ())
    {
      *os << "max, ";
    }

  *os << "length, buf, release));" << be_uidt_nl
      << "this->_pd_value = p;" << be_uidt_nl
      << "}" << be_nl_2;

  // end: Public constructor for sequence with supplied buffer

  this->emit_destructor ();

  // Accessor: non const
  if (bt->accept (&bt_visitor) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_valuebox_cs::"
                         "visit_valuebox - "
                         "base type visit failed\n"),
                        -1);
    }

  *os << " &" << be_nl
      << vb_node->name () << "::operator[] ( ::CORBA::ULong index)"
      << be_nl
      << "{" << be_idt_nl
      << "return (";

  if (bt->accept (&bt_visitor) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                       "(%N:%l) be_visitor_valuebox_cs::"
                       "visit_valuebox - "
                       "base type visit failed\n"),
                       -1);
    }

  *os << "&) this->_pd_value->operator[] (index);" << be_uidt_nl
      << "}" << be_nl_2;

  // Accessor: const
  *os << "const ";

  if (bt->accept (&bt_visitor) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_valuebox_cs::"
                         "visit_sequence - "
                         "base type visit failed\n"),
                        -1);
    }

  *os << " &" << be_nl;
  *os << vb_node->name ()
      << "::operator[] ( ::CORBA::ULong index) const" << be_nl
      << "{" << be_idt_nl;

  switch (bt->node_type())
    {
    case AST_Decl::NT_wstring:
      *os << "TAO_SeqElem_WString_Manager mgr = this->_pd_value->operator[] "
             "(index);" << be_nl
          << "return mgr._retn ();" << be_uidt_nl;
      break;

    case AST_Decl::NT_string:
      *os << "TAO_SeqElem_String_Manager mgr = this->_pd_value->operator[] "
             "(index);" << be_nl
          << "return mgr._retn ();" << be_uidt_nl;
      break;

    default:
      *os << "return (";

      if (bt->accept (&bt_visitor) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_valuebox_cs::"
                             "visit_sequence - "
                             "base type visit failed\n"),
                            -1);
        }

      *os << "&) this->_pd_value->operator[] (index);" << be_uidt_nl;
    }

  *os << "}" << be_nl_2;

  // _tao_marshal_v method
  *os << "::CORBA::Boolean" << be_nl
      << vb_node->name ()
      << "::_tao_marshal_v (TAO_OutputCDR & strm) const" << be_nl
      << "{" << be_idt_nl
      << "return (strm << this->_pd_value.in ());" << be_uidt_nl
      << "}" << be_nl_2;

  return 0;
}

int
be_visitor_valuebox_cs::visit_string (be_string *str)
{
  TAO_OutStream & os = *this->ctx_->stream ();

  // Retrieve the node being visited by this be_visitor_valuebox_cs.
  be_decl * const vb_node = this->ctx_->node ();

  os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl
     << "// " << __FILE__ << ":" << __LINE__ << be_nl_2;

  this->emit_destructor ();

  // _tao_marshal_v method
  os << "::CORBA::Boolean" << be_nl
     << vb_node->name ()
     << "::_tao_marshal_v (TAO_OutputCDR & strm) const" << be_nl
     << "{" << be_idt_nl
     << "return (strm << ";

  if (str->max_size ()->ev ()->u.ulval != 0)
    {
      if (str->width () == (long) sizeof (char))
        {
          os << "::ACE_OutputCDR::from_string "
             << "(this->_pd_value, "
             << str->max_size ()->ev ()->u.ulval << ")";
        }
      else
        {
          os << "::ACE_OutputCDR::from_wstring "
             << "(this->_pd_value, "
             << str->max_size ()->ev ()->u.ulval << ")";
        }
    }
  else
    {
      os << "this->_pd_value";
    }

  os << ");" << be_uidt_nl
     << "}" << be_nl_2;

  return 0;
}

int
be_visitor_valuebox_cs::visit_structure (be_structure *)
{
  TAO_OutStream & os = *this->ctx_->stream ();

  // Retrieve the node being visited by this be_visitor_valuebox_cs.
  be_decl * const vb_node = this->ctx_->node ();

  os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl
      << "// " << __FILE__ << ":" << __LINE__ << be_nl_2;

  this->emit_destructor ();

  // _tao_marshal_v method
  os << "::CORBA::Boolean" << be_nl
     << vb_node->name ()
     << "::_tao_marshal_v (TAO_OutputCDR & strm) const" << be_nl
     << "{" << be_idt_nl
     << "return (strm << this->_pd_value.in ());" << be_uidt_nl
     << "}" << be_nl_2;

  return 0;
}

int
be_visitor_valuebox_cs::visit_typedef (be_typedef *node)
{
  // Make a decision based on the primitive base type.
  be_type *bt = node->primitive_base_type ();

  if (!bt || (bt->accept (this) == -1))
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_valuebox_cs::"
                         "visit_typedef - "
                         "Bad primitive type\n"),
                        -1);
    }

  return 0;
}

int
be_visitor_valuebox_cs::visit_union (be_union *)
{
  TAO_OutStream & os = *this->ctx_->stream ();

  // Retrieve the node being visited by this be_visitor_valuebox_cs.
  be_decl * const vb_node = this->ctx_->node ();

  os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl
     << "// " << __FILE__ << ":" << __LINE__ << be_nl_2;

  this->emit_destructor ();

  // _tao_marshal_v method
  os << "::CORBA::Boolean" << be_nl
     << vb_node->name ()
     << "::_tao_marshal_v (TAO_OutputCDR & strm) const" << be_nl
     << "{" << be_idt_nl
     << "return (strm << this->_pd_value.in ());" << be_uidt_nl
     << "}" << be_nl_2;

  return 0;
}

void
be_visitor_valuebox_cs::emit_destructor ()
{
  TAO_OutStream & os = *this->ctx_->stream ();

  // Retrieve the node being visited by this be_visitor_valuebox_cs.
  be_decl * const vb_node = this->ctx_->node ();

  // Protected destructor
  os << vb_node->name () << "::~" << vb_node->local_name () << " ()"
     << be_nl << "{" << be_nl << "}" << be_nl_2;
}

int
be_visitor_valuebox_cs::emit_for_predef_enum (char const * marshal_arg)
{
  TAO_OutStream & os = *this->ctx_->stream ();

  // Retrieve the node being visited by this be_visitor_valuebox_cs.
  be_decl * const vb_node = this->ctx_->node ();

  os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl
     << "// " << __FILE__ << ":" << __LINE__ << be_nl_2;

  this->emit_destructor ();

  // _tao_marshal_v method
  os << "::CORBA::Boolean" << be_nl
     << vb_node->name ()
     << "::_tao_marshal_v (TAO_OutputCDR & strm) const" << be_nl
     << "{" << be_idt_nl
     << "return (strm << " << marshal_arg << ");" << be_uidt_nl
     << "}" << be_nl_2;

  return 0;
}