Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
b68e5a37
Commit
b68e5a37
authored
Aug 09, 2013
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added functions for easily converting between python list objects and std::vector.
parent
7640dece
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
boost_python_utils.h
tools/python/src/boost_python_utils.h
+37
-0
No files found.
tools/python/src/boost_python_utils.h
View file @
b68e5a37
...
...
@@ -20,5 +20,42 @@ inline bool hasattr(
return
PyObject_HasAttrString
(
obj
.
ptr
(),
attr_name
.
c_str
());
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
std
::
vector
<
T
>
python_list_to_vector
(
const
boost
::
python
::
object
&
obj
)
/*!
ensures
- converts a python object into a std::vector<T> and returns it.
!*/
{
std
::
vector
<
T
>
vect
(
len
(
obj
));
for
(
unsigned
long
i
=
0
;
i
<
vect
.
size
();
++
i
)
{
vect
[
i
]
=
boost
::
python
::
extract
<
T
>
(
obj
[
i
]);
}
return
vect
;
}
template
<
typename
T
>
boost
::
python
::
list
vector_to_python_list
(
const
std
::
vector
<
T
>&
vect
)
/*!
ensures
- converts a std::vector<T> into a python list object.
!*/
{
boost
::
python
::
list
obj
;
for
(
unsigned
long
i
=
0
;
i
<
vect
.
size
();
++
i
)
obj
.
append
(
vect
[
i
]);
return
obj
;
}
// ----------------------------------------------------------------------------------------
#endif // DLIB_BOOST_PYTHON_UtILS_H__
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