summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_sequence/gen_bounded_wstr_sequence_ci.cpp
blob: 2b64014d9d851bed2e4441b9f00d7b983b266ae6 (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
//
// $Id$
//

// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    gen_bounded_wstr_sequence_ci.cpp
//
// = DESCRIPTION
//    Visitor generating code for bounded wstring sequence in the client inline
//
// = AUTHOR
//    Jeff Parsons <parsons@cs.wustl.edu>
//
// ============================================================================

ACE_RCSID (be_visitor_sequence, 
           gen_bounded_wstr_sequence_ci, 
           "$Id$")

int
be_visitor_sequence_ci::gen_bounded_wstr_sequence (be_sequence *node)
{
  TAO_OutStream *os = this->ctx_->stream ();
  const char * class_name = node->instance_name ();

  static char full_class_name [NAMEBUFSIZE];
  ACE_OS::memset (full_class_name, 
                  '\0', 
                  NAMEBUFSIZE);

  if (node->is_nested ())
    {
      be_decl *tmp =
        be_scope::narrow_from_scope (node->defined_in ())->decl ();

      ACE_OS::sprintf (full_class_name, 
                       "%s::%s",
                       tmp->full_name (),
                       class_name);
    }
  else
    {
      ACE_OS::sprintf (full_class_name, 
                       "%s",
                       class_name);
    }

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

  os->gen_ifdef_AHETI();
  os->gen_ifdef_macro (class_name);

  // First generate the static methods since they are used by others. Since
  // they are inlined, their definition needs to come before their use else
  // some compilers (e.g., g++) produce lots of warnings.

  // allocbuf
  *os << be_nl << be_nl 
      << "ACE_INLINE" << be_nl
      << "CORBA::WChar **" << be_nl
      << full_class_name << "::allocbuf (CORBA::ULong /* length */)" << be_nl
      << "{" << be_idt_nl
      << "CORBA::WChar **buf = 0;" << be_nl
      << "ACE_NEW_RETURN (buf, CORBA::WChar *[" << node->max_size () 
      << "], 0);" << be_nl << be_nl
      << "for (CORBA::ULong i = 0; i < " << node->max_size () << "; i++)" 
      << be_idt_nl
      << "{" << be_idt_nl
      << "buf[i] = 0;" << be_uidt_nl
      << "}" << be_uidt_nl << be_nl
      << "return buf;" << be_uidt_nl
      << "}" << be_nl << be_nl;

  // freebuf
  *os << "ACE_INLINE" << be_nl
      << "void " << be_nl
      << full_class_name << "::freebuf (CORBA::WChar **buffer)" << be_nl
      << "{" << be_idt_nl
      << "for (CORBA::ULong i = 0; i < " << node->max_size () << "; ++i)" 
      << be_idt_nl
      << "{" << be_idt_nl
      << "if (buffer[i] != 0)" << be_idt_nl
      << "{" << be_idt_nl
      << "CORBA::wstring_free (buffer[i]);" << be_nl
      << "buffer[i] = 0;" << be_uidt_nl
      << "}" << be_uidt << be_uidt_nl
      << "}" << be_uidt_nl << be_nl
      << "delete [] buffer;" << be_uidt_nl
      << "}" << be_nl << be_nl;

  // constructor
  *os << "ACE_INLINE" << be_nl
      << full_class_name << "::" << class_name << " (void)" << be_nl
      << "  : TAO_Bounded_Base_Sequence (" << node->max_size ()
      << ", 0)" << be_nl
      << "{" << be_nl
      << "}" << be_nl << be_nl;

  // constructor
  *os << "ACE_INLINE" << be_nl
      << full_class_name << "::" << class_name << " ("
      << be_idt << be_idt_nl
      << "CORBA::ULong length," << be_nl
      << "CORBA::WChar* *value," << be_nl
      << "CORBA::Boolean release" << be_uidt_nl
      << ")" << be_nl
      << ": TAO_Bounded_Base_Sequence (" << node->max_size ()
      << ", length, value, release)" << be_uidt_nl
      << "{" << be_nl
      << "}" << be_nl << be_nl;

  // constructor
  *os << "ACE_INLINE" << be_nl
      << full_class_name << "::" << class_name << " (" << be_idt << be_idt_nl
      << "const "
      << class_name << " &rhs" << be_uidt_nl
      << ")" << be_nl
      << ": TAO_Bounded_Base_Sequence (rhs)" << be_uidt_nl
      << "{" << be_idt_nl
      << "if (rhs.buffer_ != 0)" << be_idt_nl
      << "{" << be_idt_nl
      << "CORBA::WChar **tmp1 =" << be_idt_nl 
      << class_name
      << "::allocbuf (this->maximum_);" << be_uidt_nl << be_nl
      << "CORBA::WChar ** const tmp2 =" << be_idt_nl
      << "ACE_reinterpret_cast (CORBA::WChar ** ACE_CAST_CONST, rhs.buffer_);"
      << be_uidt_nl << be_nl
      << "for (CORBA::ULong i=0; i < rhs.length_; i++)" << be_idt_nl
      << "{" << be_idt_nl
      << "tmp1[i] = CORBA::wstring_dup (tmp2[i]);" << be_uidt_nl
      << "}" << be_uidt_nl << be_nl
      << "this->buffer_ = tmp1;" << be_uidt_nl
      << "}" << be_uidt_nl
      << "else" << be_idt_nl
      << "{" << be_idt_nl
      << "this->buffer_ = 0;" << be_uidt_nl
      << "}" << be_uidt << be_uidt_nl
      << "}" << be_nl << be_nl;

  // operator=
  *os << "ACE_INLINE" << be_nl
      << full_class_name << "& " << be_nl
      << full_class_name << "::operator= (" << be_idt << be_idt_nl
      << "const " << class_name << " &rhs" << be_uidt_nl
      << ")" << be_uidt_nl
      << "{" << be_idt_nl
      << "if (this == &rhs)" << be_idt_nl
      << "{" << be_idt_nl
      << "return *this;" << be_uidt_nl
      << "}" << be_uidt_nl << be_nl
      << "if (this->release_ && this->buffer_ != 0)" << be_idt_nl
      << "{ " << be_idt_nl
      << "CORBA::WChar **tmp =" << be_idt_nl
      << "ACE_reinterpret_cast (CORBA::WChar **, this->buffer_);"
      << be_uidt_nl << be_nl
      << "for (CORBA::ULong i = 0; i < this->length_; ++i)" << be_idt_nl
      << "{" << be_idt_nl
      << "CORBA::wstring_free (tmp[i]);" << be_nl
      << "tmp[i] = 0;" << be_uidt_nl
      << "}" << be_uidt << be_uidt_nl
      << "}" << be_uidt_nl
      << "else" << be_idt_nl
      << "{" << be_idt_nl
      << "this->buffer_ =" << be_idt_nl
      << class_name
      << "::allocbuf (rhs.maximum_);" << be_uidt << be_uidt_nl
      << "}" << be_uidt_nl << be_nl
      << "TAO_Bounded_Base_Sequence::operator= (rhs);" << be_nl << be_nl
      << "CORBA::WChar **tmp1 =" << be_idt_nl
      << "ACE_reinterpret_cast (CORBA::WChar **, this->buffer_);"
      << be_uidt_nl
      << "CORBA::WChar ** const tmp2 =" << be_idt_nl
      << "ACE_reinterpret_cast (CORBA::WChar ** ACE_CAST_CONST, rhs.buffer_);"
      << be_uidt_nl << be_nl
      << "for (CORBA::ULong i = 0; i < rhs.length_; i++)" << be_idt_nl
      << "{" << be_idt_nl
      << "tmp1[i] = CORBA::wstring_dup (tmp2[i]);" << be_uidt_nl
      << "}" << be_uidt_nl << be_nl
      << "return *this;" << be_uidt_nl
      << "}" << be_nl << be_nl;

  // operator[]
  *os << "ACE_INLINE" << be_nl
      << "TAO_SeqElem_WString_Manager " << be_nl
      << full_class_name << "::operator[] (CORBA::ULong index) const" << be_nl
      << "{" << be_idt_nl
      << "ACE_ASSERT (index < this->maximum_);" << be_nl
      << "CORBA::WChar **const tmp =" << be_idt_nl
      << "ACE_reinterpret_cast (CORBA::WChar ** ACE_CAST_CONST, this->buffer_);" 
      << be_uidt_nl
      << "return TAO_SeqElem_WString_Manager (tmp + index, this->release_);" 
      << be_uidt_nl
      << "}" << be_nl << be_nl;

  // get_buffer
  *os << "ACE_INLINE" << be_nl
      << "CORBA::WChar**" << be_nl
      << full_class_name << "::get_buffer (CORBA::Boolean orphan)" << be_nl
      << "{" << be_idt_nl
      << "CORBA::WChar **result = 0;" << be_nl << be_nl
      << "if (orphan == 0)" << be_idt_nl
      << "{" << be_idt_nl
      << "// We retain ownership. " << be_nl
      << "if (this->buffer_ == 0)" << be_idt_nl
      << "{" << be_idt_nl
      << "result = " << class_name << "::allocbuf (this->maximum_);"
      << be_nl
      << "this->buffer_ = result;" << be_nl
      << "this->release_ = 1;" << be_uidt_nl
      << "}" << be_uidt_nl
      << "else" << be_idt_nl
      << "{" << be_idt_nl
      << "result = ACE_reinterpret_cast (CORBA::WChar **, this->buffer_);"
      << be_uidt_nl
      << "}" << be_uidt << be_uidt_nl
      << "}" << be_uidt_nl
      << "else // if (orphan == 1)" << be_idt_nl
      << "{" << be_idt_nl
      << "if (this->release_ != 0)" << be_idt_nl
      << "{" << be_idt_nl
      << "// We set state back to default and relinquish ownership." << be_nl
      << "result =" << be_idt_nl
      << "ACE_reinterpret_cast (CORBA::WChar **, this->buffer_);"
      << be_uidt_nl
      << "this->maximum_ = 0;" << be_nl
      << "this->length_ = 0;" << be_nl
      << "this->buffer_ = 0;" << be_nl
      << "this->release_ = 0;" << be_uidt_nl
      << "}" << be_uidt << be_uidt_nl
      << "}" << be_uidt_nl << be_nl
      << "return result;" << be_uidt_nl
      << "}" << be_nl << be_nl;

  // get_buffer
  *os << "ACE_INLINE" << be_nl
      << "const CORBA::WChar**" << be_nl
      << full_class_name << "::get_buffer (void) const" << be_nl
      << "{" << be_idt_nl
      << "return ACE_reinterpret_cast (const CORBA::WChar ** ACE_CAST_CONST, this->buffer_);" << be_uidt_nl
      << "}";

  os->gen_endif (); // endif macro

  // generate #endif for AHETI
  os->gen_endif_AHETI();

  return 0;
}