]> SALOME platform Git repositories - tools/hxx2salome.git/blob - scripts/parse3.awk
Salome HOME
59d889412ddf357b45f811d913a54da1a3a7fd4b
[tools/hxx2salome.git] / scripts / parse3.awk
1 # This awk program contains the type mapping tables - and the treatments
2 # --
3 # Copyright (C) CEA, EDF
4 # Author : Nicolas Crouzet (CEA)
5 # --
6 # for code generation
7 #
8 BEGIN { 
9 #
10 # file name generation
11   idl_file="code_idl"
12   hxx_file="code_hxx"
13   cxx_file="code_cxx"
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"
19 #
20 #
21 # type mapping from c++ component to idl
22 #
23   idl_arg_type["int"]="in long"
24   idl_arg_type["bool"]="in boolean"
25   idl_arg_type["double"]="in double"
26   idl_arg_type["float"]="in float"
27   idl_arg_type["long"]="in long"
28   idl_arg_type["short"]="in short"
29   idl_arg_type["unsigned"]="in unsigned long"
30   idl_arg_type["const char*"]="in string"
31   idl_arg_type["const std::string&"]="in string"
32   idl_arg_type["int&"]="out long"
33   idl_arg_type["bool&"]="out boolean"
34   idl_arg_type["double&"]="out double"
35   idl_arg_type["float&"]="out float"
36   idl_arg_type["long&"]="out long"
37   idl_arg_type["short&"]="out short"
38   idl_arg_type["unsigned&"]="out unsigned long"
39   idl_arg_type["std::string&"]="out string"
40   idl_arg_type["const MEDMEM::MESH&"]="in SALOME_MED::MESH"
41   idl_arg_type["const MEDMEM::MESH*"]="in SALOME_MED::MESH"
42   idl_arg_type["const MEDMEM::SUPPORT&"]="in SALOME_MED::SUPPORT"
43   idl_arg_type["const MEDMEM::SUPPORT*"]="in SALOME_MED::SUPPORT"
44   idl_arg_type["const MEDMEM::FIELD<double>*"]="in SALOME_MED::FIELDDOUBLE"
45   idl_arg_type["const MEDMEM::FIELD<double>&"]="in SALOME_MED::FIELDDOUBLE"
46   idl_arg_type["MEDMEM::FIELD<double>*&"]="out SALOME_MED::FIELDDOUBLE"
47   idl_arg_type["const std::vector<double>&"]="in SALOME::vectorOfDouble"
48   idl_arg_type["const std::vector<std::vector<double> >&"]="in SALOME::Matrix"
49   idl_arg_type["std::vector<double>*&"]="out SALOME::vectorOfDouble"
50   idl_arg_type["const MEDMEM::FIELD<int>*"]="in SALOME_MED::FIELDINT"
51   idl_arg_type["const MEDMEM::FIELD<int>&"]="in SALOME_MED::FIELDINT"
52   idl_arg_type["MEDMEM::FIELD<int>*&"]="out SALOME_MED::FIELDINT"
53   idl_arg_type["const std::vector<int>&"]="in SALOME::vectorOfLong"
54   idl_arg_type["std::vector<int>*&"]="out SALOME::vectorOfLong"
55   idl_arg_type["const ParaMEDMEM::MEDCouplingFieldDouble*"]="in SALOME_MED::MEDCouplingFieldDoubleCorbaInterface"
56 #
57 #
58 # mapping for returned types
59 #
60   idl_rtn_type["void"]="void"
61   idl_rtn_type["int"]="long"
62   idl_rtn_type["bool"]="boolean"
63   idl_rtn_type["double"]="double"
64   idl_rtn_type["float"]="float"
65   idl_rtn_type["long"]="long"
66   idl_rtn_type["short"]="short"
67   idl_rtn_type["unsigned"]="unsigned long"
68   idl_rtn_type["const char*"]="string"
69   idl_rtn_type["char*"]="string"
70   idl_rtn_type["std::string"]="string"
71   idl_rtn_type["const MEDMEM::MESH&"]="SALOME_MED::MESH"
72   idl_rtn_type["MEDMEM::MESH&"]="SALOME_MED::MESH"
73   idl_rtn_type["MEDMEM::MESH*"]="SALOME_MED::MESH"
74   idl_rtn_type["const MEDMEM::MESH*"]="SALOME_MED::MESH"
75   idl_rtn_type["MEDMEM::SUPPORT*"]="SALOME_MED::SUPPORT"
76   idl_rtn_type["const MEDMEM::FIELD<double>*"]="SALOME_MED::FIELDDOUBLE"
77   idl_rtn_type["MEDMEM::FIELD<double>*"]="SALOME_MED::FIELDDOUBLE"
78   idl_rtn_type["MEDMEM::FIELD<double>&"]="SALOME_MED::FIELDDOUBLE"
79   idl_rtn_type["const MEDMEM::FIELD<double>&"]="SALOME_MED::FIELDDOUBLE"
80   idl_rtn_type["std::vector<double>*"]="SALOME::vectorOfDouble"
81   idl_rtn_type["std::vector<std::vector<double> >*"]="SALOME::Matrix"
82   idl_rtn_type["const MEDMEM::FIELD<int>*"]="SALOME_MED::FIELDINT"
83   idl_rtn_type["MEDMEM::FIELD<int>*"]="SALOME_MED::FIELDINT"
84   idl_rtn_type["MEDMEM::FIELD<int>&"]="SALOME_MED::FIELDINT"
85   idl_rtn_type["const MEDMEM::FIELD<int>&"]="SALOME_MED::FIELDINT"
86   idl_rtn_type["std::vector<int>*"]="SALOME::vectorOfLong"
87   idl_rtn_type["std::vector<std::string>"]="StrSeq"
88   idl_rtn_type["ParaMEDMEM::MEDCouplingUMesh*"]="SALOME_MED::MEDCouplingUMeshCorbaInterface"
89   idl_rtn_type["ParaMEDMEM::MEDCouplingFieldDouble*"]="SALOME_MED::MEDCouplingFieldDoubleCorbaInterface"
90 #
91 #
92 # Corba mapping table (for argument's types and returned types)
93 #
94   idl_impl_hxx["in long"]="CORBA::Long"
95   idl_impl_hxx["in boolean"]="CORBA::Boolean"
96   idl_impl_hxx["in double"]="CORBA::Double"
97   idl_impl_hxx["in float"]="CORBA::Float"
98   idl_impl_hxx["in short"]="CORBA::Short"
99   idl_impl_hxx["in unsigned long"]="CORBA::ULong"
100   idl_impl_hxx["in string"]="const char*"
101   idl_impl_hxx["out long"]="CORBA::Long_out"
102   idl_impl_hxx["out boolean"]="CORBA::Boolean_out"
103   idl_impl_hxx["out double"]="CORBA::Double_out"
104   idl_impl_hxx["out float"]="CORBA::Float_out"
105   idl_impl_hxx["out short"]="CORBA::Short_out"
106   idl_impl_hxx["out unsigned long"]="CORBA::ULong_out"
107   idl_impl_hxx["out string"]="CORBA::String_out"
108   idl_impl_hxx["in SALOME_MED::MESH"]="SALOME_MED::MESH_ptr"
109   idl_impl_hxx["in SALOME_MED::SUPPORT"]="SALOME_MED::SUPPORT_ptr"
110   idl_impl_hxx["in SALOME_MED::FIELDDOUBLE"]="SALOME_MED::FIELDDOUBLE_ptr"
111   idl_impl_hxx["out SALOME_MED::FIELDDOUBLE"]="SALOME_MED::FIELDDOUBLE_out"
112   idl_impl_hxx["in SALOME::vectorOfDouble"]="const SALOME::vectorOfDouble&"
113   idl_impl_hxx["out SALOME::vectorOfDouble"]="SALOME::vectorOfDouble_out"
114   idl_impl_hxx["in SALOME::Matrix"]="SALOME::Matrix_ptr"
115   idl_impl_hxx["in SALOME_MED::FIELDINT"]="SALOME_MED::FIELDINT_ptr"
116   idl_impl_hxx["out SALOME_MED::FIELDINT"]="SALOME_MED::FIELDINT_out"
117   idl_impl_hxx["in SALOME::vectorOfLong"]="const SALOME::vectorOfLong&"
118   idl_impl_hxx["out SALOME::vectorOfLong"]="SALOME::vectorOfLong_out"
119   idl_impl_hxx["void"]="void"
120   idl_impl_hxx["long"]="CORBA::Long"
121   idl_impl_hxx["boolean"]="CORBA::Boolean"
122   idl_impl_hxx["double"]="CORBA::Double"
123   idl_impl_hxx["unsigned long"]="CORBA::ULong"
124   idl_impl_hxx["string"]="char*"
125   idl_impl_hxx["SALOME_MED::MESH"]="SALOME_MED::MESH_ptr"
126   idl_impl_hxx["SALOME_MED::SUPPORT"]="SALOME_MED::SUPPORT_ptr"
127   idl_impl_hxx["SALOME_MED::FIELDDOUBLE"]="SALOME_MED::FIELDDOUBLE_ptr"
128   idl_impl_hxx["SALOME::vectorOfDouble"]="SALOME::vectorOfDouble*"
129   idl_impl_hxx["SALOME::Matrix"]="SALOME::Matrix_ptr"
130   idl_impl_hxx["SALOME_MED::FIELDINT"]="SALOME_MED::FIELDINT_ptr"
131   idl_impl_hxx["SALOME::vectorOfLong"]="SALOME::vectorOfLong*"
132   idl_impl_hxx["StrSeq"]=class_name"_ORB::StrSeq*"
133   idl_impl_hxx["in SALOME_MED::MEDCouplingFieldDoubleCorbaInterface"]="SALOME_MED::MEDCouplingFieldDoubleCorbaInterface_ptr"
134   idl_impl_hxx["SALOME_MED::MEDCouplingUMeshCorbaInterface"]="SALOME_MED::MEDCouplingUMeshCorbaInterface_ptr"
135   idl_impl_hxx["SALOME_MED::MEDCouplingFieldDoubleCorbaInterface"]="SALOME_MED::MEDCouplingFieldDoubleCorbaInterface_ptr"
136 #
137 #
138 # table for c++ code generation : argument's processing
139 #
140   cpp_impl_a["int"]="\tint _%s(%s);\n"
141   cpp_impl_a["bool"]="\tbool _%s(%s);\n"
142   cpp_impl_a["double"]="\tdouble _%s(%s);\n"
143   cpp_impl_a["float"]="\tfloat _%s(%s);\n"
144   cpp_impl_a["long"]="\tlong _%s(%s);\n"
145   cpp_impl_a["short"]="\tshort _%s(%s);\n"
146   cpp_impl_a["unsigned"]="\tunsigned _%s(%s);\n"
147   cpp_impl_a["const char*"]="\tconst char* _%s(%s);\n"
148   cpp_impl_a["const std::string&"]="\tconst std::string _%s(%s);\n"
149   cpp_impl_a["int&"]="\tint _%s;\n"
150   cpp_impl_a["bool&"]="\tbool _%s;\n"
151   cpp_impl_a["double&"]="\tdouble _%s;\n"
152   cpp_impl_a["float&"]="\tfloat _%s;\n"
153   cpp_impl_a["long&"]="\tlong _%s;\n"
154   cpp_impl_a["short&"]="\tshort _%s;\n"
155   cpp_impl_a["unsigned&"]="\tunsigned _%s;\n"
156   cpp_impl_a["std::string&"]="\tstd::string _%s;\n"
157   cpp_impl_a["const MEDMEM::MESH&"]="\tMEDMEM::MESHClient* _%s = new MEDMEM::MESHClient(%s);\n\t _%s->fillCopy();\n" # MESHClient cannot be created on the stack (private constructor), so we create it on the heap and dereference it later (in treatment 4)
158   cpp_impl_a["const MEDMEM::MESH*"]="\tMEDMEM::MESHClient* _%s = new MEDMEM::MESHClient(%s);\n\t _%s->fillCopy();\n"
159   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)
160   cpp_impl_a["const MEDMEM::SUPPORT*"]="\tMEDMEM::SUPPORTClient* _%s = new MEDMEM::SUPPORTClient(%s);\n"
161   cpp_impl_a["MEDMEM::FIELD<double>*&"]="\tMEDMEM::FIELD<double>* _%s;\n"
162   cpp_impl_a["const MEDMEM::FIELD<double>*"]="\tstd::auto_ptr<MEDMEM::FIELD<double> > _%s ( new MEDMEM::FIELDClient<double,MEDMEM::FullInterlace>(%s) );\n"
163   cpp_impl_a["const MEDMEM::FIELD<double>&"]="\tMEDMEM::FIELDClient<double,MEDMEM::FullInterlace> _%s(%s);\n"
164   cpp_impl_a["const std::vector<double>&"]="\tlong _%s_size=%s.length();\n\tconst double *_%s_value = &%s[0];\n"\
165              "\tstd::vector<double> _%s(_%s_value,_%s_value+_%s_size);\n"
166 #  cpp_impl_a["const std::vector<double>&"]="\tlong _%s_size;\n\tdouble *_%s_value = ReceiverFactory::getValue(%s,_%s_size);\n"\
167 #             "\tstd::vector<double> _%s(_%s_value,_%s_value+_%s_size);\n\tdelete [] _%s_value;"
168   cpp_impl_a["std::vector<double>*&"]="\tstd::vector<double>* _%s;\n"
169   cpp_impl_a["const std::vector<std::vector<double> >&"]="\tMatrixClient _%s_client;\n\tint _%s_nbRow;\n\tint _%s_nbCol;\n"\
170              "\tdouble* _%s_tab = _%s_client.getValue(%s,_%s_nbCol,_%s_nbRow);\n\tstd::vector<std::vector<double> > _%s(_%s_nbRow);\n"\
171              "\tfor (int i=0; i!=_%s_nbRow; ++i)\n\t{\n\t    _%s[i].resize(_%s_nbCol);\n"\
172              "\t    std::copy(_%s_tab+_%s_nbCol*i,_%s_tab+_%s_nbCol*(i+1), _%s[i].begin());\n\t}\n\tdelete [] _%s_tab;\n"
173   cpp_impl_a["MEDMEM::FIELD<int>*&"]="\tMEDMEM::FIELD<int>* _%s;\n"
174   cpp_impl_a["const MEDMEM::FIELD<int>*"]="\tstd::auto_ptr<MEDMEM::FIELD<int> > _%s ( new MEDMEM::FIELDClient<int>(%s) );\n"
175   cpp_impl_a["const MEDMEM::FIELD<int>&"]="\tMEDMEM::FIELDClient<int> _%s(%s);\n"
176   cpp_impl_a["const std::vector<int>&"]="\tlong _%s_size=%s.length();\n"\
177                          "\tstd::vector<int> _%s(_%s_size);\n"\
178                          "\tfor (int i=0; i!=_%s_size; ++i)\n\t    _%s[i]=%s[i];"
179 #  cpp_impl_a["const std::vector<int>&"]="\tlong _%s_size;\n\tint *_%s_value = ReceiverFactory::getValue(%s,_%s_size);\n"\
180 #             "\tstd::vector<int> _%s(_%s_value,_%s_value+_%s_size);\n\tdelete [] _%s_value;"
181   cpp_impl_a["std::vector<int>*&"]="\tstd::vector<int>* _%s;\n"
182   cpp_impl_a["const ParaMEDMEM::MEDCouplingFieldDouble*"]="\tParaMEDMEM::MEDCouplingFieldDouble* _%s=ParaMEDMEM::MEDCouplingFieldDoubleClient::New(%s);\n"
183 #
184 #
185 # table for c++ code generation : returned value processing
186 #
187   cpp_impl_b["void"]=""
188   cpp_impl_b["int"]="\tCORBA::Long _rtn_ior(_rtn_cpp);\n"
189   cpp_impl_b["bool"]="\tCORBA::Boolean _rtn_ior(_rtn_cpp);\n"
190   cpp_impl_b["double"]="\tCORBA::Double _rtn_ior(_rtn_cpp);\n"
191   cpp_impl_b["float"]="\tCORBA::Float _rtn_ior(_rtn_cpp);\n"
192   cpp_impl_b["long"]="\tCORBA::Long _rtn_ior(_rtn_cpp);\n"
193   cpp_impl_b["short"]="\tCORBA::Short _rtn_ior(_rtn_cpp);\n"
194   cpp_impl_b["unsigned"]="\tCORBA::ULong _rtn_ior(_rtn_cpp);\n"
195   cpp_impl_b["const char*"]="\tchar* _rtn_ior = CORBA::string_dup(_rtn_cpp);\n"
196   cpp_impl_b["char*"]="\tchar* _rtn_ior(_rtn_cpp);\n"
197   cpp_impl_b["std::string"]="\tchar* _rtn_ior=CORBA::string_dup(_rtn_cpp.c_str());\n"
198              "\tstd::copy(_rtn_cpp.begin(),_rtn_cpp.end(),_rtn_ior);\n"    
199   cpp_impl_b["const MEDMEM::MESH&"]=\
200              "\tMEDMEM::MESH_i * _rtn_mesh_i = new MEDMEM::MESH_i(const_cast<MEDMEM::MESH*>(&_rtn_cpp));\n"\
201              "\tSALOME_MED::MESH_ptr _rtn_ior = _rtn_mesh_i->_this();\n"
202   cpp_impl_b["MEDMEM::MESH&"]=\
203              "\tMEDMEM::MESH_i * _rtn_mesh_i = new MEDMEM::MESH_i(&_rtn_cpp);\n"\
204              "\tSALOME_MED::MESH_ptr _rtn_ior = _rtn_mesh_i->_this();\n"
205   cpp_impl_b["MEDMEM::MESH*"]=\
206              "\tMEDMEM::MESH_i * _rtn_mesh_i = new MEDMEM::MESH_i(_rtn_cpp);\n"\
207              "\tSALOME_MED::MESH_ptr _rtn_ior = _rtn_mesh_i->_this();\n"
208   cpp_impl_b["const MEDMEM::MESH*"]=\
209              "\tMEDMEM::MESH_i * _rtn_mesh_i = new MEDMEM::MESH_i(const_cast<MEDMEM::MESH*>(_rtn_cpp));\n"\
210              "\tSALOME_MED::MESH_ptr _rtn_ior = _rtn_mesh_i->_this();\n"
211   cpp_impl_b["MEDMEM::SUPPORT*"]=\
212              "\tMEDMEM::SUPPORT_i * _rtn_support_i = new MEDMEM::SUPPORT_i(_rtn_cpp);\n"\
213              "\tSALOME_MED::SUPPORT_ptr _rtn_ior = _rtn_support_i->_this();\n"
214   cpp_impl_b["const MEDMEM::FIELD<double>*"]=\
215              "\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"\
216              "\tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"
217   cpp_impl_b["MEDMEM::FIELD<double>*"]=\
218              "\tMEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace> * _rtn_field_i = new MEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace>(_rtn_cpp,true);\n"\
219              "\tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"
220   cpp_impl_b["MEDMEM::FIELD<double>&"]=\
221              "\tMEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace> * _rtn_field_i = new MEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace>(&_rtn_cpp,false);\n"\
222              "\tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"
223   cpp_impl_b["const MEDMEM::FIELD<double>&"]=\
224              "\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"\
225              "\tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"
226   cpp_impl_b["std::vector<double>*"]=\
227              "\tSALOME::vectorOfDouble * _rtn_ior = new SALOME::vectorOfDouble;\n"\
228              "\tint _rtn_cpp_length=(*_rtn_cpp).size();\n"\
229              "\t_rtn_ior->length(_rtn_cpp_length);\n"\
230              "\tfor (int i=0; i<_rtn_cpp_length; ++i)\n\t    (*_rtn_ior)[i] = (*_rtn_cpp)[i];\n"
231 #  cpp_impl_b["std::vector<double>*"]=\
232 #             "\tSALOME::SenderDouble_ptr _rtn_ior = SenderFactory::buildSender(*this,&(*_rtn_cpp)[0],(*_rtn_cpp).size(),true);\n"
233   cpp_impl_b["std::vector<std::vector<double> >*"]=\
234              "\tint _rtn_cpp_i=(*_rtn_cpp).size();\n\tint _rtn_cpp_j=(*_rtn_cpp)[0].size();\n"\
235              "\tdouble* _rtn_tab = new double[_rtn_cpp_i*_rtn_cpp_j];\n"\
236              "\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"\
237              "\tSALOME_Matrix_i* _rtn_matrix_i = new SALOME_Matrix_i(*this,_rtn_tab,_rtn_cpp_i,_rtn_cpp_j,true);\n"\
238              "\tSALOME::Matrix_ptr _rtn_ior = _rtn_matrix_i->_this();\n\tdelete _rtn_cpp;\n"
239   cpp_impl_b["const MEDMEM::FIELD<int>*"]=\
240              "\tMEDMEM::FIELDINT_i * _rtn_field_i = new MEDMEM::FIELDINT_i(const_cast<MEDMEM::FIELD<int>*>(_rtn_cpp),false);\n"\
241              "\tSALOME_MED::FIELDINT_ptr _rtn_ior = _rtn_field_i->_this();\n"
242   cpp_impl_b["MEDMEM::FIELD<int>*"]=\
243              "\tMEDMEM::FIELDINT_i * _rtn_field_i = new MEDMEM::FIELDINT_i(_rtn_cpp,true);\n"\
244              "\tSALOME_MED::FIELDINT_ptr _rtn_ior = _rtn_field_i->_this();\n"
245   cpp_impl_b["MEDMEM::FIELD<int>&"]=\
246              "\tMEDMEM::FIELDINT_i * _rtn_field_i = new MEDMEM::FIELDINT_i(&_rtn_cpp,false);\n"\
247              "\tSALOME_MED::FIELDINT_ptr _rtn_ior = _rtn_field_i->_this();\n"
248   cpp_impl_b["const MEDMEM::FIELD<int>&"]=\
249              "\tMEDMEM::FIELDINT_i * _rtn_field_i = new MEDMEM::FIELDINT_i(const_cast<MEDMEM::FIELD<int>*>(&_rtn_cpp),false);\n"\
250              "\tSALOME_MED::FIELDINT_ptr _rtn_ior = _rtn_field_i->_this();\n"
251   cpp_impl_b["std::vector<int>*"]=\
252              "\tSALOME::vectorOfLong * _rtn_ior = new SALOME::vectorOfLong;\n"\
253              "\tint _rtn_cpp_length=(*_rtn_cpp).size();\n"\
254              "\t_rtn_ior->length(_rtn_cpp_length);\n"\
255              "\tfor (int i=0; i<_rtn_cpp_length; ++i)\n\t    (*_rtn_ior)[i] = (*_rtn_cpp)[i];\n"
256   cpp_impl_b["std::vector<std::string>"]=\
257              "\t"class_name"_ORB::StrSeq*_rtn_ior = new "class_name"_ORB::StrSeq;\n"\
258              "\tint _rtn_cpp_length=_rtn_cpp.size();\n"\
259              "\t_rtn_ior->length(_rtn_cpp_length);\n"\
260              "\tfor (int i=0; i<_rtn_cpp_length; ++i)\n"\
261              "\t    (*_rtn_ior)[i] = _rtn_cpp[i].c_str();\n"
262   cpp_impl_b["ParaMEDMEM::MEDCouplingFieldDouble*"]=\
263              "\tParaMEDMEM::MEDCouplingFieldDoubleServant * _rtn_field_i = new ParaMEDMEM::MEDCouplingFieldDoubleServant(_rtn_cpp);\n"\
264              "\t_rtn_cpp->decrRef();\n"\
265              "\tSALOME_MED::MEDCouplingFieldDoubleCorbaInterface_ptr _rtn_ior = _rtn_field_i->_this();\n"
266   cpp_impl_b["ParaMEDMEM::MEDCouplingUMesh*"]=\
267              "\tParaMEDMEM::MEDCouplingUMeshServant * _rtn_mesh_i = new ParaMEDMEM::MEDCouplingUMeshServant(_rtn_cpp);\n"\
268              "\t_rtn_cpp->decrRef();\n"\
269              "\tSALOME_MED::MEDCouplingUMeshCorbaInterface_ptr _rtn_ior = _rtn_mesh_i->_this();\n"
270 #  cpp_impl_b["std::vector<int>*"]=\
271 #             "\tSALOME::SenderInt_ptr _rtn_ior = SenderFactory::buildSender(*this,&(*_rtn_cpp)[0],(*_rtn_cpp).size(),true);\n"
272
273 #
274 #
275 # table for c++ code generation : out parameters processing and removeRef for reference counted objects
276 #
277   cpp_impl_c["MEDMEM::FIELD<double>*&"]=\
278              "\tMEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace> * %s_ior = new MEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace>(_%s, true);\n"\
279              "\t%s = %s_ior->_this();\n"
280   cpp_impl_c["MEDMEM::FIELD<int>*&"]=\
281              "\tMEDMEM::FIELDINT_i * %s_ior = new MEDMEM::FIELDINT_i(_%s, true);\n"\
282              "\t%s = %s_ior->_this();\n"
283   cpp_impl_c["std::vector<double>*&"]=\
284              "\t%s = new SALOME::vectorOfDouble;\n"\
285              "\t%s->length((*_%s).size());\n"\
286              "\tfor (int i=0; i<(*_%s).size(); ++i)\n\t    (*%s)[i] = (*_%s)[i];\n"
287 #             "\t%s = SenderFactory::buildSender(*this,&(*_%s)[0],(*_%s).size(),true);\n"
288   cpp_impl_c["std::vector<int>*&"]=\
289              "\t%s = new SALOME::vectorOfLong;\n"\
290              "\t%s->length((*_%s).size());\n"\
291              "\tfor (int i=0; i<(*_%s).size(); ++i)\n\t    (*%s)[i] = (*_%s)[i];\n"
292 #             "\t%s = SenderFactory::buildSender(*this,&(*_%s)[0],(*_%s).size(),true);\n"
293   cpp_impl_c["std::string&"]="\t%s = CORBA::string_dup(_%s.c_str());\n"
294   cpp_impl_c["int&"]="\t%s = _%s;\n"
295   cpp_impl_c["bool&"]="\t%s = _%s;\n"
296   cpp_impl_c["double&"]="\t%s = _%s;\n"
297   cpp_impl_c["float&"]="\t%s = _%s;\n"
298   cpp_impl_c["long&"]="\t%s = _%s;\n"
299   cpp_impl_c["short&"]="\t%s = _%s;\n"
300   cpp_impl_c["unsigned&"]="\t%s = _%s;\n"
301   cpp_impl_c["const MEDMEM::MESH&"]="\t_%s->removeReference();\n"
302   cpp_impl_c["const MEDMEM::MESH*"]="\t_%s->removeReference();\n"
303   cpp_impl_c["const MEDMEM::SUPPORT&"]="\t_%s->removeReference();\n"
304   cpp_impl_c["const MEDMEM::SUPPORT*"]="\t_%s->removeReference();\n"
305   cpp_impl_c["const ParaMEDMEM::MEDCouplingFieldDouble*"]="\t_%s->decrRef();\n"
306 #
307 #
308 # record sep is ");\n" whith blanks all around, and optional "(" at the beginning
309   RS="[(]?[ \t]*[)][ \t]*(const)?[ \t]*[;][ \t]*[\n]"  
310   FS="[ \t]*[(,][ \t]*"  # field sep is either "(" or "," surrounded by blanks 
311 }
312
313 # --------------------- treatment 1 ----------------------------------
314 #
315 #  extract from fields types, function name, and argument's names
316 #
317 {
318   print "Function : ",$0 >> "parse_result"  # print for debug
319   for (i=1; i<=NF; i++) {
320       print "\t-> ",i," : ",$i >> "parse_result"
321   }
322   ok1=0;ok=1
323   error_message="\t  The non compatible types are : "
324   # check if returned type ($1) is one of the accepted types (idl_rtn_type)
325   for (cpptype in idl_rtn_type) {
326     if ( substr($1,1,length(cpptype)) == cpptype ) {
327       # if compatible, store returned type and function name
328       type[1]=cpptype
329       name[1]=substr($1,length(cpptype)+1)
330       sub("^[ \t]*","",name[1]) # get rid of leading blanks
331       ok1=1
332       break
333     }
334   }
335   ok*=ok1
336   if ( ! ok1) {
337       split($1,tab," ") 
338       error_message=error_message sprintf("\n\t\t-> %s (return type)",tab[1])
339   }
340   # for each argument ($i), check if it is compatible (belongs to idl_arg_type)
341   for (i=2; i<=NF; i++) {
342     ok2=0
343     split($i,tab,"=") # get rid of default value
344     item=tab[1]
345     sub("/[ \t]*&[ \t]*/", "&", item) # supress spaces around * and $
346     sub("/[ \t]**[ \t]*/", "*", item)
347     for (cpptype in idl_arg_type) {
348         l = length(cpptype)
349         s0 = substr(item,1,l) # to discriminate between int and int&, ...
350         s1 = " "
351         if (length(item) > l)
352             s1 = substr(item, l+1, 1)
353
354         if ( (s0 == cpptype) && (s1 == " ") ) {
355           # if compatible, store argument type and name
356           type[i]=cpptype
357           name[i]=substr(item,length(cpptype)+1)
358           sub("^[ \t]*","",name[i]) # get rid of leading blanks
359           if ( length(name[i]) == 0 ) # automatic name if argument's name wasn't precised
360              name[i]=sprintf("_arg%d",i-1)
361           ok2=1
362           break
363        }
364     }
365     ok*=ok2 # ok=0 if one of the type is not compatible
366     if ( ! ok2) {
367         error_message=error_message "\n\t\t-> "item
368     }
369   }
370
371   # print compatibility 
372   if ( $0 !~ class_name ) { # constructor are not considered, but we don't print it
373       if ( ok == 0){ # if one of the c++ type is not compatible
374           printf "     [KO]     :  %s",$0
375       }
376       else
377           printf "     [OK]     :  %s",$0
378         
379       if ( $0 !~ /\(/  ) {
380           printf "(" # if there is no argument, parenthesis was suppressed, so we add it for printing
381       }
382       printf ");\n"
383       if ( ok == 0){ #print the error message
384           printf "%s\n\n",error_message
385       }
386   }    
387   if ( ok == 0) # pass to the next function if one of the c++ type is not compatible
388       next
389 }
390 #
391 # --------------------- treatment 2 ----------------------------------
392 #
393 #  generate the Corba interface (idl file)
394 #
395
396   printf "\t%s %s(", idl_rtn_type[type[1]],name[1] >> idl_file  # return type and name of function
397   if ( NF >= 2 ){  # if there is arguments, print them
398     for (i=2; i<=NF-1; i++)
399       printf "%s %s,",idl_arg_type[type[i]],name[i] >> idl_file
400     printf "%s %s", idl_arg_type[type[NF]],name[NF] >> idl_file
401   }
402   printf ") raises (SALOME::SALOME_Exception);\n" >> idl_file
403 }  
404 #
405 # --------------------- treatment 3 ----------------------------------
406 #
407 #  generate the C++ implementation of component (hxx file)
408 #
409
410   printf "    %s %s(",idl_impl_hxx[idl_rtn_type[type[1]]],name[1] >> hxx_file
411   if ( NF >= 2 ){  # if there is arguments, print them
412       for (i=2; i<=NF-1; i++)
413           printf "%s %s,",idl_impl_hxx[idl_arg_type[type[i]]],name[i] >> hxx_file
414       printf "%s %s", idl_impl_hxx[idl_arg_type[type[NF]]],name[NF] >> hxx_file
415   }
416   printf ") throw (SALOME::SALOME_Exception);\n" >> hxx_file
417 }
418 #
419 # --------------------- treatment 4 ----------------------------------
420 #
421 #  generate the C++ implementation of component (cxx file)
422 #
423 {
424   # a) generate the function declaration + macro declarations
425   func_name=class_name"_i::"name[1]
426   printf "%s %s(",idl_impl_hxx[idl_rtn_type[type[1]]],func_name >> cxx_file
427   if ( NF >= 2 ){  # if there is arguments, print them
428       for (i=2; i<=NF-1; i++)
429           printf "%s %s,",idl_impl_hxx[idl_arg_type[type[i]]],name[i] >> cxx_file
430       printf "%s %s", idl_impl_hxx[idl_arg_type[type[NF]]],name[NF] >> cxx_file
431   }
432   printf ") throw (SALOME::SALOME_Exception)\n{\n    beginService(\"%s\");\n    BEGIN_OF(\"%s\");\n    try\n    {\n",func_name,func_name >> cxx_file
433
434   # b) generate the argument processing part
435   if ( NF >= 2 ){
436       printf "//\tArguments processing\n" >> cxx_file
437       for (i=2; i<=NF; i++)
438           printf cpp_impl_a[type[i]],name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i],\
439                            name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i] >> cxx_file
440   }
441
442   # c) generate the call to the c++ component
443   if ( type[1] == "void" ) # if return type is void, the call syntax is different.
444       printf "//\tCall cpp component\n\tcppCompo_->%s(",name[1] >> cxx_file
445   else
446       printf "//\tCall cpp component\n\t%s _rtn_cpp = cppCompo_->%s(",type[1],name[1] >> cxx_file
447   if ( NF >= 2 ){  # if there is arguments, print them
448       for (i=2; i<=NF; i++) {
449           # special treatment for some arguments
450           post=""
451           pre=""
452           if ( cpp_impl_a[type[i]] ~ "auto_ptr" )
453              post=".get()" # for auto_ptr argument, retrieve the raw pointer behind
454           if ( type[i] == "const MEDMEM::MESH&" || type[i] == "const MEDMEM::SUPPORT&" )
455              pre="*"  # we cannot create MESHClient on the stack (private constructor), so we create it on the heap and dereference it
456           if ( i < NF )
457              post=post"," # separator between arguments
458           printf " %s_%s%s",pre,name[i],post >> cxx_file
459       }
460   }
461
462   # d) generate the post_processing of returned and out parameters
463   printf ");\n//\tPost-processing & return\n" >> cxx_file
464   for (i=2; i<=NF; i++)
465       printf cpp_impl_c[type[i]],name[i],name[i],name[i],name[i],name[i],name[i] >> cxx_file  # process for out parameters
466   printf cpp_impl_b[type[1]] >> cxx_file  # process for returned value
467   printf "\tendService(\"%s\");\n\tEND_OF(\"%s\");\n",func_name,func_name >> cxx_file
468   if ( type[1] != "void" )
469       printf "\treturn _rtn_ior;\n" >> cxx_file
470   printf "    }\n    catch (std::exception& ex)\n    {\n        THROW_SALOME_CORBA_EXCEPTION( ex.what(), SALOME::INTERNAL_ERROR );\n    }\n" >> cxx_file
471   printf "}\n\n" >> cxx_file
472 }
473 #
474 #
475 END {
476 # CNC peut être mis dans le template directement printf "\nprivate:\n    std::auto_ptr<%s> cppImpl_;\n",class_name >> hxx_file
477 }