summaryrefslogtreecommitdiff
path: root/modules/TAO/TAO_IDL/be/be_visitor_root/cdr_op.cpp
blob: f5ff95d4b41c7e0cf021c179731ffa57303d1ec5 (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
//
// $Id$
//

// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    cdr_op.cpp
//
// = DESCRIPTION
//    Visitor generating code for the CDR operators for types defined
//    in Root's scope.
//
// = AUTHOR
//    Aniruddha Gokhale
//
// ============================================================================

ACE_RCSID (be_visitor_root, 
           cdr_op, 
           "$Id$")

// ***************************************************************************
// Root visitor for generating CDR operator declarations in the client header
// and stub
// ***************************************************************************

be_visitor_root_cdr_op::be_visitor_root_cdr_op (be_visitor_context *ctx)
  : be_visitor_root (ctx)
{
}

be_visitor_root_cdr_op::~be_visitor_root_cdr_op (void)
{
}

int
be_visitor_root_cdr_op::visit_root (be_root *node)
{
  if (this->visit_scope (node) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_root_cdr_op::visit_root - "
                         "codegen for scope failed\n"), 
                        -1);
    }

  TAO_OutStream *os = this->ctx_->stream ();
  TAO_CodeGen::CG_STATE cg_state = this->ctx_->state ();
  
  if (cg_state == TAO_CodeGen::TAO_ROOT_CDR_OP_CH)
    {
      *os << be_nl << be_nl
          << "TAO_BEGIN_VERSIONED_NAMESPACE_DECL"
          << be_nl << be_nl
          << "::CORBA::Boolean operator<< (TAO_OutputCDR &strm, const std::string &_tao_string);"
          << be_nl
          << "::CORBA::Boolean operator>> (TAO_InputCDR &strm, std::string &_tao_string);";
          
      *os << be_nl << be_nl
          << "TAO_END_VERSIONED_NAMESPACE_DECL";
          
      *os << be_nl << be_nl
          << "TAO_BEGIN_VERSIONED_NAMESPACE_DECL";
          
      *os << be_nl << be_nl
          << "::CORBA::Boolean operator<< (TAO_OutputCDR &strm, const Param_Test::UB_Long_Seq &_tao_vector);"
          << be_nl
          << "::CORBA::Boolean operator>> (TAO_InputCDR &strm, Param_Test::UB_Long_Seq &_tao_vector);";
          
      *os << be_nl << be_nl
          << "TAO_END_VERSIONED_NAMESPACE_DECL";
    }
  else if (cg_state == TAO_CodeGen::TAO_ROOT_CDR_OP_CS)
    {
      *os << be_nl << be_nl
          << "TAO_BEGIN_VERSIONED_NAMESPACE_DECL";
          
      *os << be_nl << be_nl
          << "::CORBA::Boolean operator<< (" << be_idt_nl
          << "TAO_OutputCDR &strm," << be_nl
          << "const std::string &_tao_string)" << be_uidt_nl
          << "{" << be_idt_nl
          << "return strm << _tao_string.c_str ();" << be_uidt_nl
          << "}" << be_nl << be_nl
          << "::CORBA::Boolean operator>> (" << be_idt_nl
          << "TAO_InputCDR &strm," << be_nl
          << "std::string &_tao_string)" << be_uidt_nl
          << "{" << be_idt_nl
          << "char *buf = 0;" << be_nl
          << "strm >> buf;" << be_nl
          << "_tao_string.assign (buf);" << be_nl
          << "ACE::strdelete (buf);" << be_nl
          << "return true;" << be_uidt_nl
          << "}";
          
      *os << be_nl << be_nl
          << "TAO_END_VERSIONED_NAMESPACE_DECL";
          
      *os << be_nl << be_nl
          << "TAO_BEGIN_VERSIONED_NAMESPACE_DECL";
          
      *os << be_nl << be_nl
          << "::CORBA::Boolean operator<< (" << be_idt_nl
          << "TAO_OutputCDR &strm," << be_nl
          << "const Param_Test::UB_Long_Seq &_tao_vector)"
          << be_uidt_nl
          << "{" << be_idt_nl
          << "::CORBA::ULong length = _tao_vector.size ();"
          << be_nl
          << "strm << length;" << be_nl << be_nl
          << "for ( ::CORBA::ULong i = 0UL; i < length; ++i)"
          << be_idt_nl
          << "{" << be_idt_nl
          << "strm << _tao_vector[i];" << be_uidt_nl
          << "}" << be_uidt_nl << be_nl
          << "return true;" << be_uidt_nl
          << "}";
          
      *os << be_nl << be_nl
          << "::CORBA::Boolean operator>> (" << be_idt_nl
          << "TAO_InputCDR &strm," << be_nl
          << "Param_Test::UB_Long_Seq &_tao_vector)" << be_uidt_nl
          << "{" << be_idt_nl
          << "::CORBA::ULong length = 0UL;" << be_nl
          << "::CORBA::ULong tmp = 0UL;" << be_nl << be_nl
          << "for ( ::CORBA::ULong i = 0UL; i < length; ++i)"
          << be_idt_nl
          << "{" << be_idt_nl
          << "strm >> tmp;" << be_nl
          << "_tao_vector[i] = tmp;" << be_uidt_nl
          << "}" << be_uidt_nl << be_nl
          << "return true;" << be_uidt_nl
          << "}";

      *os << be_nl << be_nl
          << "TAO_BEGIN_VERSIONED_NAMESPACE_DECL";       
    }

  return 0;
}