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
49994070
Commit
49994070
authored
Jan 11, 2021
by
Ralf W. Grosse-Kunstleve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factoring out smart_holder_type_caster_load.
parent
ed6c8907
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
12 deletions
+15
-12
tests/test_classh_wip.cpp
+15
-12
No files found.
tests/test_classh_wip.cpp
View file @
49994070
...
...
@@ -44,8 +44,22 @@ namespace detail {
using
namespace
pybind11_tests
::
classh_wip
;
template
<
typename
T
>
struct
smart_holder_type_caster_load
{
bool
load
(
handle
src
,
bool
/*convert*/
)
{
if
(
!
isinstance
<
T
>
(
src
))
return
false
;
auto
inst
=
reinterpret_cast
<
instance
*>
(
src
.
ptr
());
auto
v_h
=
inst
->
get_value_and_holder
(
get_type_info
(
typeid
(
T
)));
smhldr_ptr
=
&
v_h
.
holder
<
pybindit
::
memory
::
smart_holder
>
();
return
true
;
}
protected
:
pybindit
::
memory
::
smart_holder
*
smhldr_ptr
=
nullptr
;
};
template
<>
struct
type_caster
<
mpty
>
{
struct
type_caster
<
mpty
>
:
smart_holder_type_caster_load
<
mpty
>
{
static
constexpr
auto
name
=
_
<
mpty
>
();
// static handle cast(mpty, ...)
...
...
@@ -100,17 +114,6 @@ struct type_caster<mpty> {
operator
mpty
&
()
{
return
smhldr_ptr
->
lvalue_ref
<
mpty
>
();
}
operator
mpty
const
*
()
{
return
smhldr_ptr
->
as_raw_ptr_unowned
<
mpty
>
();
}
operator
mpty
*
()
{
return
smhldr_ptr
->
as_raw_ptr_unowned
<
mpty
>
();
}
bool
load
(
handle
src
,
bool
/*convert*/
)
{
if
(
!
isinstance
<
mpty
>
(
src
))
return
false
;
auto
inst
=
reinterpret_cast
<
instance
*>
(
src
.
ptr
());
auto
v_h
=
inst
->
get_value_and_holder
(
get_type_info
(
typeid
(
mpty
)));
smhldr_ptr
=
&
v_h
.
holder
<
pybindit
::
memory
::
smart_holder
>
();
return
true
;
}
private
:
pybindit
::
memory
::
smart_holder
*
smhldr_ptr
=
nullptr
;
};
template
<>
...
...
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