Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openstructure
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor 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
schwede
openstructure
Commits
b96aa9a9
Commit
b96aa9a9
authored
12 years ago
by
Gabriel Studer
Browse files
Options
Downloads
Patches
Plain Diff
added a template based converter between vectors and python lists
parent
c89a8ba6
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/base/src/CMakeLists.txt
+1
-0
1 addition, 0 deletions
modules/base/src/CMakeLists.txt
modules/base/src/export_helper/vec_to_list_conv.hh
+57
-0
57 additions, 0 deletions
modules/base/src/export_helper/vec_to_list_conv.hh
with
58 additions
and
0 deletions
modules/base/src/CMakeLists.txt
+
1
−
0
View file @
b96aa9a9
...
...
@@ -37,6 +37,7 @@ boost_filesystem_helper.hh
set
(
OST_EXPORT_HELPERS
generic_property_def.hh
pair_to_tuple_conv.hh
vec_to_list_conv.hh
)
module
(
NAME base SOURCES
${
OST_BASE_SOURCES
}
HEADERS
${
OST_EXPORT_HELPERS
}
IN_DIR export_helper
...
...
This diff is collapsed.
Click to expand it.
modules/base/src/export_helper/vec_to_list_conv.hh
0 → 100644
+
57
−
0
View file @
b96aa9a9
//------------------------------------------------------------------------------
// This file is part of the OpenStructure project <www.openstructure.org>
//
// Copyright (C) 2008-2011 by the OpenStructure authors
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3.0 of the License, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
#ifndef VEC_LIST_CONV_HH
#define VEC_LIST_CONV_HH
#include
<boost/python.hpp>
#include
<vector>
namespace
ost
{
/// \brief helper to convert between python list and std::vector
///
/// Usage:
/// #include vec_to_list_conv.hh
/// std::vector<Real> fancy_vector();
/// boost::python::list fancy_list = VecToList<Real>(fancy_vector);
template
<
typename
T
>
boost
::
python
::
list
VecToList
(
std
::
vector
<
T
>&
vec
){
boost
::
python
::
list
l
;
for
(
typename
std
::
vector
<
T
>::
iterator
it
=
vec
.
begin
();
it
!=
vec
.
end
();
++
it
){
l
.
append
(
*
it
);
}
return
l
;
}
template
<
typename
T
>
std
::
vector
<
T
>
ListToVec
(
boost
::
python
::
list
&
l
){
std
::
vector
<
T
>
vec
;
for
(
int
i
=
0
;
i
<
boost
::
python
::
len
(
l
);
++
i
){
vec
.
push_back
(
boost
::
python
::
extract
<
T
>
(
l
[
i
]));
}
return
vec
;
}
}
#endif
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