Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
eigenpy
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stack Of Tasks
eigenpy
Commits
9be4fa3d
Commit
9be4fa3d
authored
1 year ago
by
Wilson Jallet
Browse files
Options
Downloads
Patches
Plain Diff
tests/python: use old-style call to parent ctor
parent
43022a1e
No related branches found
No related tags found
No related merge requests found
Pipeline
#27435
passed with warnings
1 year ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
unittest/bind_virtual_factory.cpp
+7
-5
7 additions, 5 deletions
unittest/bind_virtual_factory.cpp
unittest/python/test_bind_virtual.py
+3
-2
3 additions, 2 deletions
unittest/python/test_bind_virtual.py
with
10 additions
and
7 deletions
unittest/bind_virtual_factory.cpp
+
7
−
5
View file @
9be4fa3d
...
@@ -24,7 +24,7 @@ struct MyVirtualClass {
...
@@ -24,7 +24,7 @@ struct MyVirtualClass {
};
};
struct
MyVirtualData
{
struct
MyVirtualData
{
MyVirtualData
(
MyVirtualClass
const
&
)
{}
MyVirtualData
(
MyVirtualClass
const
&
)
{}
virtual
~
MyVirtualData
()
{}
// virtual dtor to mark class as polymorphic
virtual
~
MyVirtualData
()
{}
// virtual dtor to mark class as polymorphic
};
};
...
@@ -84,8 +84,9 @@ struct VirtualClassWrapper : MyVirtualClass, bp::wrapper<MyVirtualClass> {
...
@@ -84,8 +84,9 @@ struct VirtualClassWrapper : MyVirtualClass, bp::wrapper<MyVirtualClass> {
/// This "trampoline class" does nothing but is ABSOLUTELY required to ensure
/// This "trampoline class" does nothing but is ABSOLUTELY required to ensure
/// downcasting works properly with non-smart ptr signatures. Otherwise,
/// downcasting works properly with non-smart ptr signatures. Otherwise,
/// there is no handle to the original Python object ( @c PyObject *).
/// there is no handle to the original Python object ( @c PyObject *).
/// Every single polymorphic type exposed to Python should be exposed through such a trampoline.
/// Every single polymorphic type exposed to Python should be exposed through
/// Users can also create their own wrapper classes by taking inspiration from boost::python::wrapper<T>.
/// such a trampoline. Users can also create their own wrapper classes by taking
/// inspiration from boost::python::wrapper<T>.
struct
DataWrapper
:
MyVirtualData
,
bp
::
wrapper
<
MyVirtualData
>
{
struct
DataWrapper
:
MyVirtualData
,
bp
::
wrapper
<
MyVirtualData
>
{
/// we have to use-declare non-defaulted constructors
/// we have to use-declare non-defaulted constructors
/// (see https://en.cppreference.com/w/cpp/language/default_constructor)
/// (see https://en.cppreference.com/w/cpp/language/default_constructor)
...
@@ -99,7 +100,8 @@ const MyVirtualData &iden_ref(const MyVirtualData &d) {
...
@@ -99,7 +100,8 @@ const MyVirtualData &iden_ref(const MyVirtualData &d) {
return
d
;
return
d
;
}
}
/// Take a shared_ptr (by const reference or value, doesn't matter), return by const reference
/// Take a shared_ptr (by const reference or value, doesn't matter), return by
/// const reference
const
MyVirtualData
&
iden_shared
(
const
shared_ptr
<
MyVirtualData
>
&
d
)
{
const
MyVirtualData
&
iden_shared
(
const
shared_ptr
<
MyVirtualData
>
&
d
)
{
// get boost.python's custom deleter
// get boost.python's custom deleter
// boost.python hides the handle to the original object in there
// boost.python hides the handle to the original object in there
...
@@ -136,7 +138,7 @@ BOOST_PYTHON_MODULE(bind_virtual_factory) {
...
@@ -136,7 +138,7 @@ BOOST_PYTHON_MODULE(bind_virtual_factory) {
/// otherwise if passed as "HeldType", we need to define
/// otherwise if passed as "HeldType", we need to define
/// the constructor and call initializer manually.
/// the constructor and call initializer manually.
bp
::
class_
<
DataWrapper
,
boost
::
noncopyable
>
(
"MyVirtualData"
,
bp
::
no_init
)
bp
::
class_
<
DataWrapper
,
boost
::
noncopyable
>
(
"MyVirtualData"
,
bp
::
no_init
)
.
def
(
bp
::
init
<
MyVirtualClass
const
&>
(
bp
::
args
(
"self"
,
"model"
)));
.
def
(
bp
::
init
<
MyVirtualClass
const
&>
(
bp
::
args
(
"self"
,
"model"
)));
bp
::
def
(
"callDoSomethingPtr"
,
callDoSomethingPtr
,
bp
::
args
(
"obj"
));
bp
::
def
(
"callDoSomethingPtr"
,
callDoSomethingPtr
,
bp
::
args
(
"obj"
));
bp
::
def
(
"callDoSomethingRef"
,
callDoSomethingRef
,
bp
::
args
(
"obj"
));
bp
::
def
(
"callDoSomethingRef"
,
callDoSomethingRef
,
bp
::
args
(
"obj"
));
...
...
This diff is collapsed.
Click to expand it.
unittest/python/test_bind_virtual.py
+
3
−
2
View file @
9be4fa3d
...
@@ -4,7 +4,7 @@ import bind_virtual_factory as bvf
...
@@ -4,7 +4,7 @@ import bind_virtual_factory as bvf
class
ImplClass
(
bvf
.
MyVirtualClass
):
class
ImplClass
(
bvf
.
MyVirtualClass
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
val
=
42
self
.
val
=
42
super
()
.
__init__
()
bvf
.
MyVirtualClass
.
__init__
(
self
)
def
createData
(
self
):
def
createData
(
self
):
return
ImplData
(
self
)
return
ImplData
(
self
)
...
@@ -27,7 +27,8 @@ class ImplClass(bvf.MyVirtualClass):
...
@@ -27,7 +27,8 @@ class ImplClass(bvf.MyVirtualClass):
class
ImplData
(
bvf
.
MyVirtualData
):
class
ImplData
(
bvf
.
MyVirtualData
):
def
__init__
(
self
,
c
):
def
__init__
(
self
,
c
):
super
().
__init__
(
c
)
# parent virtual class requires arg
# parent virtual class requires arg
bvf
.
MyVirtualData
.
__init__
(
self
,
c
)
self
.
value
=
c
.
val
self
.
value
=
c
.
val
...
...
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