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