Salome HOME
Add COPYING license file
[tools/yacsgen.git] / module_generator / hxx_awk.py
1 # Copyright (C) 2009-2024  EDF
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 # only the first two characters of the map are actually used to find out in/out caracteristic
21 cpp2idl_mapping={}
22 cpp2idl_mapping["int"]="in long"
23 cpp2idl_mapping["bool"]="in boolean"
24 cpp2idl_mapping["double"]="in double"
25 cpp2idl_mapping["float"]="in float"
26 cpp2idl_mapping["long"]="in long"
27 cpp2idl_mapping["short"]="in short"
28 cpp2idl_mapping["unsigned"]="in unsigned long"
29 cpp2idl_mapping["const char*"]="in string"
30 cpp2idl_mapping["const std::string&"]="in string"
31 cpp2idl_mapping["int&"]="out long"
32 cpp2idl_mapping["bool&"]="out boolean"
33 cpp2idl_mapping["double&"]="out double"
34 cpp2idl_mapping["float&"]="out float"
35 cpp2idl_mapping["long&"]="out long"
36 cpp2idl_mapping["short&"]="out short"
37 cpp2idl_mapping["unsigned&"]="out unsigned long"
38 cpp2idl_mapping["std::string&"]="out string"
39 cpp2idl_mapping["const MEDMEM::MESH&"]="in SALOME_MED::MESH"
40 cpp2idl_mapping["const MEDMEM::MESH*"]="in SALOME_MED::MESH"
41 cpp2idl_mapping["const MEDMEM::SUPPORT&"]="in SALOME_MED::SUPPORT"
42 cpp2idl_mapping["const MEDMEM::SUPPORT*"]="in SALOME_MED::SUPPORT"
43 cpp2idl_mapping["const MEDMEM::FIELD<double>*"]="in SALOME_MED::FIELDDOUBLE"
44 cpp2idl_mapping["const MEDMEM::FIELD<double>&"]="in SALOME_MED::FIELDDOUBLE"
45 cpp2idl_mapping["MEDMEM::FIELD<double>*&"]="out SALOME_MED::FIELDDOUBLE"
46 cpp2idl_mapping["const std::vector<double>&"]="in %(module)s::dblevec"
47 cpp2idl_mapping["const std::vector<std::vector<double> >&"]="in SALOME::Matrix"
48 cpp2idl_mapping["std::vector<double>*&"]="out %(module)s::dblevec"
49 cpp2idl_mapping["const MEDMEM::FIELD<int>*"]="in SALOME_MED::FIELDINT"
50 cpp2idl_mapping["const MEDMEM::FIELD<int>&"]="in SALOME_MED::FIELDINT"
51 cpp2idl_mapping["MEDMEM::FIELD<int>*&"]="out SALOME_MED::FIELDINT"
52 cpp2idl_mapping["const std::vector<int>&"]="in %(module)s::intvec"
53 cpp2idl_mapping["std::vector<int>*&"]="out %(module)s::intvec"
54 cpp2idl_mapping["const MEDCoupling::MEDCouplingFieldDouble*"]="in SALOME_MED::MEDCouplingFieldDoubleCorbaInterface"
55 cpp2idl_mapping["const MEDCoupling::MEDCouplingFieldDouble&"]="in SALOME_MED::MEDCouplingFieldDoubleCorbaInterface"
56 cpp2idl_mapping["MEDCoupling::MEDCouplingFieldDouble*&"]="out SALOME_MED::MEDCouplingFieldDoubleCorbaInterface"
57 cpp2idl_mapping["const MEDCoupling::MEDCouplingUMesh*"]="in SALOME_MED::MEDCouplingUMeshCorbaInterface"
58
59 # ['stringvec', 'string', 'double', 'long', 'dblevec', 'file', 'intvec', 'dataref', 'GEOM_Object', 'SMESH_Mesh', 'SMESH_Hypothesis', 'SALOME_MED/MED', 'SALOME_MED/MESH', 'SALOME_MED/SUPPORT', 'SALOME_MED/FIELD', 'SALOME_MED/FIELDDOUBLE', 'SALOME_MED/FIELDINT']
60 cpp2yacs_mapping={}
61 cpp2yacs_mapping["int"]="long"
62 cpp2yacs_mapping["bool"]="boolean"
63 cpp2yacs_mapping["double"]="double"
64 #cpp2yacs_mapping["float"]="in float"
65 cpp2yacs_mapping["long"]="long"
66 #cpp2yacs_mapping["short"]="in short"
67 #cpp2yacs_mapping["unsigned"]="in unsigned long"
68 cpp2yacs_mapping["const char*"]="string"
69 cpp2yacs_mapping["const std::string&"]="string"
70 cpp2yacs_mapping["int&"]="long"
71 cpp2yacs_mapping["bool&"]="boolean"
72 cpp2yacs_mapping["double&"]="double"
73 #cpp2yacs_mapping["float&"]="out float"
74 cpp2yacs_mapping["long&"]="long"
75 #cpp2yacs_mapping["short&"]="out short"
76 #cpp2yacs_mapping["unsigned&"]="out unsigned long"
77 cpp2yacs_mapping["std::string&"]="string"
78 cpp2yacs_mapping["const MEDMEM::MESH&"]="SALOME_MED/MESH"
79 cpp2yacs_mapping["const MEDMEM::MESH*"]="SALOME_MED/MESH"
80 cpp2yacs_mapping["const MEDMEM::SUPPORT&"]="SALOME_MED/SUPPORT"
81 cpp2yacs_mapping["const MEDMEM::SUPPORT*"]="SALOME_MED/SUPPORT"
82 cpp2yacs_mapping["const MEDMEM::FIELD<double>*"]="SALOME_MED/FIELDDOUBLE"
83 cpp2yacs_mapping["const MEDMEM::FIELD<double>&"]="SALOME_MED/FIELDDOUBLE"
84 cpp2yacs_mapping["MEDMEM::FIELD<double>*&"]="SALOME_MED/FIELDDOUBLE"
85
86 cpp2yacs_mapping["const std::vector<double>&"]="dblevec"
87
88 cpp2yacs_mapping["const std::vector<std::vector<double> >&"]="SALOME/Matrix"
89
90 cpp2yacs_mapping["std::vector<double>*&"]="dblevec"
91
92 cpp2yacs_mapping["const MEDMEM::FIELD<int>*"]="SALOME_MED/FIELDINT"
93 cpp2yacs_mapping["const MEDMEM::FIELD<int>&"]="SALOME_MED/FIELDINT"
94 cpp2yacs_mapping["MEDMEM::FIELD<int>*&"]="SALOME_MED/FIELDINT"
95 cpp2yacs_mapping["const std::vector<int>&"]="intvec"
96 cpp2yacs_mapping["std::vector<int>*&"]="intvec"
97
98 cpp2yacs_mapping["void"]="void"
99 cpp2yacs_mapping["char*"]="string"
100 cpp2yacs_mapping["std::string"]="string"
101 cpp2yacs_mapping["MEDMEM::MESH&"]="SALOME_MED/MESH"
102 cpp2yacs_mapping["MEDMEM::MESH*"]="SALOME_MED/MESH"
103 cpp2yacs_mapping["MEDMEM::SUPPORT*"]="SALOME_MED/SUPPORT"
104 cpp2yacs_mapping["MEDMEM::FIELD<double>*"]="SALOME_MED/FIELDDOUBLE"
105 cpp2yacs_mapping["MEDMEM::FIELD<double>&"]="SALOME_MED/FIELDDOUBLE"
106 cpp2yacs_mapping["MEDMEM::FIELD<int>*"]="SALOME_MED/FIELDINT"
107 cpp2yacs_mapping["MEDMEM::FIELD<int>&"]="SALOME_MED/FIELDINT"
108
109 cpp2yacs_mapping["std::vector<double>*"]="dblevec"
110 cpp2yacs_mapping["std::vector<int>*"]="intvec"
111
112 cpp2yacs_mapping["std::vector<std::vector<double> >*"]="SALOME/Matrix"
113 cpp2yacs_mapping["std::vector<std::string>"]="stringvec"
114 cpp2yacs_mapping["const MEDCoupling::MEDCouplingFieldDouble*"]="SALOME_MED/MEDCouplingFieldDoubleCorbaInterface"
115 cpp2yacs_mapping["const MEDCoupling::MEDCouplingFieldDouble&"]="SALOME_MED/MEDCouplingFieldDoubleCorbaInterface"
116 cpp2yacs_mapping["const MEDCoupling::MEDCouplingUMesh*"]="SALOME_MED/MEDCouplingUMeshCorbaInterface"
117 cpp2yacs_mapping["MEDCoupling::MEDCouplingFieldDouble*&"]="SALOME_MED/MEDCouplingFieldDoubleCorbaInterface"
118 cpp2yacs_mapping["MEDCoupling::MEDCouplingUMesh*"]="SALOME_MED/MEDCouplingUMeshCorbaInterface"
119 cpp2yacs_mapping["MEDCoupling::MEDCouplingFieldDouble*"]="SALOME_MED/MEDCouplingFieldDoubleCorbaInterface"
120 cpp2yacs_mapping["MEDCoupling::DataArrayDouble*"]="SALOME_MED/DataArrayDoubleCorbaInterface"
121 # table for c++ code generation : argument's processing
122 cpp_impl_a={}
123 cpp_impl_a["int"]="\tint _%(arg)s(%(arg)s);\n"
124 cpp_impl_a["bool"]="\tbool _%(arg)s(%(arg)s);\n"
125 cpp_impl_a["double"]="\tdouble _%(arg)s(%(arg)s);\n"
126 cpp_impl_a["float"]="\tfloat _%(arg)s(%(arg)s);\n"
127 cpp_impl_a["long"]="\tlong _%(arg)s(%(arg)s);\n"
128 cpp_impl_a["short"]="\tshort _%(arg)s(%(arg)s);\n"
129 cpp_impl_a["unsigned"]="\tunsigned _%(arg)s(%(arg)s);\n"
130 cpp_impl_a["const char*"]="\tconst char* _%(arg)s(%(arg)s);\n"
131 cpp_impl_a["const std::string&"]="\tconst std::string _%(arg)s(%(arg)s);\n"
132 cpp_impl_a["int&"]="\tint _%(arg)s;\n"
133 cpp_impl_a["bool&"]="\tbool _%(arg)s;\n"
134 cpp_impl_a["double&"]="\tdouble _%(arg)s;\n"
135 cpp_impl_a["float&"]="\tfloat _%(arg)s;\n"
136 cpp_impl_a["long&"]="\tlong _%(arg)s;\n"
137 cpp_impl_a["short&"]="\tshort _%(arg)s;\n"
138 cpp_impl_a["unsigned&"]="\tunsigned _%(arg)s;\n"
139 cpp_impl_a["std::string&"]="\tstd::string _%(arg)s;\n"
140 cpp_impl_a["const MEDMEM::MESH&"]="\tMEDMEM::MESHClient* _%(arg)s = new MEDMEM::MESHClient(%(arg)s);\n\t _%(arg)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)
141 cpp_impl_a["const MEDMEM::MESH*"]="\tMEDMEM::MESHClient* _%(arg)s = new MEDMEM::MESHClient(%(arg)s);\n\t _%(arg)s->fillCopy();\n"
142 cpp_impl_a["const MEDMEM::SUPPORT&"]="\tMEDMEM::SUPPORTClient* _%(arg)s = new MEDMEM::SUPPORTClient(%(arg)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)
143 cpp_impl_a["const MEDMEM::SUPPORT*"]="\tMEDMEM::SUPPORTClient* _%(arg)s = new MEDMEM::SUPPORTClient(%(arg)s);\n"
144 cpp_impl_a["MEDMEM::FIELD<double>*&"]="\tMEDMEM::FIELD<double>* _%(arg)s;\n"
145 cpp_impl_a["const MEDMEM::FIELD<double>*"]="\tstd::auto_ptr<MEDMEM::FIELD<double> > _%(arg)s ( new MEDMEM::FIELDClient<double,MEDMEM::FullInterlace>(%(arg)s) );\n"
146 cpp_impl_a["const MEDMEM::FIELD<double>&"]="\tMEDMEM::FIELDClient<double,MEDMEM::FullInterlace> _%(arg)s(%(arg)s);\n"
147 cpp_impl_a["const std::vector<double>&"]="\tlong _%(arg)s_size=%(arg)s.length();\n\tconst double *_%(arg)s_value = &%(arg)s[0];\n"\
148            "\tstd::vector<double> _%(arg)s(_%(arg)s_value,_%(arg)s_value+_%(arg)s_size);\n"
149 cpp_impl_a["std::vector<double>*&"]="\tstd::vector<double>* _%(arg)s;\n"
150 cpp_impl_a["const std::vector<std::vector<double> >&"]="\tMatrixClient _%(arg)s_client;\n\tint _%(arg)s_nbRow;\n\tint _%(arg)s_nbCol;\n"\
151            "\tdouble* _%(arg)s_tab = _%(arg)s_client.getValue(%(arg)s,_%(arg)s_nbCol,_%(arg)s_nbRow);\n\tstd::vector<std::vector<double> > _%(arg)s(_%(arg)s_nbRow);\n"\
152            "\tfor (int i=0; i!=_%(arg)s_nbRow; ++i)\n\t{\n\t    _%(arg)s[i].resize(_%(arg)s_nbCol);\n"\
153            "\t    std::copy(_%(arg)s_tab+_%(arg)s_nbCol*i,_%(arg)s_tab+_%(arg)s_nbCol*(i+1), _%(arg)s[i].begin());\n\t}\n\tdelete [] _%(arg)s_tab;\n"
154 cpp_impl_a["MEDMEM::FIELD<int>*&"]="\tMEDMEM::FIELD<int>* _%(arg)s;\n"
155 cpp_impl_a["const MEDMEM::FIELD<int>*"]="\tstd::auto_ptr<MEDMEM::FIELD<int> > _%(arg)s ( new MEDMEM::FIELDClient<int>(%(arg)s) );\n"
156 cpp_impl_a["const MEDMEM::FIELD<int>&"]="\tMEDMEM::FIELDClient<int> _%(arg)s(%(arg)s);\n"
157 cpp_impl_a["const std::vector<int>&"]="\tlong _%(arg)s_size=%(arg)s.length();\n"\
158                          "\tstd::vector<int> _%(arg)s(_%(arg)s_size);\n"\
159                          "\tfor (int i=0; i!=_%(arg)s_size; ++i)\n\t    _%(arg)s[i]=%(arg)s[i];"
160 cpp_impl_a["std::vector<int>*&"]="\tstd::vector<int>* _%(arg)s;\n"
161 cpp_impl_a["const MEDCoupling::MEDCouplingFieldDouble*"]="\tMEDCoupling::MEDCouplingFieldDouble* _%(arg)s=MEDCoupling::MEDCouplingFieldDoubleClient::New(%(arg)s);\n"
162 cpp_impl_a["const MEDCoupling::MEDCouplingFieldDouble&"]="\tMEDCoupling::MEDCouplingFieldDouble* __%(arg)s=MEDCoupling::MEDCouplingFieldDoubleClient::New(%(arg)s);\n"\
163                          "\tMEDCoupling::MEDCouplingFieldDouble& _%(arg)s=*__%(arg)s;\n"
164 cpp_impl_a["MEDCoupling::MEDCouplingFieldDouble*&"]="\tMEDCoupling::MEDCouplingFieldDouble* _%(arg)s;\n"
165 cpp_impl_a["const MEDCoupling::MEDCouplingUMesh*"]="\tMEDCoupling::MEDCouplingUMesh* _%(arg)s=MEDCoupling::MEDCouplingUMeshClient::New(%(arg)s);\n"
166
167
168 # table for c++ code generation : returned value processing
169 cpp_impl_b={}
170 cpp_impl_b["void"]=""
171 cpp_impl_b["int"]="\tCORBA::Long _rtn_ior(_rtn_cpp);\n"
172 cpp_impl_b["bool"]="\tCORBA::Boolean _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&"]="""\tMEDMEM::MESH_i * _rtn_mesh_i = new MEDMEM::MESH_i(const_cast<MEDMEM::MESH*>(&_rtn_cpp));\n
183 \tSALOME_MED::MESH_ptr _rtn_ior = _rtn_mesh_i->_this();\n"""
184 cpp_impl_b["MEDMEM::MESH&"]="\tMEDMEM::MESH_i * _rtn_mesh_i = new MEDMEM::MESH_i(&_rtn_cpp);\n\tSALOME_MED::MESH_ptr _rtn_ior = _rtn_mesh_i->_this();\n"
185 cpp_impl_b["MEDMEM::MESH*"]= "\tMEDMEM::MESH_i * _rtn_mesh_i = new MEDMEM::MESH_i(_rtn_cpp);\n\tSALOME_MED::MESH_ptr _rtn_ior = _rtn_mesh_i->_this();\n"
186 cpp_impl_b["const MEDMEM::MESH*"]="\tMEDMEM::MESH_i * _rtn_mesh_i = new MEDMEM::MESH_i(const_cast<MEDMEM::MESH*>(_rtn_cpp));\n\tSALOME_MED::MESH_ptr _rtn_ior = _rtn_mesh_i->_this();\n"
187 cpp_impl_b["MEDMEM::SUPPORT*"]="\tMEDMEM::SUPPORT_i * _rtn_support_i = new MEDMEM::SUPPORT_i(_rtn_cpp);\n\tSALOME_MED::SUPPORT_ptr _rtn_ior = _rtn_support_i->_this();\n"
188 cpp_impl_b["const MEDMEM::FIELD<double>*"]="""\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["MEDMEM::FIELD<double>*"]="""\tMEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace> * _rtn_field_i = new MEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace>(_rtn_cpp,true);\n
191 \tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"""
192 cpp_impl_b["MEDMEM::FIELD<double>&"]="""\tMEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace> * _rtn_field_i = new MEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace>(&_rtn_cpp,false);\n
193 \tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"""
194 cpp_impl_b["const MEDMEM::FIELD<double>&"]="""\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
195 \tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"""
196 cpp_impl_b["std::vector<double>*"]="""\t%(module)s::dblevec * _rtn_ior = new %(module)s::dblevec;\n
197 \tint _rtn_cpp_length=(*_rtn_cpp).size();\n
198 \t_rtn_ior->length(_rtn_cpp_length);\n
199 \tfor (int i=0; i<_rtn_cpp_length; ++i)\n\t    (*_rtn_ior)[i] = (*_rtn_cpp)[i];\n"""
200 cpp_impl_b["std::vector<std::vector<double> >*"]="""\tint _rtn_cpp_i=(*_rtn_cpp).size();\n\tint _rtn_cpp_j=(*_rtn_cpp)[0].size();\n
201 \tdouble* _rtn_tab = new double[_rtn_cpp_i*_rtn_cpp_j];\n
202 \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
203 \tSALOME_Matrix_i* _rtn_matrix_i = new SALOME_Matrix_i(*this,_rtn_tab,_rtn_cpp_i,_rtn_cpp_j,true);\n
204 \tSALOME::Matrix_ptr _rtn_ior = _rtn_matrix_i->_this();\n\tdelete _rtn_cpp;\n"""
205 cpp_impl_b["const MEDMEM::FIELD<int>*"]="\tMEDMEM::FIELDINT_i * _rtn_field_i = new MEDMEM::FIELDINT_i(const_cast<MEDMEM::FIELD<int>*>(_rtn_cpp),false);\n\tSALOME_MED::FIELDINT_ptr _rtn_ior = _rtn_field_i->_this();\n"
206 cpp_impl_b["MEDMEM::FIELD<int>*"]="\tMEDMEM::FIELDINT_i * _rtn_field_i = new MEDMEM::FIELDINT_i(_rtn_cpp,true);\n\tSALOME_MED::FIELDINT_ptr _rtn_ior = _rtn_field_i->_this();\n"
207 cpp_impl_b["MEDMEM::FIELD<int>&"]="\tMEDMEM::FIELDINT_i * _rtn_field_i = new MEDMEM::FIELDINT_i(&_rtn_cpp,false);\n\tSALOME_MED::FIELDINT_ptr _rtn_ior = _rtn_field_i->_this();\n"
208 cpp_impl_b["const MEDMEM::FIELD<int>&"]="\tMEDMEM::FIELDINT_i * _rtn_field_i = new MEDMEM::FIELDINT_i(const_cast<MEDMEM::FIELD<int>*>(&_rtn_cpp),false);\n\tSALOME_MED::FIELDINT_ptr _rtn_ior = _rtn_field_i->_this();\n"
209 cpp_impl_b["std::vector<int>*"]="""\t%(module)s::intvec * _rtn_ior = new %(module)s::intvec;
210 \tint _rtn_cpp_length=(*_rtn_cpp).size();
211 \t_rtn_ior->length(_rtn_cpp_length);
212 \tfor (int i=0; i<_rtn_cpp_length; ++i)\n\t    (*_rtn_ior)[i] = (*_rtn_cpp)[i];\n"""
213 cpp_impl_b["std::vector<std::string>"]="""\t%(module)s::stringvec * _rtn_ior = new %(module)s::stringvec;
214 \tint _rtn_cpp_length=_rtn_cpp.size();
215 \t_rtn_ior->length(_rtn_cpp_length);
216 \tfor (int i=0; i<_rtn_cpp_length; ++i)
217 \t    (*_rtn_ior)[i] = _rtn_cpp[i].c_str();\n"""
218 cpp_impl_b["MEDCoupling::MEDCouplingFieldDouble*"]="""\tMEDCoupling::MEDCouplingFieldDoubleServant * _rtn_field_i = new MEDCoupling::MEDCouplingFieldDoubleServant(_rtn_cpp);
219 \t_rtn_cpp->decrRef();
220 \tSALOME_MED::MEDCouplingFieldDoubleCorbaInterface_ptr _rtn_ior = _rtn_field_i->_this();\n"""
221 cpp_impl_b["MEDCoupling::MEDCouplingUMesh*"]="""\tMEDCoupling::MEDCouplingUMeshServant * _rtn_mesh_i = new MEDCoupling::MEDCouplingUMeshServant(_rtn_cpp);
222 \t_rtn_cpp->decrRef();
223 \tSALOME_MED::MEDCouplingUMeshCorbaInterface_ptr _rtn_ior = _rtn_mesh_i->_this();\n"""
224 cpp_impl_b["MEDCoupling::DataArrayDouble*"]="""\tMEDCoupling::DataArrayDoubleServant * _rtn_field_i = new MEDCoupling::DataArrayDoubleServant(_rtn_cpp);
225 \t_rtn_cpp->decrRef();
226 \tSALOME_MED::DataArrayDoubleCorbaInterface_ptr _rtn_ior = _rtn_field_i->_this();\n"""
227 #
228 # table for c++ code generation : out parameters processing and removeRef for reference counted objects
229 #
230 cpp_impl_c={}
231 cpp_impl_c["MEDMEM::FIELD<double>*&"]="""\tMEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace> * %(arg)s_ior = new MEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace>(_%(arg)s, true);\n
232 \t%(arg)s = %(arg)s_ior->_this();\n"""
233 cpp_impl_c["MEDMEM::FIELD<int>*&"]=""" \tMEDMEM::FIELDINT_i * %(arg)s_ior = new MEDMEM::FIELDINT_i(_%(arg)s, true);\n
234 \t%(arg)s = %(arg)s_ior->_this();\n"""
235 cpp_impl_c["std::vector<double>*&"]="""\t%(arg)s = new %(module)s::dblevec;\n
236 \t%(arg)s->length((*_%(arg)s).size());\n
237 \tfor (int i=0; i<(*_%(arg)s).size(); ++i)\n\t    (*%(arg)s)[i] = (*_%(arg)s)[i];\n"""
238 cpp_impl_c["std::vector<int>*&"]="""\t%(arg)s = new %(module)s::intvec;\n
239 \t%(arg)s->length((*_%(arg)s).size());\n
240 \tfor (int i=0; i<(*_%(arg)s).size(); ++i)\n\t    (*%(arg)s)[i] = (*_%(arg)s)[i];\n"""
241 cpp_impl_c["std::string&"]="\t%(arg)s = CORBA::string_dup(_%(arg)s.c_str());\n"
242 cpp_impl_c["int&"]="\t%(arg)s = _%(arg)s;\n"
243 cpp_impl_c["bool&"]="\t%(arg)s = _%(arg)s;\n"
244 cpp_impl_c["double&"]="\t%(arg)s = _%(arg)s;\n"
245 cpp_impl_c["float&"]="\t%(arg)s = _%(arg)s;\n"
246 cpp_impl_c["long&"]="\t%(arg)s = _%(arg)s;\n"
247 cpp_impl_c["short&"]="\t%(arg)s = _%(arg)s;\n"
248 cpp_impl_c["unsigned&"]="\t%(arg)s = _%(arg)s;\n"
249 cpp_impl_c["const MEDMEM::MESH&"]="\t_%(arg)s->removeReference();\n"
250 cpp_impl_c["const MEDMEM::MESH*"]="\t_%(arg)s->removeReference();\n"
251 cpp_impl_c["const MEDMEM::SUPPORT&"]="\t_%(arg)s->removeReference();\n"
252 cpp_impl_c["const MEDMEM::SUPPORT*"]="\t_%(arg)s->removeReference();\n"
253 cpp_impl_c["const MEDCoupling::MEDCouplingFieldDouble*"]="\t_%(arg)s->decrRef();\n"
254 cpp_impl_c["const MEDCoupling::MEDCouplingUMesh*"]="\t_%(arg)s->decrRef();\n"
255 cpp_impl_c["const MEDCoupling::MEDCouplingFieldDouble&"]="\t__%(arg)s->decrRef();\n"
256 cpp_impl_c["MEDCoupling::MEDCouplingFieldDouble*&"]="""\tMEDCoupling::MEDCouplingFieldDoubleServant * %(arg)s_out=new MEDCoupling::MEDCouplingFieldDoubleServant(_%(arg)s);
257 \t_%(arg)s->decrRef();
258 \t%(arg)s = %(arg)s_out->_this();\n"""
259
260 #
261 # the following awk files (extracted from hxx2saloe) are used to parse hxx file
262
263 #
264 parse01="""
265 # This awk program deletes C like comments '*/  ...  /*'  
266 # --
267 # Copyright (C) CEA
268 # Author : Nicolas Crouzet (CEA)
269 # --
270 {
271     if (t = index($0, "/*")) {
272         if (t > 1)
273             tmp = substr($0, 1, t - 1)
274         else
275             tmp = ""
276         u = index(substr($0, t + 2), "*/")
277         while (u == 0) {
278             getline
279             t = -1
280             u = index($0, "*/")
281         }
282         if (u <= length($0) - 2)
283             $0 = tmp substr($0, t + u + 3)
284         else
285             $0 = tmp
286     }
287     print $0
288 }
289 """
290 parse1="""
291 # This awk program extract public functions of the class definition present in hxx interface
292 # --
293 # Copyright (C) CEA
294 # Author : Nicolas Crouzet (CEA)
295 # --
296
297 BEGIN { public=0 }
298
299 # we want to extract each function that is public and that does'nt contain
300 # the patterns : public, protected, private, // (comments), { and }
301 public == 1     && 
302 $1 !~ /public/  && 
303 $1 !~ /protected/ && 
304 $1 !~ /private/ && 
305 $1 !~ /\/\/*/   && 
306 $1 !~ /{|}/  {
307    for (i=1; i<=NF; i++)
308       printf "%s ", $i
309 #  change line if last field contains ";" -> one function per line in output
310    if ( $NF ~ /;/ ) 
311       printf "\\n"
312 }
313    
314 $1 == "class" && $0 !~ /;/ {public=1} # we test matching against /;/  to get rid of forward declaration
315 $1 ~ /public/ {public=1}
316 $1 ~ /protected/ {public=0}
317 $1 ~ /private/ {public=0}
318 $1 ~ /}/      {public=0}
319 """
320 parse2="""
321 # suppress blanks between type and indirection or reference operators (* and &)
322 # --
323 # Copyright (C) CEA
324 # Author : Nicolas Crouzet (CEA)
325 # --
326 { gsub(/[ \\t]+&/,"\\\\& ")
327   gsub(/[ \\t]+\*/,"* ")
328   print $0 }
329 """
330 parse3="""
331 # This awk program contains the type mapping tables - and the treatments
332 # --
333 # Copyright (C) CEA, EDF
334 # Author : Nicolas Crouzet (CEA)
335 # --
336 # for code generation
337 #
338 BEGIN { 
339 #
340 # file name generation
341   class_i=class_name"_i"
342 #
343 #
344 # type mapping from c++ component to idl
345 #
346   idl_arg_type["int"]="in long"
347   idl_arg_type["bool"]="in boolean"
348   idl_arg_type["double"]="in double"
349   idl_arg_type["float"]="in float"
350   idl_arg_type["long"]="in long"
351   idl_arg_type["short"]="in short"
352 #  idl_arg_type["unsigned"]="in unsigned long"
353   idl_arg_type["const char*"]="in string"
354   idl_arg_type["const std::string&"]="in string"
355   idl_arg_type["int&"]="out long"
356   idl_arg_type["bool&"]="out boolean"
357   idl_arg_type["double&"]="out double"
358   idl_arg_type["float&"]="out float"
359   idl_arg_type["long&"]="out long"
360   idl_arg_type["short&"]="out short"
361   idl_arg_type["unsigned&"]="out unsigned long"
362   idl_arg_type["std::string&"]="out string"
363   idl_arg_type["const MEDMEM::MESH&"]="in SALOME_MED::MESH"
364   idl_arg_type["const MEDMEM::MESH*"]="in SALOME_MED::MESH"
365   idl_arg_type["const MEDMEM::SUPPORT&"]="in SALOME_MED::SUPPORT"
366   idl_arg_type["const MEDMEM::SUPPORT*"]="in SALOME_MED::SUPPORT"
367   idl_arg_type["const MEDMEM::FIELD<double>*"]="in SALOME_MED::FIELDDOUBLE"
368   idl_arg_type["const MEDMEM::FIELD<double>&"]="in SALOME_MED::FIELDDOUBLE"
369   idl_arg_type["MEDMEM::FIELD<double>*&"]="out SALOME_MED::FIELDDOUBLE"
370   idl_arg_type["const std::vector<double>&"]="in SALOME::vectorOfDouble"
371   idl_arg_type["const std::vector<std::vector<double> >&"]="in SALOME::Matrix"
372   idl_arg_type["std::vector<double>*&"]="out SALOME::vectorOfDouble"
373   idl_arg_type["const MEDMEM::FIELD<int>*"]="in SALOME_MED::FIELDINT"
374   idl_arg_type["const MEDMEM::FIELD<int>&"]="in SALOME_MED::FIELDINT"
375   idl_arg_type["MEDMEM::FIELD<int>*&"]="out SALOME_MED::FIELDINT"
376   idl_arg_type["const std::vector<int>&"]="in SALOME::vectorOfLong"
377   idl_arg_type["std::vector<int>*&"]="out SALOME::vectorOfLong"
378   idl_arg_type["const MEDCoupling::MEDCouplingFieldDouble*"]="in SALOME_MED::MEDCouplingFieldDoubleCorbaInterface"
379   idl_arg_type["const MEDCoupling::MEDCouplingFieldDouble&"]="in SALOME_MED::MEDCouplingFieldDoubleCorbaInterface"
380   idl_arg_type["MEDCoupling::MEDCouplingFieldDouble*&"]="out SALOME_MED::MEDCouplingFieldDoubleCorbaInterface"
381   idl_arg_type["const MEDCoupling::MEDCouplingUMesh*"]="in SALOME_MED::MEDCouplingUMeshCorbaInterface"
382 #
383 #
384 # mapping for returned types
385 #
386   idl_rtn_type["void"]="void"
387   idl_rtn_type["int"]="long"
388   idl_rtn_type["bool"]="boolean"
389   idl_rtn_type["double"]="double"
390   idl_rtn_type["float"]="float"
391   idl_rtn_type["long"]="long"
392   idl_rtn_type["short"]="short"
393   idl_rtn_type["unsigned"]="unsigned long"
394   idl_rtn_type["const char*"]="string"
395   idl_rtn_type["char*"]="string"
396   idl_rtn_type["std::string"]="string"
397   idl_rtn_type["const MEDMEM::MESH&"]="SALOME_MED::MESH"
398   idl_rtn_type["MEDMEM::MESH&"]="SALOME_MED::MESH"
399   idl_rtn_type["MEDMEM::MESH*"]="SALOME_MED::MESH"
400   idl_rtn_type["const MEDMEM::MESH*"]="SALOME_MED::MESH"
401   idl_rtn_type["MEDMEM::SUPPORT*"]="SALOME_MED::SUPPORT"
402   idl_rtn_type["const MEDMEM::FIELD<double>*"]="SALOME_MED::FIELDDOUBLE"
403   idl_rtn_type["MEDMEM::FIELD<double>*"]="SALOME_MED::FIELDDOUBLE"
404   idl_rtn_type["MEDMEM::FIELD<double>&"]="SALOME_MED::FIELDDOUBLE"
405   idl_rtn_type["const MEDMEM::FIELD<double>&"]="SALOME_MED::FIELDDOUBLE"
406   idl_rtn_type["std::vector<double>*"]="SALOME::vectorOfDouble"
407   idl_rtn_type["std::vector<std::vector<double> >*"]="SALOME::Matrix"
408   idl_rtn_type["const MEDMEM::FIELD<int>*"]="SALOME_MED::FIELDINT"
409   idl_rtn_type["MEDMEM::FIELD<int>*"]="SALOME_MED::FIELDINT"
410   idl_rtn_type["MEDMEM::FIELD<int>&"]="SALOME_MED::FIELDINT"
411   idl_rtn_type["const MEDMEM::FIELD<int>&"]="SALOME_MED::FIELDINT"
412   idl_rtn_type["std::vector<int>*"]="SALOME::vectorOfLong"
413   idl_rtn_type["std::vector<std::string>"]="StrSeq"
414   idl_rtn_type["MEDCoupling::MEDCouplingUMesh*"]="SALOME_MED::MEDCouplingUMeshCorbaInterface"
415   idl_rtn_type["MEDCoupling::MEDCouplingFieldDouble*"]="SALOME_MED::MEDCouplingFieldDoubleCorbaInterface"
416   idl_rtn_type["MEDCoupling::DataArrayDouble*"]="SALOME_MED::DataArrayDoubleServantCorbaInterface"
417 #
418 #
419 # record sep is ");\\n" whith blanks all around, and optional "(" at the beginning
420   RS="[(]?[ \\t]*[)][ \\t]*(const)?[ \\t]*[;][ \\t]*[\\n]"  
421   FS="[ \\t]*[(,][ \\t]*"  # field sep is either "(" or "," surrounded by blanks 
422 }
423
424 # --------------------- treatment 1 ----------------------------------
425 #
426 #  extract from fields types, function name, and argument's names
427 #
428 {
429   print "Function : ",$0 >> "parse_result"  # print for debug
430   for (i=1; i<=NF; i++) {
431       print "\\t-> ",i," : ",$i >> "parse_result"
432   }
433   ok1=0;ok=1
434   error_message="\\t  The non compatible types are : "
435   # check if returned type ($1) is one of the accepted types (idl_rtn_type)
436   for (cpptype in idl_rtn_type) {
437     if ( substr($1,1,length(cpptype)) == cpptype ) {
438       # if compatible, store returned type and function name
439       type[1]=cpptype
440       name[1]=substr($1,length(cpptype)+1)
441       sub("^[ \\t]*","",name[1]) # get rid of leading blanks
442       ok1=1
443       break
444     }
445   }
446   ok*=ok1
447   if ( ! ok1) {
448       split($1,tab," ") 
449       error_message=error_message sprintf("\\n\\t\\t-> %s (return type)",tab[1])
450   }
451   # for each argument ($i), check if it is compatible (belongs to idl_arg_type)
452   for (i=2; i<=NF; i++) {
453     ok2=0
454     split($i,tab,"=") # get rid of default value
455     item=tab[1]
456     sub("/[ \\t]*&[ \\t]*/", "&", item) # supress spaces around * and $
457     sub("/[ \\t]**[ \\t]*/", "*", item)
458     for (cpptype in idl_arg_type) {
459         l = length(cpptype)
460         s0 = substr(item,1,l) # to discriminate between int and int&, ...
461         s1 = " "
462         if (length(item) > l)
463             s1 = substr(item, l+1, 1)
464
465         if ( (s0 == cpptype) && (s1 == " ") ) {
466           # if compatible, store argument type and name
467           type[i]=cpptype
468           name[i]=substr(item,length(cpptype)+1)
469           sub("^[ \\t]*","",name[i]) # get rid of leading blanks
470           if ( length(name[i]) == 0 ) # automatic name if argument's name wasn't precised
471              name[i]=sprintf("_arg%d",i-1)
472           ok2=1
473           break
474        }
475     }
476     ok*=ok2 # ok=0 if one of the type is not compatible
477     if ( ! ok2) {
478         error_message=error_message "\\n\\t\\t-> "item
479     }
480   }
481
482   # print compatibility 
483   if ( $0 !~ class_name ) { # constructor are not considered, but we don't print it
484       if ( ok == 0){ # if one of the c++ type is not compatible
485           printf "     [KO]     :  %s",$0
486       }
487       else
488           printf "     [OK]     :  %s",$0
489         
490       if ( $0 !~ /\(/  ) {
491           printf "(" # if there is no argument, parenthesis was suppressed, so we add it for printing
492       }
493       printf ");\\n"
494       if ( ok == 0){ #print the error message
495           printf "%s\\n\\n",error_message
496       }
497   }    
498   if ( ok == 0) # pass to the next function if one of the c++ type is not compatible
499       next
500 }
501 #
502 # --------------------- treatment 1 bis ------------------------------
503 {
504     printf "Function;%s;%s\\n",type[1],name[1] > "parse_type_result"
505     for (i=2; i<=NF; i++) {
506         printf "%s;%s\\n",type[i],name[i] >> "parse_type_result"
507     }
508 }
509 """