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
b00caae8
Commit
b00caae8
authored
Jan 28, 2021
by
Ralf W. Grosse-Kunstleve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reintroducing py::classh, this time as a simple alias for py::class_<U, py::smart_holder>.
parent
e19d373d
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
24 additions
and
13 deletions
+24
-13
include/pybind11/smart_holder.h
+15
-0
tests/class_sh_module_local_1.cpp
+1
-1
tests/class_sh_module_local_2.cpp
+1
-1
tests/test_class_sh_basic.cpp
+1
-3
tests/test_class_sh_inheritance.cpp
+5
-5
tests/test_class_sh_unique_ptr_member.cpp
+1
-3
No files found.
include/pybind11/smart_holder.h
View file @
b00caae8
...
@@ -5,3 +5,18 @@
...
@@ -5,3 +5,18 @@
#pragma once
#pragma once
#include "detail/smart_holder_type_casters.h"
#include "detail/smart_holder_type_casters.h"
#include "pybind11.h"
PYBIND11_NAMESPACE_BEGIN
(
PYBIND11_NAMESPACE
)
// Supports easier switching between py::class_<U> and py::class_<U, py::smart_holder>:
// users can simply replace the `_` in `class_` with `h` or vice versa.
// Note though that the PYBIND11_SMART_HOLDER_TYPE_CASTERS(U) macro also needs to be
// added (for `classh`) or commented out (for `class_`).
template
<
typename
type_
,
typename
...
options
>
class
classh
:
public
class_
<
type_
,
smart_holder
,
options
...
>
{
public
:
using
class_
<
type_
,
smart_holder
,
options
...
>::
class_
;
};
PYBIND11_NAMESPACE_END
(
PYBIND11_NAMESPACE
)
tests/class_sh_module_local_1.cpp
View file @
b00caae8
...
@@ -22,7 +22,7 @@ PYBIND11_MODULE(class_sh_module_local_1, m) {
...
@@ -22,7 +22,7 @@ PYBIND11_MODULE(class_sh_module_local_1, m) {
namespace
py
=
pybind11
;
namespace
py
=
pybind11
;
using
namespace
pybind11_tests
::
class_sh_module_local
;
using
namespace
pybind11_tests
::
class_sh_module_local
;
py
::
class
_
<
atyp
,
py
::
smart_holder
>
(
m
,
"atyp"
,
py
::
module_local
())
py
::
class
h
<
atyp
>
(
m
,
"atyp"
,
py
::
module_local
())
.
def
(
py
::
init
([](
const
std
::
string
&
mtxt
)
{
.
def
(
py
::
init
([](
const
std
::
string
&
mtxt
)
{
atyp
obj
;
atyp
obj
;
obj
.
mtxt
=
mtxt
;
obj
.
mtxt
=
mtxt
;
...
...
tests/class_sh_module_local_2.cpp
View file @
b00caae8
...
@@ -22,7 +22,7 @@ PYBIND11_MODULE(class_sh_module_local_2, m) {
...
@@ -22,7 +22,7 @@ PYBIND11_MODULE(class_sh_module_local_2, m) {
namespace
py
=
pybind11
;
namespace
py
=
pybind11
;
using
namespace
pybind11_tests
::
class_sh_module_local
;
using
namespace
pybind11_tests
::
class_sh_module_local
;
py
::
class
_
<
atyp
,
py
::
smart_holder
>
(
m
,
"atyp"
,
py
::
module_local
())
py
::
class
h
<
atyp
>
(
m
,
"atyp"
,
py
::
module_local
())
.
def
(
py
::
init
([](
const
std
::
string
&
mtxt
)
{
.
def
(
py
::
init
([](
const
std
::
string
&
mtxt
)
{
atyp
obj
;
atyp
obj
;
obj
.
mtxt
=
mtxt
;
obj
.
mtxt
=
mtxt
;
...
...
tests/test_class_sh_basic.cpp
View file @
b00caae8
...
@@ -57,9 +57,7 @@ namespace class_sh_basic {
...
@@ -57,9 +57,7 @@ namespace class_sh_basic {
TEST_SUBMODULE
(
class_sh_basic
,
m
)
{
TEST_SUBMODULE
(
class_sh_basic
,
m
)
{
namespace
py
=
pybind11
;
namespace
py
=
pybind11
;
py
::
class_
<
atyp
,
py
::
smart_holder
>
(
m
,
"atyp"
)
py
::
classh
<
atyp
>
(
m
,
"atyp"
).
def
(
py
::
init
<>
()).
def
(
py
::
init
([](
const
std
::
string
&
mtxt
)
{
.
def
(
py
::
init
<>
())
.
def
(
py
::
init
([](
const
std
::
string
&
mtxt
)
{
atyp
obj
;
atyp
obj
;
obj
.
mtxt
=
mtxt
;
obj
.
mtxt
=
mtxt
;
return
obj
;
return
obj
;
...
...
tests/test_class_sh_inheritance.cpp
View file @
b00caae8
...
@@ -73,8 +73,8 @@ namespace pybind11_tests {
...
@@ -73,8 +73,8 @@ namespace pybind11_tests {
namespace
class_sh_inheritance
{
namespace
class_sh_inheritance
{
TEST_SUBMODULE
(
class_sh_inheritance
,
m
)
{
TEST_SUBMODULE
(
class_sh_inheritance
,
m
)
{
py
::
class
_
<
base
,
py
::
smart_holder
>
(
m
,
"base"
);
py
::
class
h
<
base
>
(
m
,
"base"
);
py
::
class
_
<
drvd
,
base
,
py
::
smart_holder
>
(
m
,
"drvd"
);
py
::
class
h
<
drvd
,
base
>
(
m
,
"drvd"
);
auto
rvto
=
py
::
return_value_policy
::
take_ownership
;
auto
rvto
=
py
::
return_value_policy
::
take_ownership
;
...
@@ -89,9 +89,9 @@ TEST_SUBMODULE(class_sh_inheritance, m) {
...
@@ -89,9 +89,9 @@ TEST_SUBMODULE(class_sh_inheritance, m) {
m
.
def
(
"pass_shcp_drvd"
,
pass_shcp_drvd
);
m
.
def
(
"pass_shcp_drvd"
,
pass_shcp_drvd
);
// __init__ needed for Python inheritance.
// __init__ needed for Python inheritance.
py
::
class
_
<
base1
,
py
::
smart_holder
>
(
m
,
"base1"
).
def
(
py
::
init
<>
());
py
::
class
h
<
base1
>
(
m
,
"base1"
).
def
(
py
::
init
<>
());
py
::
class
_
<
base2
,
py
::
smart_holder
>
(
m
,
"base2"
).
def
(
py
::
init
<>
());
py
::
class
h
<
base2
>
(
m
,
"base2"
).
def
(
py
::
init
<>
());
py
::
class
_
<
drvd2
,
base1
,
base2
,
py
::
smart_holder
>
(
m
,
"drvd2"
);
py
::
class
h
<
drvd2
,
base1
,
base2
>
(
m
,
"drvd2"
);
m
.
def
(
"rtrn_mptr_drvd2"
,
rtrn_mptr_drvd2
,
rvto
);
m
.
def
(
"rtrn_mptr_drvd2"
,
rtrn_mptr_drvd2
,
rvto
);
m
.
def
(
"rtrn_mptr_drvd2_up_cast1"
,
rtrn_mptr_drvd2_up_cast1
,
rvto
);
m
.
def
(
"rtrn_mptr_drvd2_up_cast1"
,
rtrn_mptr_drvd2_up_cast1
,
rvto
);
...
...
tests/test_class_sh_unique_ptr_member.cpp
View file @
b00caae8
...
@@ -46,9 +46,7 @@ namespace pybind11_tests {
...
@@ -46,9 +46,7 @@ namespace pybind11_tests {
namespace
class_sh_unique_ptr_member
{
namespace
class_sh_unique_ptr_member
{
TEST_SUBMODULE
(
class_sh_unique_ptr_member
,
m
)
{
TEST_SUBMODULE
(
class_sh_unique_ptr_member
,
m
)
{
py
::
class_
<
pointee
,
py
::
smart_holder
>
(
m
,
"pointee"
)
py
::
classh
<
pointee
>
(
m
,
"pointee"
).
def
(
py
::
init
<>
()).
def
(
"get_int"
,
&
pointee
::
get_int
);
.
def
(
py
::
init
<>
())
.
def
(
"get_int"
,
&
pointee
::
get_int
);
m
.
def
(
"make_unique_pointee"
,
make_unique_pointee
);
m
.
def
(
"make_unique_pointee"
,
make_unique_pointee
);
...
...
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