Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
1e3be73a
Commit
1e3be73a
authored
May 24, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PYBIND11_OVERLOAD_NAME and PYBIND11_OVERLOAD_PURE_NAME (fixes #205)
parent
b4378673
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
12 deletions
+24
-12
docs/advanced.rst
+8
-2
example/example12.ref
+1
-1
example/issues.ref
+1
-1
include/pybind11/pybind11.h
+14
-8
No files found.
docs/advanced.rst
View file @
1e3be73a
...
...
@@ -268,8 +268,14 @@ helper class that is defined as follows:
The macro :func:`PYBIND11_OVERLOAD_PURE` should be used for pure virtual
functions, and :func:`PYBIND11_OVERLOAD` should be used for functions which have
a default implementation. The binding code also needs a few minor adaptations
(highlighted):
a default implementation.
There are also two alternate macros :func:`PYBIND11_OVERLOAD_PURE_NAME` and
:func:`PYBIND11_OVERLOAD_NAME` which take a string-valued name argument
after the *Name of the function* slot. This is useful when the C++ and Python
versions of the function have different names, e.g. ``operator()`` vs ``__call__``.
The binding code also needs a few minor adaptations (highlighted):
.. code-block:: cpp
:emphasize-lines: 4,6,7
...
...
example/example12.ref
View file @
1e3be73a
Constructing Example12..
Original implementation of Example12::run(state=10, value=20)
30
Caught expected exception: Tried to call pure virtual function "pure_virtual"
Caught expected exception: Tried to call pure virtual function "
Example12::
pure_virtual"
Constructing Example12..
ExtendedExample12::run(20), calling parent..
Original implementation of Example12::run(state=11, value=21)
...
...
example/issues.ref
View file @
1e3be73a
const char *
c
Failed as expected: Tried to call pure virtual function "dispatch"
Failed as expected: Tried to call pure virtual function "
Base::
dispatch"
Yay..
[Placeholder[1], Placeholder[2], Placeholder[3], Placeholder[4]]
[3, 5, 7, 9, 11, 13, 15]
...
...
include/pybind11/pybind11.h
View file @
1e3be73a
...
...
@@ -1184,19 +1184,25 @@ inline function get_overload(const void *this_ptr, const char *name) {
return
overload
;
}
#define PYBIND11_OVERLOAD_INT(ret_type,
class_name,
name, ...) { \
#define PYBIND11_OVERLOAD_INT(ret_type, name, ...) { \
pybind11::gil_scoped_acquire gil; \
pybind11::function overload = pybind11::get_overload(this,
#
name); \
pybind11::function overload = pybind11::get_overload(this, name); \
if (overload) \
return overload(__VA_ARGS__).template cast<ret_type>(); }
#define PYBIND11_OVERLOAD
(ret_type, class_name, name
, ...) \
PYBIND11_OVERLOAD_INT(ret_type,
class_name,
name, __VA_ARGS__) \
return c
lass_name::name
(__VA_ARGS__)
#define PYBIND11_OVERLOAD
_NAME(ret_type, cname, name, fn
, ...) \
PYBIND11_OVERLOAD_INT(ret_type, name, __VA_ARGS__) \
return c
name::fn
(__VA_ARGS__)
#define PYBIND11_OVERLOAD_PURE(ret_type, class_name, name, ...) \
PYBIND11_OVERLOAD_INT(ret_type, class_name, name, __VA_ARGS__) \
pybind11::pybind11_fail("Tried to call pure virtual function \"" #name "\"");
#define PYBIND11_OVERLOAD_PURE_NAME(ret_type, cname, name, fn, ...) \
PYBIND11_OVERLOAD_INT(ret_type, name, __VA_ARGS__) \
pybind11::pybind11_fail("Tried to call pure virtual function \"" #cname "::" name "\"");
#define PYBIND11_OVERLOAD(ret_type, cname, fn, ...) \
PYBIND11_OVERLOAD_NAME(ret_type, cname, #fn, fn, __VA_ARGS__)
#define PYBIND11_OVERLOAD_PURE(ret_type, cname, fn, ...) \
PYBIND11_OVERLOAD_PURE_NAME(ret_type, cname, #fn, fn, __VA_ARGS__)
NAMESPACE_END
(
pybind11
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment