Salome HOME
Update copyrights 2014.
[tools/yacsgen.git] / module_generator / hxx_awk.py
1 # Copyright (C) 2009-2014  EDF R&D
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 ParaMEDMEM::MEDCouplingFieldDouble*"]="in SALOME_MED::MEDCouplingFieldDoubleCorbaInterface"
55 cpp2idl_mapping["const ParaMEDMEM::MEDCouplingFieldDouble&"]="in SALOME_MED::MEDCouplingFieldDoubleCorbaInterface"
56 cpp2idl_mapping["ParaMEDMEM::MEDCouplingFieldDouble*&"]="out SALOME_MED::MEDCouplingFieldDoubleCorbaInterface"
57 cpp2idl_mapping["const ParaMEDMEM::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 ParaMEDMEM::MEDCouplingFieldDouble*"]="SALOME_MED/MEDCouplingFieldDoubleCorbaInterface"
115 cpp2yacs_mapping["const ParaMEDMEM::MEDCouplingFieldDouble&"]="SALOME_MED/MEDCouplingFieldDoubleCorbaInterface"
116 cpp2yacs_mapping["const ParaMEDMEM::MEDCouplingUMesh*"]="SALOME_MED/MEDCouplingUMeshCorbaInterface"
117 cpp2yacs_mapping["ParaMEDMEM::MEDCouplingFieldDouble*&"]="SALOME_MED/MEDCouplingFieldDoubleCorbaInterface"
118 cpp2yacs_mapping["ParaMEDMEM::MEDCouplingUMesh*"]="SALOME_MED/MEDCouplingUMeshCorbaInterface"
119 cpp2yacs_mapping["ParaMEDMEM::MEDCouplingFieldDouble*"]="SALOME_MED/MEDCouplingFieldDoubleCorbaInterface"
120 # table for c++ code generation : argument's processing
121 cpp_impl_a={}
122 cpp_impl_a["int"]="\tint _%(arg)s(%(arg)s);\n"
123 cpp_impl_a["bool"]="\tbool _%(arg)s(%(arg)s);\n"
124 cpp_impl_a["double"]="\tdouble _%(arg)s(%(arg)s);\n"
125 cpp_impl_a["float"]="\tfloat _%(arg)s(%(arg)s);\n"
126 cpp_impl_a["long"]="\tlong _%(arg)s(%(arg)s);\n"
127 cpp_impl_a["short"]="\tshort _%(arg)s(%(arg)s);\n"
128 cpp_impl_a["unsigned"]="\tunsigned _%(arg)s(%(arg)s);\n"
129 cpp_impl_a["const char*"]="\tconst char* _%(arg)s(%(arg)s);\n"
130 cpp_impl_a["const std::string&"]="\tconst std::string _%(arg)s(%(arg)s);\n"
131 cpp_impl_a["int&"]="\tint _%(arg)s;\n"
132 cpp_impl_a["bool&"]="\tbool _%(arg)s;\n"
133 cpp_impl_a["double&"]="\tdouble _%(arg)s;\n"
134 cpp_impl_a["float&"]="\tfloat _%(arg)s;\n"
135 cpp_impl_a["long&"]="\tlong _%(arg)s;\n"
136 cpp_impl_a["short&"]="\tshort _%(arg)s;\n"
137 cpp_impl_a["unsigned&"]="\tunsigned _%(arg)s;\n"
138 cpp_impl_a["std::string&"]="\tstd::string _%(arg)s;\n"
139 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)
140 cpp_impl_a["const MEDMEM::MESH*"]="\tMEDMEM::MESHClient* _%(arg)s = new MEDMEM::MESHClient(%(arg)s);\n\t _%(arg)s->fillCopy();\n"
141 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)
142 cpp_impl_a["const MEDMEM::SUPPORT*"]="\tMEDMEM::SUPPORTClient* _%(arg)s = new MEDMEM::SUPPORTClient(%(arg)s);\n"
143 cpp_impl_a["MEDMEM::FIELD<double>*&"]="\tMEDMEM::FIELD<double>* _%(arg)s;\n"
144 cpp_impl_a["const MEDMEM::FIELD<double>*"]="\tstd::auto_ptr<MEDMEM::FIELD<double> > _%(arg)s ( new MEDMEM::FIELDClient<double,MEDMEM::FullInterlace>(%(arg)s) );\n"
145 cpp_impl_a["const MEDMEM::FIELD<double>&"]="\tMEDMEM::FIELDClient<double,MEDMEM::FullInterlace> _%(arg)s(%(arg)s);\n"
146 cpp_impl_a["const std::vector<double>&"]="\tlong _%(arg)s_size=%(arg)s.length();\n\tconst double *_%(arg)s_value = &%(arg)s[0];\n"\
147            "\tstd::vector<double> _%(arg)s(_%(arg)s_value,_%(arg)s_value+_%(arg)s_size);\n"
148 cpp_impl_a["std::vector<double>*&"]="\tstd::vector<double>* _%(arg)s;\n"
149 cpp_impl_a["const std::vector<std::vector<double> >&"]="\tMatrixClient _%(arg)s_client;\n\tint _%(arg)s_nbRow;\n\tint _%(arg)s_nbCol;\n"\
150            "\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"\
151            "\tfor (int i=0; i!=_%(arg)s_nbRow; ++i)\n\t{\n\t    _%(arg)s[i].resize(_%(arg)s_nbCol);\n"\
152            "\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"
153 cpp_impl_a["MEDMEM::FIELD<int>*&"]="\tMEDMEM::FIELD<int>* _%(arg)s;\n"
154 cpp_impl_a["const MEDMEM::FIELD<int>*"]="\tstd::auto_ptr<MEDMEM::FIELD<int> > _%(arg)s ( new MEDMEM::FIELDClient<int>(%(arg)s) );\n"
155 cpp_impl_a["const MEDMEM::FIELD<int>&"]="\tMEDMEM::FIELDClient<int> _%(arg)s(%(arg)s);\n"
156 cpp_impl_a["const std::vector<int>&"]="\tlong _%(arg)s_size=%(arg)s.length();\n"\
157                          "\tstd::vector<int> _%(arg)s(_%(arg)s_size);\n"\
158                          "\tfor (int i=0; i!=_%(arg)s_size; ++i)\n\t    _%(arg)s[i]=%(arg)s[i];"
159 cpp_impl_a["std::vector<int>*&"]="\tstd::vector<int>* _%(arg)s;\n"
160 cpp_impl_a["const ParaMEDMEM::MEDCouplingFieldDouble*"]="\tParaMEDMEM::MEDCouplingFieldDouble* _%(arg)s=ParaMEDMEM::MEDCouplingFieldDoubleClient::New(%(arg)s);\n"
161 cpp_impl_a["const ParaMEDMEM::MEDCouplingFieldDouble&"]="\tParaMEDMEM::MEDCouplingFieldDouble* __%(arg)s=ParaMEDMEM::MEDCouplingFieldDoubleClient::New(%(arg)s);\n"\
162                          "\tParaMEDMEM::MEDCouplingFieldDouble& _%(arg)s=*__%(arg)s;\n"
163 cpp_impl_a["ParaMEDMEM::MEDCouplingFieldDouble*&"]="\tParaMEDMEM::MEDCouplingFieldDouble* _%(arg)s;\n"
164 cpp_impl_a["const ParaMEDMEM::MEDCouplingUMesh*"]="\tParaMEDMEM::MEDCouplingUMesh* _%(arg)s=ParaMEDMEM::MEDCouplingUMeshClient::New(%(arg)s);\n"
165
166
167 # table for c++ code generation : returned value processing
168 cpp_impl_b={}
169 cpp_impl_b["void"]=""
170 cpp_impl_b["int"]="\tCORBA::Long _rtn_ior(_rtn_cpp);\n"
171 cpp_impl_b["bool"]="\tCORBA::Boolean _rtn_ior(_rtn_cpp);\n"
172 cpp_impl_b["double"]="\tCORBA::Double _rtn_ior(_rtn_cpp);\n"
173 cpp_impl_b["float"]="\tCORBA::Float _rtn_ior(_rtn_cpp);\n"
174 cpp_impl_b["long"]="\tCORBA::Long _rtn_ior(_rtn_cpp);\n"
175 cpp_impl_b["short"]="\tCORBA::Short _rtn_ior(_rtn_cpp);\n"
176 cpp_impl_b["unsigned"]="\tCORBA::ULong _rtn_ior(_rtn_cpp);\n"
177 cpp_impl_b["const char*"]="\tchar* _rtn_ior = CORBA::string_dup(_rtn_cpp);\n"
178 cpp_impl_b["char*"]="\tchar* _rtn_ior(_rtn_cpp);\n"
179 cpp_impl_b["std::string"]="""\tchar* _rtn_ior=CORBA::string_dup(_rtn_cpp.c_str());\n
180 \tstd::copy(_rtn_cpp.begin(),_rtn_cpp.end(),_rtn_ior);\n"""
181 cpp_impl_b["const MEDMEM::MESH&"]="""\tMEDMEM::MESH_i * _rtn_mesh_i = new MEDMEM::MESH_i(const_cast<MEDMEM::MESH*>(&_rtn_cpp));\n
182 \tSALOME_MED::MESH_ptr _rtn_ior = _rtn_mesh_i->_this();\n"""
183 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"
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["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"
186 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"
187 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
188 \tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"""
189 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
190 \tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"""
191 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
192 \tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"""
193 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
194 \tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"""
195 cpp_impl_b["std::vector<double>*"]="""\t%(module)s::dblevec * _rtn_ior = new %(module)s::dblevec;\n
196 \tint _rtn_cpp_length=(*_rtn_cpp).size();\n
197 \t_rtn_ior->length(_rtn_cpp_length);\n
198 \tfor (int i=0; i<_rtn_cpp_length; ++i)\n\t    (*_rtn_ior)[i] = (*_rtn_cpp)[i];\n"""
199 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
200 \tdouble* _rtn_tab = new double[_rtn_cpp_i*_rtn_cpp_j];\n
201 \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
202 \tSALOME_Matrix_i* _rtn_matrix_i = new SALOME_Matrix_i(*this,_rtn_tab,_rtn_cpp_i,_rtn_cpp_j,true);\n
203 \tSALOME::Matrix_ptr _rtn_ior = _rtn_matrix_i->_this();\n\tdelete _rtn_cpp;\n"""
204 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"
205 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"
206 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"
207 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"
208 cpp_impl_b["std::vector<int>*"]="""\t%(module)s::intvec * _rtn_ior = new %(module)s::intvec;
209 \tint _rtn_cpp_length=(*_rtn_cpp).size();
210 \t_rtn_ior->length(_rtn_cpp_length);
211 \tfor (int i=0; i<_rtn_cpp_length; ++i)\n\t    (*_rtn_ior)[i] = (*_rtn_cpp)[i];\n"""
212 cpp_impl_b["std::vector<std::string>"]="""\t%(module)s::stringvec * _rtn_ior = new %(module)s::stringvec;
213 \tint _rtn_cpp_length=_rtn_cpp.size();
214 \t_rtn_ior->length(_rtn_cpp_length);
215 \tfor (int i=0; i<_rtn_cpp_length; ++i)
216 \t    (*_rtn_ior)[i] = _rtn_cpp[i].c_str();\n"""
217 cpp_impl_b["ParaMEDMEM::MEDCouplingFieldDouble*"]="""\tParaMEDMEM::MEDCouplingFieldDoubleServant * _rtn_field_i = new ParaMEDMEM::MEDCouplingFieldDoubleServant(_rtn_cpp);
218 \t_rtn_cpp->decrRef();
219 \tSALOME_MED::MEDCouplingFieldDoubleCorbaInterface_ptr _rtn_ior = _rtn_field_i->_this();\n"""
220 cpp_impl_b["ParaMEDMEM::MEDCouplingUMesh*"]="""\tParaMEDMEM::MEDCouplingUMeshServant * _rtn_mesh_i = new ParaMEDMEM::MEDCouplingUMeshServant(_rtn_cpp);
221 \t_rtn_cpp->decrRef();
222 \tSALOME_MED::MEDCouplingUMeshCorbaInterface_ptr _rtn_ior = _rtn_mesh_i->_this();\n"""
223 #
224 # table for c++ code generation : out parameters processing and removeRef for reference counted objects
225 #
226 cpp_impl_c={}
227 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
228 \t%(arg)s = %(arg)s_ior->_this();\n"""
229 cpp_impl_c["MEDMEM::FIELD<int>*&"]=""" \tMEDMEM::FIELDINT_i * %(arg)s_ior = new MEDMEM::FIELDINT_i(_%(arg)s, true);\n
230 \t%(arg)s = %(arg)s_ior->_this();\n"""
231 cpp_impl_c["std::vector<double>*&"]="""\t%(arg)s = new %(module)s::dblevec;\n
232 \t%(arg)s->length((*_%(arg)s).size());\n
233 \tfor (int i=0; i<(*_%(arg)s).size(); ++i)\n\t    (*%(arg)s)[i] = (*_%(arg)s)[i];\n"""
234 cpp_impl_c["std::vector<int>*&"]="""\t%(arg)s = new %(module)s::intvec;\n
235 \t%(arg)s->length((*_%(arg)s).size());\n
236 \tfor (int i=0; i<(*_%(arg)s).size(); ++i)\n\t    (*%(arg)s)[i] = (*_%(arg)s)[i];\n"""
237 cpp_impl_c["std::string&"]="\t%(arg)s = CORBA::string_dup(_%(arg)s.c_str());\n"
238 cpp_impl_c["int&"]="\t%(arg)s = _%(arg)s;\n"
239 cpp_impl_c["bool&"]="\t%(arg)s = _%(arg)s;\n"
240 cpp_impl_c["double&"]="\t%(arg)s = _%(arg)s;\n"
241 cpp_impl_c["float&"]="\t%(arg)s = _%(arg)s;\n"
242 cpp_impl_c["long&"]="\t%(arg)s = _%(arg)s;\n"
243 cpp_impl_c["short&"]="\t%(arg)s = _%(arg)s;\n"
244 cpp_impl_c["unsigned&"]="\t%(arg)s = _%(arg)s;\n"
245 cpp_impl_c["const MEDMEM::MESH&"]="\t_%(arg)s->removeReference();\n"
246 cpp_impl_c["const MEDMEM::MESH*"]="\t_%(arg)s->removeReference();\n"
247 cpp_impl_c["const MEDMEM::SUPPORT&"]="\t_%(arg)s->removeReference();\n"
248 cpp_impl_c["const MEDMEM::SUPPORT*"]="\t_%(arg)s->removeReference();\n"
249 cpp_impl_c["const ParaMEDMEM::MEDCouplingFieldDouble*"]="\t_%(arg)s->decrRef();\n"
250 cpp_impl_c["const ParaMEDMEM::MEDCouplingUMesh*"]="\t_%(arg)s->decrRef();\n"
251 cpp_impl_c["const ParaMEDMEM::MEDCouplingFieldDouble&"]="\t__%(arg)s->decrRef();\n"
252 cpp_impl_c["ParaMEDMEM::MEDCouplingFieldDouble*&"]="""\tParaMEDMEM::MEDCouplingFieldDoubleServant * %(arg)s_out=new ParaMEDMEM::MEDCouplingFieldDoubleServant(_%(arg)s);
253 \t_%(arg)s->decrRef();
254 \t%(arg)s = %(arg)s_out->_this();\n"""
255
256 #
257 # the following awk files (extracted from hxx2saloe) are used to parse hxx file
258
259 #
260 parse01="""
261 # This awk program deletes C like comments '*/  ...  /*'  
262 # --
263 # Copyright (C) CEA
264 # Author : Nicolas Crouzet (CEA)
265 # --
266 {
267     if (t = index($0, "/*")) {
268         if (t > 1)
269             tmp = substr($0, 1, t - 1)
270         else
271             tmp = ""
272         u = index(substr($0, t + 2), "*/")
273         while (u == 0) {
274             getline
275             t = -1
276             u = index($0, "*/")
277         }
278         if (u <= length($0) - 2)
279             $0 = tmp substr($0, t + u + 3)
280         else
281             $0 = tmp
282     }
283     print $0
284 }
285 """
286 parse1="""
287 # This awk program extract public functions of the class definition present in hxx interface
288 # --
289 # Copyright (C) CEA
290 # Author : Nicolas Crouzet (CEA)
291 # --
292
293 BEGIN { public=0 }
294
295 # we want to extract each function that is public and that does'nt contain
296 # the patterns : public, protected, private, // (comments), { and }
297 public == 1     && 
298 $1 !~ /public/  && 
299 $1 !~ /protected/ && 
300 $1 !~ /private/ && 
301 $1 !~ /\/\/*/   && 
302 $1 !~ /{|}/  {
303    for (i=1; i<=NF; i++)
304       printf "%s ", $i
305 #  change line if last field contains ";" -> one function per line in output
306    if ( $NF ~ /;/ ) 
307       printf "\\n"
308 }
309    
310 $1 == "class" && $0 !~ /;/ {public=1} # we test matching against /;/  to get rid of forward declaration
311 $1 ~ /public/ {public=1}
312 $1 ~ /protected/ {public=0}
313 $1 ~ /private/ {public=0}
314 $1 ~ /}/      {public=0}
315 """
316 parse2="""
317 # suppress blanks between type and indirection or reference operators (* and &)
318 # --
319 # Copyright (C) CEA
320 # Author : Nicolas Crouzet (CEA)
321 # --
322 { gsub(/[ \\t]+&/,"\\\\& ")
323   gsub(/[ \\t]+\*/,"* ")
324   print $0 }
325 """
326 parse3="""
327 # This awk program contains the type mapping tables - and the treatments
328 # --
329 # Copyright (C) CEA, EDF
330 # Author : Nicolas Crouzet (CEA)
331 # --
332 # for code generation
333 #
334 BEGIN { 
335 #
336 # file name generation
337   class_i=class_name"_i"
338 #
339 #
340 # type mapping from c++ component to idl
341 #
342   idl_arg_type["int"]="in long"
343   idl_arg_type["bool"]="in boolean"
344   idl_arg_type["double"]="in double"
345   idl_arg_type["float"]="in float"
346   idl_arg_type["long"]="in long"
347   idl_arg_type["short"]="in short"
348 #  idl_arg_type["unsigned"]="in unsigned long"
349   idl_arg_type["const char*"]="in string"
350   idl_arg_type["const std::string&"]="in string"
351   idl_arg_type["int&"]="out long"
352   idl_arg_type["bool&"]="out boolean"
353   idl_arg_type["double&"]="out double"
354   idl_arg_type["float&"]="out float"
355   idl_arg_type["long&"]="out long"
356   idl_arg_type["short&"]="out short"
357   idl_arg_type["unsigned&"]="out unsigned long"
358   idl_arg_type["std::string&"]="out string"
359   idl_arg_type["const MEDMEM::MESH&"]="in SALOME_MED::MESH"
360   idl_arg_type["const MEDMEM::MESH*"]="in SALOME_MED::MESH"
361   idl_arg_type["const MEDMEM::SUPPORT&"]="in SALOME_MED::SUPPORT"
362   idl_arg_type["const MEDMEM::SUPPORT*"]="in SALOME_MED::SUPPORT"
363   idl_arg_type["const MEDMEM::FIELD<double>*"]="in SALOME_MED::FIELDDOUBLE"
364   idl_arg_type["const MEDMEM::FIELD<double>&"]="in SALOME_MED::FIELDDOUBLE"
365   idl_arg_type["MEDMEM::FIELD<double>*&"]="out SALOME_MED::FIELDDOUBLE"
366   idl_arg_type["const std::vector<double>&"]="in SALOME::vectorOfDouble"
367   idl_arg_type["const std::vector<std::vector<double> >&"]="in SALOME::Matrix"
368   idl_arg_type["std::vector<double>*&"]="out SALOME::vectorOfDouble"
369   idl_arg_type["const MEDMEM::FIELD<int>*"]="in SALOME_MED::FIELDINT"
370   idl_arg_type["const MEDMEM::FIELD<int>&"]="in SALOME_MED::FIELDINT"
371   idl_arg_type["MEDMEM::FIELD<int>*&"]="out SALOME_MED::FIELDINT"
372   idl_arg_type["const std::vector<int>&"]="in SALOME::vectorOfLong"
373   idl_arg_type["std::vector<int>*&"]="out SALOME::vectorOfLong"
374   idl_arg_type["const ParaMEDMEM::MEDCouplingFieldDouble*"]="in SALOME_MED::MEDCouplingFieldDoubleCorbaInterface"
375   idl_arg_type["const ParaMEDMEM::MEDCouplingFieldDouble&"]="in SALOME_MED::MEDCouplingFieldDoubleCorbaInterface"
376   idl_arg_type["ParaMEDMEM::MEDCouplingFieldDouble*&"]="out SALOME_MED::MEDCouplingFieldDoubleCorbaInterface"
377   idl_arg_type["const ParaMEDMEM::MEDCouplingUMesh*"]="in SALOME_MED::MEDCouplingUMeshCorbaInterface"
378 #
379 #
380 # mapping for returned types
381 #
382   idl_rtn_type["void"]="void"
383   idl_rtn_type["int"]="long"
384   idl_rtn_type["bool"]="boolean"
385   idl_rtn_type["double"]="double"
386   idl_rtn_type["float"]="float"
387   idl_rtn_type["long"]="long"
388   idl_rtn_type["short"]="short"
389   idl_rtn_type["unsigned"]="unsigned long"
390   idl_rtn_type["const char*"]="string"
391   idl_rtn_type["char*"]="string"
392   idl_rtn_type["std::string"]="string"
393   idl_rtn_type["const MEDMEM::MESH&"]="SALOME_MED::MESH"
394   idl_rtn_type["MEDMEM::MESH&"]="SALOME_MED::MESH"
395   idl_rtn_type["MEDMEM::MESH*"]="SALOME_MED::MESH"
396   idl_rtn_type["const MEDMEM::MESH*"]="SALOME_MED::MESH"
397   idl_rtn_type["MEDMEM::SUPPORT*"]="SALOME_MED::SUPPORT"
398   idl_rtn_type["const MEDMEM::FIELD<double>*"]="SALOME_MED::FIELDDOUBLE"
399   idl_rtn_type["MEDMEM::FIELD<double>*"]="SALOME_MED::FIELDDOUBLE"
400   idl_rtn_type["MEDMEM::FIELD<double>&"]="SALOME_MED::FIELDDOUBLE"
401   idl_rtn_type["const MEDMEM::FIELD<double>&"]="SALOME_MED::FIELDDOUBLE"
402   idl_rtn_type["std::vector<double>*"]="SALOME::vectorOfDouble"
403   idl_rtn_type["std::vector<std::vector<double> >*"]="SALOME::Matrix"
404   idl_rtn_type["const MEDMEM::FIELD<int>*"]="SALOME_MED::FIELDINT"
405   idl_rtn_type["MEDMEM::FIELD<int>*"]="SALOME_MED::FIELDINT"
406   idl_rtn_type["MEDMEM::FIELD<int>&"]="SALOME_MED::FIELDINT"
407   idl_rtn_type["const MEDMEM::FIELD<int>&"]="SALOME_MED::FIELDINT"
408   idl_rtn_type["std::vector<int>*"]="SALOME::vectorOfLong"
409   idl_rtn_type["std::vector<std::string>"]="StrSeq"
410   idl_rtn_type["ParaMEDMEM::MEDCouplingUMesh*"]="SALOME_MED::MEDCouplingUMeshCorbaInterface"
411   idl_rtn_type["ParaMEDMEM::MEDCouplingFieldDouble*"]="SALOME_MED::MEDCouplingFieldDoubleCorbaInterface"
412 #
413 #
414 # record sep is ");\\n" whith blanks all around, and optional "(" at the beginning
415   RS="[(]?[ \\t]*[)][ \\t]*(const)?[ \\t]*[;][ \\t]*[\\n]"  
416   FS="[ \\t]*[(,][ \\t]*"  # field sep is either "(" or "," surrounded by blanks 
417 }
418
419 # --------------------- treatment 1 ----------------------------------
420 #
421 #  extract from fields types, function name, and argument's names
422 #
423 {
424   print "Function : ",$0 >> "parse_result"  # print for debug
425   for (i=1; i<=NF; i++) {
426       print "\\t-> ",i," : ",$i >> "parse_result"
427   }
428   ok1=0;ok=1
429   error_message="\\t  The non compatible types are : "
430   # check if returned type ($1) is one of the accepted types (idl_rtn_type)
431   for (cpptype in idl_rtn_type) {
432     if ( substr($1,1,length(cpptype)) == cpptype ) {
433       # if compatible, store returned type and function name
434       type[1]=cpptype
435       name[1]=substr($1,length(cpptype)+1)
436       sub("^[ \\t]*","",name[1]) # get rid of leading blanks
437       ok1=1
438       break
439     }
440   }
441   ok*=ok1
442   if ( ! ok1) {
443       split($1,tab," ") 
444       error_message=error_message sprintf("\\n\\t\\t-> %s (return type)",tab[1])
445   }
446   # for each argument ($i), check if it is compatible (belongs to idl_arg_type)
447   for (i=2; i<=NF; i++) {
448     ok2=0
449     split($i,tab,"=") # get rid of default value
450     item=tab[1]
451     sub("/[ \\t]*&[ \\t]*/", "&", item) # supress spaces around * and $
452     sub("/[ \\t]**[ \\t]*/", "*", item)
453     for (cpptype in idl_arg_type) {
454         l = length(cpptype)
455         s0 = substr(item,1,l) # to discriminate between int and int&, ...
456         s1 = " "
457         if (length(item) > l)
458             s1 = substr(item, l+1, 1)
459
460         if ( (s0 == cpptype) && (s1 == " ") ) {
461           # if compatible, store argument type and name
462           type[i]=cpptype
463           name[i]=substr(item,length(cpptype)+1)
464           sub("^[ \\t]*","",name[i]) # get rid of leading blanks
465           if ( length(name[i]) == 0 ) # automatic name if argument's name wasn't precised
466              name[i]=sprintf("_arg%d",i-1)
467           ok2=1
468           break
469        }
470     }
471     ok*=ok2 # ok=0 if one of the type is not compatible
472     if ( ! ok2) {
473         error_message=error_message "\\n\\t\\t-> "item
474     }
475   }
476
477   # print compatibility 
478   if ( $0 !~ class_name ) { # constructor are not considered, but we don't print it
479       if ( ok == 0){ # if one of the c++ type is not compatible
480           printf "     [KO]     :  %s",$0
481       }
482       else
483           printf "     [OK]     :  %s",$0
484         
485       if ( $0 !~ /\(/  ) {
486           printf "(" # if there is no argument, parenthesis was suppressed, so we add it for printing
487       }
488       printf ");\\n"
489       if ( ok == 0){ #print the error message
490           printf "%s\\n\\n",error_message
491       }
492   }    
493   if ( ok == 0) # pass to the next function if one of the c++ type is not compatible
494       next
495 }
496 #
497 # --------------------- treatment 1 bis ------------------------------
498 {
499     printf "Function;%s;%s\\n",type[1],name[1] > "parse_type_result"
500     for (i=2; i<=NF; i++) {
501         printf "%s;%s\\n",type[i],name[i] >> "parse_type_result"
502     }
503 }
504 """