Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Gmsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gmsh
Gmsh
Commits
2a32d8cb
There was a problem fetching the pipeline summary.
Commit
2a32d8cb
authored
Apr 30, 2018
by
Christophe Geuzaine
Browse files
Options
Downloads
Patches
Plain Diff
gmshc.hpp -> gmsh.h_cwrap
parent
d5b7a03b
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!112
C++ wrapper for C API
Pipeline
#
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/GenApi.py
+101
-86
101 additions, 86 deletions
api/GenApi.py
api/README.txt
+9
-1
9 additions, 1 deletion
api/README.txt
api/gmsh.py
+326
-326
326 additions, 326 deletions
api/gmsh.py
with
436 additions
and
413 deletions
api/GenApi.py
+
101
−
86
View file @
2a32d8cb
...
...
@@ -22,7 +22,7 @@ class arg:
self
.
c_post
=
""
self
.
c
=
type_c
+
"
"
+
name
self
.
hp
p_arg
=
self
.
name
self
.
cwra
p_arg
=
self
.
name
self
.
python_arg
=
"
not_implemented
"
self
.
python_return
=
"
not_implemented
"
...
...
@@ -33,7 +33,7 @@ class arg:
def
ibool
(
name
,
value
=
None
,
python_value
=
None
):
a
=
arg
(
name
,
value
,
python_value
,
"
const bool
"
,
"
const int
"
,
False
)
a
.
python_arg
=
"
c_int(bool(
"
+
name
+
"
))
"
a
.
hp
p_arg
=
"
int(
"
+
name
+
"
)
"
a
.
cwra
p_arg
=
"
int(
"
+
name
+
"
)
"
return
a
def
iint
(
name
,
value
=
None
,
python_value
=
None
):
...
...
@@ -49,7 +49,7 @@ def idouble(name, value=None, python_value=None):
def
istring
(
name
,
value
=
None
,
python_value
=
None
):
a
=
arg
(
name
,
value
,
python_value
,
"
const std::string &
"
,
"
const char *
"
,
False
)
a
.
python_arg
=
"
c_char_p(
"
+
name
+
"
.encode())
"
a
.
hp
p_arg
=
name
+
"
.c_str()
"
a
.
cwra
p_arg
=
name
+
"
.c_str()
"
return
a
def
ivectorint
(
name
,
value
=
None
,
python_value
=
None
):
...
...
@@ -57,6 +57,7 @@ def ivectorint(name, value=None, python_value=None):
a
.
c_pre
=
"
std::vector<int> api_
"
+
name
+
"
_(
"
+
name
+
"
,
"
+
name
+
"
+
"
+
name
+
"
_n);
\n
"
a
.
c_arg
=
"
api_
"
+
name
+
"
_
"
a
.
c
=
"
int *
"
+
name
+
"
, size_t
"
+
name
+
"
_n
"
a
.
cwrap_arg
=
"
&
"
+
name
+
"
[0],
"
+
name
+
"
.size()
"
a
.
python_pre
=
"
api_
"
+
name
+
"
_, api_
"
+
name
+
"
_n_ = _ivectorint(
"
+
name
+
"
)
"
a
.
python_arg
=
"
api_
"
+
name
+
"
_, api_
"
+
name
+
"
_n_
"
return
a
...
...
@@ -66,6 +67,7 @@ def ivectordouble(name, value=None, python_value=None):
a
.
c_pre
=
"
std::vector<double> api_
"
+
name
+
"
_(
"
+
name
+
"
,
"
+
name
+
"
+
"
+
name
+
"
_n);
\n
"
a
.
c_arg
=
"
api_
"
+
name
+
"
_
"
a
.
c
=
"
double *
"
+
name
+
"
, size_t
"
+
name
+
"
_n
"
a
.
cwrap_arg
=
"
&
"
+
name
+
"
[0],
"
+
name
+
"
.size()
"
a
.
python_pre
=
"
api_
"
+
name
+
"
_, api_
"
+
name
+
"
_n_ = _ivectordouble(
"
+
name
+
"
)
"
a
.
python_arg
=
"
api_
"
+
name
+
"
_, api_
"
+
name
+
"
_n_
"
return
a
...
...
@@ -79,6 +81,9 @@ def ivectorpair(name, value=None, python_value=None):
"
}
\n
"
a
.
c_arg
=
"
api_
"
+
name
+
"
_
"
a
.
c
=
"
int *
"
+
name
+
"
, size_t
"
+
name
+
"
_n
"
a
.
cwrap_pre
=
"
TODO pre vector pair
\n
"
a
.
cwrap_arg
=
"
TODO arg vector pair
"
a
.
cwrap_post
=
"
TODO post vector pair
\n
"
a
.
python_pre
=
"
api_
"
+
name
+
"
_, api_
"
+
name
+
"
_n_ = _ivectorpair(
"
+
name
+
"
)
"
a
.
python_arg
=
"
api_
"
+
name
+
"
_, api_
"
+
name
+
"
_n_
"
return
a
...
...
@@ -90,6 +95,9 @@ def ivectorvectorint(name, value=None, python_value=None):
"
api_
"
+
name
+
"
_[i] = std::vector<int>(
"
+
name
+
"
[i],
"
+
name
+
"
[i] +
"
+
name
+
"
_n[i]);
\n
"
a
.
c_arg
=
"
api_
"
+
name
+
"
_
"
a
.
c
=
"
const int **
"
+
name
+
"
, const size_t *
"
+
name
+
"
_n,
"
+
"
size_t
"
+
name
+
"
_nn
"
a
.
cwrap_pre
=
"
TODO pre vector int
\n
"
a
.
cwrap_arg
=
"
TODO arg vector int
"
a
.
cwrap_post
=
"
TODO post vector int
\n
"
a
.
python_pre
=
"
api_
"
+
name
+
"
_, api_
"
+
name
+
"
_n_, api_
"
+
name
+
"
_nn_ = _ivectorvectorint(
"
+
name
+
"
)
"
a
.
python_arg
=
"
api_
"
+
name
+
"
_, api_
"
+
name
+
"
_n_, api_
"
+
name
+
"
_nn_
"
return
a
...
...
@@ -101,6 +109,9 @@ def ivectorvectordouble(name, value=None, python_value=None):
"
api_
"
+
name
+
"
_[i] = std::vector<double>(
"
+
name
+
"
[i],
"
+
name
+
"
[i] +
"
+
name
+
"
_n[i]);
\n
"
a
.
c_arg
=
"
api_
"
+
name
+
"
_
"
a
.
c
=
"
const double **
"
+
name
+
"
, const size_t *
"
+
name
+
"
_n,
"
+
"
size_t
"
+
name
+
"
_nn
"
a
.
cwrap_pre
=
"
TODO pre vector vector double
\n
"
a
.
cwrap_arg
=
"
TODO arg vector vector double
"
a
.
cwrap_post
=
"
TODO post vector vector double
\n
"
a
.
python_pre
=
"
api_
"
+
name
+
"
_, api_
"
+
name
+
"
_n_, api_
"
+
name
+
"
_nn_ = _ivectorvectordouble(
"
+
name
+
"
)
"
a
.
python_arg
=
"
api_
"
+
name
+
"
_, api_
"
+
name
+
"
_n_, api_
"
+
name
+
"
_nn_
"
return
a
...
...
@@ -247,6 +258,7 @@ def argcargv() :
a
.
c
=
"
int argc, char ** argv
"
a
.
c_pre
=
""
a
.
c_post
=
""
a
.
cwrap_arg
=
"
argc, argv
"
a
.
name
=
"
argv
"
a
.
python_value
=
"
[]
"
a
.
python_arg
=
"
api_argc_, api_argv_
"
...
...
@@ -428,23 +440,25 @@ void gmshFree(void *p) {
"""
c
_hp
p_header
=
"""
// Gmsh - Copyright (C) 1997-2018 C. Geuzaine, J.-F. Remacle
c
wra
p_header
=
"""
// Gmsh - Copyright (C) 1997-2018 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to the public mailing list <gmsh@onelab.info>.
#ifndef _GMSH
C
_H
PP
_
#define _GMSH
C
_H
PP
_
#ifndef _GMSH_H_
#define _GMSH_H_
// This file defines
C++ bindings for
the Gmsh C API. This file is
provided
// as a convenience for users of the binary Gmsh SDK, whose C++ compiler
ABI
// is not compatible with the ABI of the C++ compiler used to create the SDK
// This file
re
defines
the C++ API in terms of
the Gmsh C API. This file is
//
provided
as a convenience for users of the binary Gmsh SDK, whose C++ compiler
//
ABI
is not compatible with the ABI of the C++ compiler used to create the SDK
// (and who can thus not directly use the C++ API defined in `gmsh.h
'
).
//
// Using this header file will lead to (slightly) reduced performance compared
// to using the native Gmsh C++ API defined in `gmsh.h
'
, as it entails
// additional data copies between this C++ wrapper, the C API and the native
// C++ code.
// To use these C++ bindings of the C API instead of the native C++ API, simply
// rename this file as `gmsh.h
'
.
//
// Warning: using this header file will lead to (slightly) reduced performance
// compared to using the native Gmsh C++ API, as it entails additional data copies
// between this C++ wrapper, the C API and the native C++ code.
//
// Do not edit this file directly: it is automatically generated by `api/gen.py
'
.
...
...
@@ -479,7 +493,7 @@ namespace gmsh {
"""
c
_hp
p_footer
=
"""
#endif
c
wra
p_footer
=
"""
#endif
"""
python_header
=
"""
# Gmsh - Copyright (C) 1997-2018 C. Geuzaine, J.-F. Remacle
...
...
@@ -667,7 +681,7 @@ class API:
c_namespace
+=
module
.
name
[
0
].
upper
()
+
module
.
name
[
1
:]
else
:
c_namespace
=
module
.
name
f
hp
p
.
write
(
indent
+
"
namespace
"
+
module
.
name
+
"
{ //
"
+
module
.
doc
+
"
\n\n
"
)
f
cwra
p
.
write
(
indent
+
"
namespace
"
+
module
.
name
+
"
{ //
"
+
module
.
doc
+
"
\n\n
"
)
indent
+=
"
"
for
rtype
,
name
,
args
,
doc
,
rawc
in
module
.
fs
:
# gmshc.h
...
...
@@ -698,38 +712,39 @@ class API:
if
rtype
:
fc
.
write
(
"
return result_api_;
\n
"
);
fc
.
write
(
"
}
\n\n
"
)
# gmsh
c
.h
p
p
f
hp
p
.
write
(
indent
+
"
//
"
+
(
"
\n
"
+
indent
+
"
//
"
).
join
(
textwrap
.
wrap
(
doc
,
80
-
len
(
indent
)))
+
"
\n
"
)
# gmsh.h
_cwra
p
f
cwra
p
.
write
(
indent
+
"
//
"
+
(
"
\n
"
+
indent
+
"
//
"
).
join
(
textwrap
.
wrap
(
doc
,
80
-
len
(
indent
)))
+
"
\n
"
)
rt
=
rtype
.
rtype_cpp
if
rtype
else
"
void
"
fnameapi
=
indent
+
"
GMSH_API
"
+
rt
+
"
"
+
name
+
"
(
"
;
f
hp
p
.
write
(
fnameapi
)
f
cwra
p
.
write
(
fnameapi
)
if
args
:
f
hp
p
.
write
((
"
,
\n
"
+
'
'
*
len
(
fnameapi
)).
join
(
a
.
cpp
for
a
in
args
))
f
hp
p
.
write
(
"
)
\n
"
+
indent
+
"
{
\n
"
+
indent
+
"
int ierr = 0;
\n
"
+
indent
+
"
"
)
f
cwra
p
.
write
((
"
,
\n
"
+
'
'
*
len
(
fnameapi
)).
join
(
a
.
cpp
for
a
in
args
))
f
cwra
p
.
write
(
"
)
\n
"
+
indent
+
"
{
\n
"
+
indent
+
"
int ierr = 0;
\n
"
+
indent
+
"
"
)
if
rtype
:
f
hp
p
.
write
(
"
int result_api_ =
"
)
f
hp
p
.
write
(
fname
+
"
(
"
)
f
cwra
p
.
write
(
"
int result_api_ =
"
)
f
cwra
p
.
write
(
fname
+
"
(
"
+
"
,
"
.
join
((
a
.
cwrap_arg
for
a
in
args
))
)
fhpp
.
write
(
"
,
"
.
join
((
a
.
hpp_arg
for
a
in
args
)))
fhpp
.
write
(
"
, &ierr);
\n
"
)
fhpp
.
write
(
indent
+
"
"
+
"
if(ierr) throw ierr;
\n
"
);
if
args
:
fcwrap
.
write
(
"
, &ierr);
\n
"
)
else
:
fcwrap
.
write
(
"
&ierr);
\n
"
)
fcwrap
.
write
(
indent
+
"
"
+
"
if(ierr) throw ierr;
\n
"
);
if
rtype
:
f
hp
p
.
write
(
indent
+
"
return result_api_;
\n
"
)
f
hp
p
.
write
(
indent
+
"
}
\n\n
"
)
f
cwra
p
.
write
(
indent
+
"
return result_api_;
\n
"
)
f
cwra
p
.
write
(
indent
+
"
}
\n\n
"
)
for
m
in
module
.
submodules
:
write_module
(
m
,
c_namespace
,
cpp_namespace
,
indent
)
f
hp
p
.
write
(
indent
[:
-
2
]
+
"
} // namespace
"
+
module
.
name
+
"
\n\n
"
)
f
cwra
p
.
write
(
indent
[:
-
2
]
+
"
} // namespace
"
+
module
.
name
+
"
\n\n
"
)
with
open
(
"
gmshc.h
"
,
"
w
"
)
as
f
:
with
open
(
"
gmshc.cpp
"
,
"
w
"
)
as
fc
:
with
open
(
"
gmsh
c
.h
p
p
"
,
"
w
"
)
as
f
hpp
:
with
open
(
"
gmsh.h
_cwra
p
"
,
"
w
"
)
as
f
cwrap
:
f
.
write
(
c_header
)
fc
.
write
(
c_cpp_header
)
f
hp
p
.
write
(
c
_hp
p_header
)
f
cwra
p
.
write
(
c
wra
p_header
)
for
module
in
self
.
modules
:
write_module
(
module
,
""
,
""
,
""
)
f
.
write
(
c_footer
)
f
hp
p
.
write
(
c
_hp
p_footer
)
f
cwra
p
.
write
(
c
wra
p_footer
)
def
write_python
(
self
):
def
parg
(
a
):
...
...
This diff is collapsed.
Click to expand it.
api/README.txt
+
9
−
1
View file @
2a32d8cb
...
...
@@ -2,11 +2,19 @@ This directory contains the Gmsh API:
- gmsh.h: the header defining the Gmsh C++ API
- gmshc.h: the header defining the Gmsh C API
- gmshc.cpp: the wrapper for the Gmsh C API
- gmsh.py: the module defining the Gmsh Python API
These files are all automatically generated by the Python script 'gen.py'.
The additional file `gmsh.h_crwap' redefines the C++ API in terms of the C API.
This is provided as a convenience for users of the binary Gmsh SDK, whose C++
compiler ABI is not compatible with the ABI of the C++ compiler used to create
the SDK. To use these C++ bindings of the C API instead of the native C++ API,
simply rename `gmsh.h_cwrap' as `gmsh.h'. Warning: this will lead to (slightly)
reduced performance compared to using the native Gmsh C++ API, as it entails
additional data copies between the C++ wrapper, the C API and the native C++
code.
See `gmsh/demos/api' for examples on how to use the Gmsh API. In particular,
this directory contains C++ and Python versions of several of the `.geo'
tutorials from `gmsh/tutorials'.
...
...
This diff is collapsed.
Click to expand it.
api/gmsh.py
+
326
−
326
View file @
2a32d8cb
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment