Salome HOME
00ecbf77720cd9efaaf1355815802a0180433419
[tools/hxx2salome.git] / scripts / parse3.awk
1 # This awk program contains the type mapping tables - and the treatments
2 # for code generation
3 #
4 BEGIN { 
5 #
6 # file name generation
7   idl_file="code_idl"
8   hxx_file="code_hxx"
9   cxx_file="code_cxx"
10   class_i=class_name"_i"
11   print "\t// generated part" > idl_file
12   printf "    // generated part\n" > hxx_file
13   printf "//\n// generated part\n//\n" > cxx_file
14   print "Functions parsing (for debug)" > "parse_result"
15 #
16 #
17 # type mapping from c++ component to idl
18 #
19   idl_arg_type["int"]="in long"
20   idl_arg_type["double"]="in double"
21   idl_arg_type["float"]="in float"
22   idl_arg_type["long"]="in long"
23   idl_arg_type["short"]="in short"
24   idl_arg_type["unsigned"]="in unsigned long"
25   idl_arg_type["const char*"]="in string"
26   idl_arg_type["const std::string&"]="in string"
27   idl_arg_type["int&"]="out long"
28   idl_arg_type["double&"]="out double"
29   idl_arg_type["float&"]="out float"
30   idl_arg_type["long&"]="out long"
31   idl_arg_type["short&"]="out short"
32   idl_arg_type["unsigned&"]="out unsigned long"
33   idl_arg_type["std::string&"]="out string"
34   idl_arg_type["const MEDMEM::MESH&"]="in SALOME_MED::MESH"
35   idl_arg_type["const MEDMEM::MESH*"]="in SALOME_MED::MESH"
36   idl_arg_type["const MEDMEM::FIELD<double>*"]="in SALOME_MED::FIELDDOUBLE"
37   idl_arg_type["const MEDMEM::FIELD<double>&"]="in SALOME_MED::FIELDDOUBLE"
38   idl_arg_type["MEDMEM::FIELD<double>*&"]="out SALOME_MED::FIELDDOUBLE"
39   idl_arg_type["const std::vector<double>&"]="in SALOME::SenderDouble"
40   idl_arg_type["const std::vector<std::vector<double> >&"]="in SALOME::Matrix"
41   idl_arg_type["std::vector<double>*&"]="out SALOME::SenderDouble"
42   idl_arg_type["const MEDMEM::FIELD<int>*"]="in SALOME_MED::FIELDINT"
43   idl_arg_type["const MEDMEM::FIELD<int>&"]="in SALOME_MED::FIELDINT"
44   idl_arg_type["MEDMEM::FIELD<int>*&"]="out SALOME_MED::FIELDINT"
45   idl_arg_type["const std::vector<int>&"]="in SALOME::SenderInt"
46   idl_arg_type["std::vector<int>*&"]="out SALOME::SenderInt"
47 #
48 #
49 # mapping for returned types
50 #
51   idl_rtn_type["void"]="void"
52   idl_rtn_type["int"]="long"
53   idl_rtn_type["double"]="double"
54   idl_rtn_type["float"]="float"
55   idl_rtn_type["long"]="long"
56   idl_rtn_type["short"]="short"
57   idl_rtn_type["unsigned"]="unsigned long"
58   idl_rtn_type["const char*"]="string"
59   idl_rtn_type["char*"]="string"
60   idl_rtn_type["std::string"]="string"
61   idl_rtn_type["const MEDMEM::MESH&"]="SALOME_MED::MESH"
62   idl_rtn_type["MEDMEM::MESH&"]="SALOME_MED::MESH"
63   idl_rtn_type["MEDMEM::MESH*"]="SALOME_MED::MESH"
64   idl_rtn_type["const MEDMEM::MESH*"]="SALOME_MED::MESH"
65   idl_rtn_type["const MEDMEM::FIELD<double>*"]="SALOME_MED::FIELDDOUBLE"
66   idl_rtn_type["MEDMEM::FIELD<double>*"]="SALOME_MED::FIELDDOUBLE"
67   idl_rtn_type["MEDMEM::FIELD<double>&"]="SALOME_MED::FIELDDOUBLE"
68   idl_rtn_type["const MEDMEM::FIELD<double>&"]="SALOME_MED::FIELDDOUBLE"
69   idl_rtn_type["std::vector<double>*"]="SALOME::SenderDouble"
70   idl_rtn_type["std::vector<std::vector<double> >*"]="SALOME::Matrix"
71   idl_rtn_type["const MEDMEM::FIELD<int>*"]="SALOME_MED::FIELDINT"
72   idl_rtn_type["MEDMEM::FIELD<int>*"]="SALOME_MED::FIELDINT"
73   idl_rtn_type["MEDMEM::FIELD<int>&"]="SALOME_MED::FIELDINT"
74   idl_rtn_type["const MEDMEM::FIELD<int>&"]="SALOME_MED::FIELDINT"
75   idl_rtn_type["std::vector<int>*"]="SALOME::SenderInt"
76 #
77 #
78 # Corba mapping table (for argument's types and returned types)
79 #
80   idl_impl_hxx["in long"]="CORBA::Long"
81   idl_impl_hxx["in double"]="CORBA::Double"
82   idl_impl_hxx["in float"]="CORBA::Float"
83   idl_impl_hxx["in short"]="CORBA::Short"
84   idl_impl_hxx["in unsigned long"]="CORBA::ULong"
85   idl_impl_hxx["in string"]="const char*"
86   idl_impl_hxx["out long"]="CORBA::Long_out"
87   idl_impl_hxx["out double"]="CORBA::Double_out"
88   idl_impl_hxx["out float"]="CORBA::Float_out"
89   idl_impl_hxx["out short"]="CORBA::Short_out"
90   idl_impl_hxx["out unsigned long"]="CORBA::ULong_out"
91   idl_impl_hxx["out string"]="CORBA::String_out"
92   idl_impl_hxx["in SALOME_MED::MESH"]="SALOME_MED::MESH_ptr"
93   idl_impl_hxx["in SALOME_MED::FIELDDOUBLE"]="SALOME_MED::FIELDDOUBLE_ptr"
94   idl_impl_hxx["out SALOME_MED::FIELDDOUBLE"]="SALOME_MED::FIELDDOUBLE_out"
95   idl_impl_hxx["in SALOME::SenderDouble"]="SALOME::SenderDouble_ptr"
96   idl_impl_hxx["out SALOME::SenderDouble"]="SALOME::SenderDouble_out"
97   idl_impl_hxx["in SALOME::Matrix"]="SALOME::Matrix_ptr"
98   idl_impl_hxx["in SALOME_MED::FIELDINT"]="SALOME_MED::FIELDINT_ptr"
99   idl_impl_hxx["out SALOME_MED::FIELDINT"]="SALOME_MED::FIELDINT_out"
100   idl_impl_hxx["in SALOME::SenderInt"]="SALOME::SenderInt_ptr"
101   idl_impl_hxx["out SALOME::SenderInt"]="SALOME::SenderInt_out"
102   idl_impl_hxx["void"]="void"
103   idl_impl_hxx["long"]="CORBA::Long"
104   idl_impl_hxx["double"]="CORBA::Double"
105   idl_impl_hxx["unsigned long"]="CORBA::ULong"
106   idl_impl_hxx["string"]="char*"
107   idl_impl_hxx["SALOME_MED::MESH"]="SALOME_MED::MESH_ptr"
108   idl_impl_hxx["SALOME_MED::FIELDDOUBLE"]="SALOME_MED::FIELDDOUBLE_ptr"
109   idl_impl_hxx["SALOME::SenderDouble"]="SALOME::SenderDouble_ptr"
110   idl_impl_hxx["SALOME::Matrix"]="SALOME::Matrix_ptr"
111   idl_impl_hxx["SALOME_MED::FIELDINT"]="SALOME_MED::FIELDINT_ptr"
112   idl_impl_hxx["SALOME::SenderInt"]="SALOME::SenderInt_ptr"
113 #
114 #
115 # table for c++ code generation : argument's processing
116 #
117   cpp_impl_a["int"]="\tint _%s(%s);\n"
118   cpp_impl_a["double"]="\tdouble _%s(%s);\n"
119   cpp_impl_a["float"]="\tfloat _%s(%s);\n"
120   cpp_impl_a["long"]="\tlong _%s(%s);\n"
121   cpp_impl_a["short"]="\tshort _%s(%s);\n"
122   cpp_impl_a["unsigned"]="\tunsigned _%s(%s);\n"
123   cpp_impl_a["const char*"]="\tconst char* _%s(%s);\n"
124   cpp_impl_a["const std::string&"]="\tconst std::string _%s(%s);\n"
125   cpp_impl_a["int&"]="\tint _%s;\n"
126   cpp_impl_a["double&"]="\tdouble _%s;\n"
127   cpp_impl_a["float&"]="\tfloat _%s;\n"
128   cpp_impl_a["long&"]="\tlong _%s;\n"
129   cpp_impl_a["short&"]="\tshort _%s;\n"
130   cpp_impl_a["unsigned&"]="\tunsigned _%s;\n"
131   cpp_impl_a["std::string&"]="std::string _%s;\n"
132   cpp_impl_a["const MEDMEM::MESH&"]="\tMEDMEM::MESHClient* _%s = new MEDMEM::MESHClient(%s);\n" # MESHClient cannot be created on the stack (private constructor), so we create it on the heap and dereference it later (in treatment 4)
133   cpp_impl_a["const MEDMEM::MESH*"]="\tMEDMEM::MESHClient* _%s = new MEDMEM::MESHClient(%s);\n"
134   cpp_impl_a["MEDMEM::FIELD<double>*&"]="\tMEDMEM::FIELD<double>* _%s;\n"
135   cpp_impl_a["const MEDMEM::FIELD<double>*"]="\tstd::auto_ptr<MEDMEM::FIELD<double> > _%s ( new MEDMEM::FIELDClient<double,MEDMEM::FullInterlace>(%s) );\n"
136   cpp_impl_a["const MEDMEM::FIELD<double>&"]="\tMEDMEM::FIELDClient<double,MEDMEM::FullInterlace> _%s(%s);\n"
137   cpp_impl_a["const std::vector<double>&"]="\tlong _%s_size;\n\tdouble *_%s_value = ReceiverFactory::getValue(%s,_%s_size);\n"\
138              "\tstd::vector<double> _%s(_%s_value,_%s_value+_%s_size);\n\tdelete [] _%s_value;"
139   cpp_impl_a["std::vector<double>*&"]="\tstd::vector<double>* _%s;\n"
140   cpp_impl_a["const std::vector<std::vector<double> >&"]="\tMatrixClient _%s_client;\n\tint _%s_nbRow;\n\tint _%s_nbCol;\n"\
141              "\tdouble* _%s_tab = _%s_client.getValue(%s,_%s_nbCol,_%s_nbRow);\n\tstd::vector<std::vector<double> > _%s(_%s_nbRow);\n"\
142              "\tfor (int i=0; i!=_%s_nbRow; ++i)\n\t{\n\t    _%s[i].resize(_%s_nbCol);\n"\
143              "\t    std::copy(_%s_tab+_%s_nbCol*i,_%s_tab+_%s_nbCol*(i+1), _%s[i].begin());\n\t}\n\tdelete [] _%s_tab;\n"
144   cpp_impl_a["MEDMEM::FIELD<int>*&"]="\tMEDMEM::FIELD<int>* _%s;\n"
145   cpp_impl_a["const MEDMEM::FIELD<int>*"]="\tstd::auto_ptr<MEDMEM::FIELD<int> > _%s ( new MEDMEM::FIELDClient<int>(%s) );\n"
146   cpp_impl_a["const MEDMEM::FIELD<int>&"]="\tMEDMEM::FIELDClient<int> _%s(%s);\n"
147   cpp_impl_a["const std::vector<int>&"]="\tlong _%s_size;\n\tint *_%s_value = ReceiverFactory::getValue(%s,_%s_size);\n"\
148              "\tstd::vector<int> _%s(_%s_value,_%s_value+_%s_size);\n\tdelete [] _%s_value;"
149   cpp_impl_a["std::vector<int>*&"]="\tstd::vector<int>* _%s;\n"
150
151 #
152 #
153 # table for c++ code generation : returned value processing
154 #
155   cpp_impl_b["void"]=""
156   cpp_impl_b["int"]="\tCORBA::Long _rtn_ior(_rtn_cpp);\n"
157   cpp_impl_b["double"]="\tCORBA::Double _rtn_ior(_rtn_cpp);\n"
158   cpp_impl_b["float"]="\tCORBA::Float _rtn_ior(_rtn_cpp);\n"
159   cpp_impl_b["long"]="\tCORBA::Long _rtn_ior(_rtn_cpp);\n"
160   cpp_impl_b["short"]="\tCORBA::Short _rtn_ior(_rtn_cpp);\n"
161   cpp_impl_b["unsigned"]="\tCORBA::ULong _rtn_ior(_rtn_cpp);\n"
162   cpp_impl_b["const char*"]="\tchar* _rtn_ior = CORBA::string_dup(_rtn_cpp);\n"
163   cpp_impl_b["char*"]="\tchar* _rtn_ior(_rtn_cpp);\n"
164   cpp_impl_b["std::string"]="\tchar* _rtn_ior=CORBA::string_dup(_rtn_cpp.c_str());\n"
165              "\tstd::copy(_rtn_cpp.begin(),_rtn_cpp.end(),_rtn_ior);\n"    
166   cpp_impl_b["const MEDMEM::MESH&"]=\
167              "\tMEDMEM::MESH_i * _rtn_mesh_i = new MEDMEM::MESH_i(const_cast<MEDMEM::MESH*>(&_rtn_cpp));\n"\
168              "\tSALOME_MED::MESH_ptr _rtn_ior = _rtn_mesh_i->_this();\n"
169   cpp_impl_b["MEDMEM::MESH&"]=\
170              "\tMEDMEM::MESH_i * _rtn_mesh_i = new MEDMEM::MESH_i(&_rtn_cpp);\n"\
171              "\tSALOME_MED::MESH_ptr _rtn_ior = _rtn_mesh_i->_this();\n"
172   cpp_impl_b["MEDMEM::MESH*"]=\
173              "\tMEDMEM::MESH_i * _rtn_mesh_i = new MEDMEM::MESH_i(_rtn_cpp);\n"\
174              "\tSALOME_MED::MESH_ptr _rtn_ior = _rtn_mesh_i->_this();\n"
175   cpp_impl_b["const MEDMEM::MESH*"]=\
176              "\tMEDMEM::MESH_i * _rtn_mesh_i = new MEDMEM::MESH_i(const_cast<MEDMEM::MESH*>(_rtn_cpp));\n"\
177              "\tSALOME_MED::MESH_ptr _rtn_ior = _rtn_mesh_i->_this();\n"
178   cpp_impl_b["const MEDMEM::FIELD<double>*"]=\
179              "\tMEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace> * _rtn_field_i = new MEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace>(const_cast<MEDMEM::FIELD<double>*>(_rtn_cpp),false);\n"\
180              "\tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"
181   cpp_impl_b["MEDMEM::FIELD<double>*"]=\
182              "\tMEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace> * _rtn_field_i = new MEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace>(_rtn_cpp,true);\n"\
183              "\tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"
184   cpp_impl_b["MEDMEM::FIELD<double>&"]=\
185              "\tMEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace> * _rtn_field_i = new MEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace>(&_rtn_cpp,false);\n"\
186              "\tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"
187   cpp_impl_b["const MEDMEM::FIELD<double>&"]=\
188              "\tMEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace> * _rtn_field_i = new MEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace>(const_cast<MEDMEM::FIELD<double>*>(&_rtn_cpp),false);\n"\
189              "\tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"
190   cpp_impl_b["std::vector<double>*"]=\
191              "\tSALOME::SenderDouble_ptr _rtn_ior = SenderFactory::buildSender(*this,&(*_rtn_cpp)[0],(*_rtn_cpp).size(),true);\n"
192   cpp_impl_b["std::vector<std::vector<double> >*"]=\
193              "\tint _rtn_cpp_i=(*_rtn_cpp).size();\n\tint _rtn_cpp_j=(*_rtn_cpp)[0].size();\n"\
194              "\tdouble* _rtn_tab = new double[_rtn_cpp_i*_rtn_cpp_j];\n"\
195              "\tfor (int i=0; i!=_rtn_cpp_i; ++i)\n\t    std::copy((*_rtn_cpp)[i].begin(),(*_rtn_cpp)[i].end(),_rtn_tab+i*_rtn_cpp_j);\n"\
196              "\tSALOME_Matrix_i* _rtn_matrix_i = new SALOME_Matrix_i(*this,_rtn_tab,_rtn_cpp_i,_rtn_cpp_j,true);\n"\
197              "\tSALOME::Matrix_ptr _rtn_ior = _rtn_matrix_i->_this();\n\tdelete _rtn_cpp;\n"
198   cpp_impl_b["const MEDMEM::FIELD<int>*"]=\
199              "\tMEDMEM::FIELDINT_i * _rtn_field_i = new MEDMEM::FIELDINT_i(const_cast<MEDMEM::FIELD<int>*>(_rtn_cpp),false);\n"\
200              "\tSALOME_MED::FIELDINT_ptr _rtn_ior = _rtn_field_i->_this();\n"
201   cpp_impl_b["MEDMEM::FIELD<int>*"]=\
202              "\tMEDMEM::FIELDINT_i * _rtn_field_i = new MEDMEM::FIELDINT_i(_rtn_cpp,true);\n"\
203              "\tSALOME_MED::FIELDINT_ptr _rtn_ior = _rtn_field_i->_this();\n"
204   cpp_impl_b["MEDMEM::FIELD<int>&"]=\
205              "\tMEDMEM::FIELDINT_i * _rtn_field_i = new MEDMEM::FIELDINT_i(&_rtn_cpp,false);\n"\
206              "\tSALOME_MED::FIELDINT_ptr _rtn_ior = _rtn_field_i->_this();\n"
207   cpp_impl_b["const MEDMEM::FIELD<int>&"]=\
208              "\tMEDMEM::FIELDINT_i * _rtn_field_i = new MEDMEM::FIELDINT_i(const_cast<MEDMEM::FIELD<int>*>(&_rtn_cpp),false);\n"\
209              "\tSALOME_MED::FIELDINT_ptr _rtn_ior = _rtn_field_i->_this();\n"
210   cpp_impl_b["std::vector<int>*"]=\
211              "\tSALOME::SenderInt_ptr _rtn_ior = SenderFactory::buildSender(*this,&(*_rtn_cpp)[0],(*_rtn_cpp).size(),true);\n"
212
213 #
214 #
215 # table for c++ code generation : out parameters processing and removeRef for reference counted objects
216 #
217   cpp_impl_c["MEDMEM::FIELD<double>*&"]=\
218              "\tMEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace> * %s_ior = new MEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace>(_%s, true);\n"\
219              "\t%s = %s_ior->_this();\n"
220   cpp_impl_c["MEDMEM::FIELD<int>*&"]=\
221              "\tMEDMEM::FIELDINT_i * %s_ior = new MEDMEM::FIELDINT_i(_%s, true);\n"\
222              "\t%s = %s_ior->_this();\n"
223   cpp_impl_c["std::vector<double>*&"]=\
224              "\t%s = SenderFactory::buildSender(*this,&(*_%s)[0],(*_%s).size(),true);\n"
225   cpp_impl_c["std::vector<int>*&"]=\
226              "\t%s = SenderFactory::buildSender(*this,&(*_%s)[0],(*_%s).size(),true);\n"
227   cpp_impl_c["std::string&"]="\t%s = CORBA::string_dup(_%s.c_str());\n"
228   cpp_impl_c["int&"]="\t%s = _%s;\n"
229   cpp_impl_c["double&"]="\t%s = _%s;\n"
230   cpp_impl_c["float&"]="\t%s = _%s;\n"
231   cpp_impl_c["long&"]="\t%s = _%s;\n"
232   cpp_impl_c["short&"]="\t%s = _%s;\n"
233   cpp_impl_c["unsigned&"]="\t%s = _%s;\n"
234   cpp_impl_c["const MEDMEM::MESH&"]="\t_%s->removeReference();\n"
235   cpp_impl_c["const MEDMEM::MESH*"]="\t_%s->removeReference();\n"
236 #
237 #
238 # record sep is ");\n" whith blanks all around, and optional "(" at the beginning
239   RS="[(]?[ \t]*\)[ \t]*;[ \t]*\n"  
240   FS="[ \t]*[(,][ \t]*"  # field sep is either "(" or "," surrounded by blanks 
241 }
242
243 # --------------------- treatment 1 ----------------------------------
244 #
245 #  extract from fields types, function name, and argument's names
246 #
247 {
248   print "Function : ",$0 >> "parse_result"  # print for debug
249   for (i=1; i<=NF; i++) {
250       print "\t-> ",i," : ",$i >> "parse_result"
251   }
252   ok1=0;ok=1
253   # check if returned type ($1) is one of the accepted types (idl_rtn_type)
254   for (cpptype in idl_rtn_type) {
255     if ( substr($1,1,length(cpptype)) == cpptype ) {
256       # if compatible, store returned type and function name
257       type[1]=cpptype
258       name[1]=substr($1,length(cpptype)+1)
259       sub("^[ \t]*","",name[1]) # get rid of leading blanks
260       ok1=1
261       break
262     }
263   }
264   ok*=ok1
265   # for each argument ($i), check if it is compatible (belongs to idl_arg_type)
266   for (i=2; i<=NF; i++) {
267     ok2=0
268     split($i,tab,"=") # get rid of default value
269     item=tab[1]
270     for (cpptype in idl_arg_type) {
271        if ( substr(item,1,length(cpptype)) == cpptype ) {
272           # if compatible, store argument type and name
273           type[i]=cpptype
274           name[i]=substr(item,length(cpptype)+1)
275           sub("^[ \t]*","",name[i]) # get rid of leading blanks
276           if ( length(name[i]) == 0 ) # automatic name if argument's name wasn't precised
277              name[i]=sprintf("_arg%d",i-1)
278           ok2=1
279           break
280        }
281     }
282     ok*=ok2 # ok=0 if one of the type is not compatible
283   }
284
285   # print compatibility 
286   if ( $0 !~ class_name ) { # constructor are not considered, but we don't print it
287       if ( ok == 0){ # if one of the c++ type is not compatible
288           printf "     [KO]     :  %s",$0
289       }
290       else
291           printf "     [OK]     :  %s",$0
292         
293       if ( $0 !~ /\(/  ) {
294           printf "(" # if there is no argument, parenthesis was suppressed, so we add it for printing
295       }
296       printf ");\n"
297   }    
298   if ( ok == 0) # pass to the next function if one of the c++ type is not compatible
299       next
300 }
301 #
302 # --------------------- treatment 2 ----------------------------------
303 #
304 #  generate the Corba interface (idl file)
305 #
306
307   printf "\t%s %s(", idl_rtn_type[type[1]],name[1] >> idl_file  # return type and name of function
308   if ( NF >= 2 ){  # if there is arguments, print them
309     for (i=2; i<=NF-1; i++)
310       printf "%s %s,",idl_arg_type[type[i]],name[i] >> idl_file
311     printf "%s %s", idl_arg_type[type[NF]],name[NF] >> idl_file
312   }
313   printf ");\n" >> idl_file
314 }  
315 #
316 # --------------------- treatment 3 ----------------------------------
317 #
318 #  generate the C++ implementation of component (hxx file)
319 #
320
321   printf "    %s %s(",idl_impl_hxx[idl_rtn_type[type[1]]],name[1] >> hxx_file
322   if ( NF >= 2 ){  # if there is arguments, print them
323       for (i=2; i<=NF-1; i++)
324           printf "%s %s,",idl_impl_hxx[idl_arg_type[type[i]]],name[i] >> hxx_file
325       printf "%s %s", idl_impl_hxx[idl_arg_type[type[NF]]],name[NF] >> hxx_file
326   }
327   printf ");\n" >> hxx_file
328 }
329 #
330 # --------------------- treatment 4 ----------------------------------
331 #
332 #  generate the C++ implementation of component (cxx file)
333 #
334 {
335   # a) generate the function declaration + macro declarations
336   func_name=class_name"_i::"name[1]
337   printf "%s %s(",idl_impl_hxx[idl_rtn_type[type[1]]],func_name >> cxx_file
338   if ( NF >= 2 ){  # if there is arguments, print them
339       for (i=2; i<=NF-1; i++)
340           printf "%s %s,",idl_impl_hxx[idl_arg_type[type[i]]],name[i] >> cxx_file
341       printf "%s %s", idl_impl_hxx[idl_arg_type[type[NF]]],name[NF] >> cxx_file
342   }
343   printf ")\n{\n\tbeginService(\"%s\");\n\tBEGIN_OF(\"%s\");\n",func_name,func_name >> cxx_file
344
345   # b) generate the argument processing part
346   if ( NF >= 2 ){
347       printf "//\tArguments processing\n" >> cxx_file
348       for (i=2; i<=NF; i++)
349           printf cpp_impl_a[type[i]],name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i],\
350                            name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i] >> cxx_file
351   }
352
353   # c) generate the call to the c++ component
354   if ( type[1] == "void" ) # if return type is void, the call syntax is different.
355       printf "//\tCall cpp component\n\tcppCompo_->%s(",name[1] >> cxx_file
356   else
357       printf "//\tCall cpp component\n\t%s _rtn_cpp = cppCompo_->%s(",type[1],name[1] >> cxx_file
358   if ( NF >= 2 ){  # if there is arguments, print them
359       for (i=2; i<=NF; i++) {
360           # special treatment for some arguments
361           post=""
362           pre=""
363           if ( cpp_impl_a[type[i]] ~ "auto_ptr" )
364              post=".get()" # for auto_ptr argument, retrieve the raw pointer behind
365           if ( type[i] == "const MEDMEM::MESH&" )
366              pre="*"  # we cannot create MESHClient on the stack (private constructor), so we create it on the heap and dereference it
367           if ( i < NF )
368              post=post"," # separator between arguments
369           printf " %s_%s%s",pre,name[i],post >> cxx_file
370       }
371   }
372
373   # d) generate the post_processing of returned and out parameters
374   printf ");\n//\tPost-processing & return\n" >> cxx_file
375   for (i=2; i<=NF; i++)
376       printf cpp_impl_c[type[i]],name[i],name[i],name[i],name[i] >> cxx_file  # process for out parameters
377   printf cpp_impl_b[type[1]] >> cxx_file  # process for returned value
378   printf "\tendService(\"%s\");\n\tEND_OF(\"%s\");\n",func_name,func_name >> cxx_file
379   if ( type[1] != "void" )
380       printf "\treturn _rtn_ior;\n" >> cxx_file
381   printf "}\n\n" >> cxx_file
382 }
383 #
384 #
385 END {
386 # CNC peut ĂȘtre mis dans le template directement printf "\nprivate:\n    std::auto_ptr<%s> cppImpl_;\n",class_name >> hxx_file
387 }