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
a56ca1a2
Unverified
Commit
a56ca1a2
authored
1 year ago
by
Joris Vaillant
Browse files
Options
Downloads
Patches
Plain Diff
unique_ptr: Move object
parent
87a8f81a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/eigenpy/std_unique_ptr.hpp
+36
-12
36 additions, 12 deletions
include/eigenpy/std_unique_ptr.hpp
with
36 additions
and
12 deletions
include/eigenpy/std_unique_ptr.hpp
+
36
−
12
View file @
a56ca1a2
...
@@ -6,31 +6,53 @@
...
@@ -6,31 +6,53 @@
#define __eigenpy_utils_std_unique_ptr_hpp__
#define __eigenpy_utils_std_unique_ptr_hpp__
#include
"eigenpy/fwd.hpp"
#include
"eigenpy/fwd.hpp"
#include
"eigenpy/utils/traits.hpp"
#include
<boost/python.hpp>
#include
<boost/python.hpp>
#include
<memory>
#include
<memory>
#include
<iostream>
namespace
eigenpy
{
namespace
eigenpy
{
namespace
details
{
template
<
typename
T
>
typename
std
::
enable_if
<
is_class_or_union_remove_cvref
<
T
>::
value
,
PyObject
*>::
type
unique_ptr_to_python
(
std
::
unique_ptr
<
T
>&&
x
)
{
if
(
!
x
)
{
return
bp
::
detail
::
none
();
}
else
{
return
bp
::
detail
::
make_owning_holder
::
execute
(
x
.
release
());
}
}
template
<
typename
T
>
typename
std
::
enable_if
<!
is_class_or_union_remove_cvref
<
T
>::
value
,
PyObject
*>::
type
unique_ptr_to_python
(
std
::
unique_ptr
<
T
>&&
x
)
{
if
(
!
x
)
{
return
bp
::
detail
::
none
();
}
else
{
return
bp
::
to_python_value
<
const
T
&>
()(
*
x
);
}
}
}
// namespace details
/// result_converter of StdUniquePtrCallPolicies
/// result_converter of StdUniquePtrCallPolicies
struct
StdUniquePtrResultConverter
{
struct
StdUniquePtrResultConverter
{
template
<
class
T
>
template
<
typename
T
>
struct
apply
{
struct
apply
{
struct
type
{
struct
type
{
typedef
typename
bp
::
detail
::
value_arg
<
T
>::
type
argu
ment_type
;
typedef
typename
T
::
element_
type
ele
ment_type
;
/// TODO, this work by copy
PyObject
*
operator
()(
T
&&
x
)
const
{
/// We maybe can transfer the ownership to Python for class type
return
details
::
unique_ptr_to_python
(
std
::
forward
<
T
>
(
x
));
/// and when argument_type is an lvalue ref
PyObject
*
operator
()(
argument_type
x
)
const
{
return
bp
::
to_python_value
<
const
typename
T
::
element_type
&>
()(
*
x
);
}
}
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
PyTypeObject
const
*
get_pytype
()
const
{
PyTypeObject
const
*
get_pytype
()
const
{
return
bp
::
to_python_value
<
const
typename
T
::
element_type
&>
()
return
bp
::
to_python_value
<
const
element_type
&>
().
get_pytype
();
.
get_pytype
();
}
}
#endif
#endif
BOOST_STATIC_CONSTANT
(
bool
,
uses_registry
=
true
);
BOOST_STATIC_CONSTANT
(
bool
,
uses_registry
=
true
);
...
@@ -38,8 +60,10 @@ struct StdUniquePtrResultConverter {
...
@@ -38,8 +60,10 @@ struct StdUniquePtrResultConverter {
};
};
};
};
/// Access CallPolicie to get std::unique_ptr value from a functio
/// CallPolicies to get std::unique_ptr value from a function
/// that return an std::unique_ptr
/// that return an std::unique_ptr.
/// If the object inside the std::unique_ptr is a class or an union
/// it will be moved. In other case, it will be copied.
struct
StdUniquePtrCallPolicies
:
bp
::
default_call_policies
{
struct
StdUniquePtrCallPolicies
:
bp
::
default_call_policies
{
typedef
StdUniquePtrResultConverter
result_converter
;
typedef
StdUniquePtrResultConverter
result_converter
;
};
};
...
...
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