Skip to content
Snippets Groups Projects
Commit 953660b3 authored by Wilson Jallet's avatar Wilson Jallet :clapper:
Browse files

Run pre-commit on copyable, pickle-vector, std-aligned-vector

remove references to aligned
parent 7ec0e310
No related branches found
No related tags found
No related merge requests found
......@@ -7,28 +7,26 @@
#include <boost/python.hpp>
namespace pinocchio
{
namespace python
{
namespace bp = boost::python;
///
/// \brief Add the Python method copy to allow a copy of this by calling the copy constructor.
///
template<class C>
struct CopyableVisitor
: public bp::def_visitor< CopyableVisitor<C> >
{
template<class PyClass>
void visit(PyClass & cl) const
{ cl.def("copy",&copy,bp::arg("self"),"Returns a copy of *this."); }
private:
static C copy(const C & self) { return C(self); }
};
} // namespace python
} // namespace pinocchio
namespace pinocchio {
namespace python {
#endif // ifndef __pinocchio_python_utils_copyable_hpp__
namespace bp = boost::python;
///
/// \brief Add the Python method copy to allow a copy of this by calling the
/// copy constructor.
///
template <class C>
struct CopyableVisitor : public bp::def_visitor<CopyableVisitor<C> > {
template <class PyClass>
void visit(PyClass& cl) const {
cl.def("copy", &copy, bp::arg("self"), "Returns a copy of *this.");
}
private:
static C copy(const C& self) { return C(self); }
};
} // namespace python
} // namespace pinocchio
#endif // ifndef __pinocchio_python_utils_copyable_hpp__
......@@ -6,46 +6,43 @@
#define __pinocchio_python_utils_pickle_vector_hpp__
#include <boost/python.hpp>
#include <boost/python/tuple.hpp>
#include <boost/python/stl_iterator.hpp>
#include <boost/python/tuple.hpp>
namespace pinocchio
{
namespace python
{
///
/// \brief Create a pickle interface for the std::vector and aligned vector
///
/// \tparam VecType Vector Type to pickle
///
template<typename VecType>
struct PickleVector : boost::python::pickle_suite
{
static boost::python::tuple getinitargs(const VecType&)
{ return boost::python::make_tuple(); }
static boost::python::tuple getstate(boost::python::object op)
{
return boost::python::make_tuple(boost::python::list(boost::python::extract<const VecType&>(op)()));
}
static void setstate(boost::python::object op, boost::python::tuple tup)
{
if(boost::python::len(tup) > 0)
{
VecType & o = boost::python::extract<VecType&>(op)();
boost::python::stl_input_iterator<typename VecType::value_type> begin(tup[0]), end;
while(begin != end)
{
o.push_back(*begin);
++begin;
}
}
namespace pinocchio {
namespace python {
///
/// \brief Create a pickle interface for the std::vector
///
/// \tparam VecType Vector Type to pickle
///
template <typename VecType>
struct PickleVector : boost::python::pickle_suite {
static boost::python::tuple getinitargs(const VecType&) {
return boost::python::make_tuple();
}
static boost::python::tuple getstate(boost::python::object op) {
return boost::python::make_tuple(
boost::python::list(boost::python::extract<const VecType&>(op)()));
}
static void setstate(boost::python::object op, boost::python::tuple tup) {
if (boost::python::len(tup) > 0) {
VecType& o = boost::python::extract<VecType&>(op)();
boost::python::stl_input_iterator<typename VecType::value_type> begin(
tup[0]),
end;
while (begin != end) {
o.push_back(*begin);
++begin;
}
static bool getstate_manages_dict() { return true; }
};
}
}
}
#endif // ifndef __pinocchio_python_utils_pickle_vector_hpp__
static bool getstate_manages_dict() { return true; }
};
} // namespace python
} // namespace pinocchio
#endif // ifndef __pinocchio_python_utils_pickle_vector_hpp__
......@@ -8,77 +8,78 @@
#include <boost/python.hpp>
#include <string>
#include "pinocchio/container/aligned-vector.hpp"
#include "pinocchio/bindings/python/utils/pickle-vector.hpp"
#include "pinocchio/bindings/python/utils/std-vector.hpp"
#include "pinocchio/container/aligned-vector.hpp"
namespace pinocchio {
namespace python {
///
/// \brief Expose an container::aligned_vector from a type given as template
/// argument.
///
/// \tparam T Type to expose as container::aligned_vector<T>.
/// \tparam EnableFromPythonListConverter Enables the conversion from a Python
/// list to a container::aligned_vector<T>.
///
/// \sa StdAlignedVectorPythonVisitor
///
template <class T, bool NoProxy = false,
bool EnableFromPythonListConverter = true>
struct StdAlignedVectorPythonVisitor
: public ::boost::python::vector_indexing_suite<
typename container::aligned_vector<T>, NoProxy,
internal::contains_vector_derived_policies<
typename container::aligned_vector<T>, NoProxy> >,
public StdContainerFromPythonList<container::aligned_vector<T> > {
typedef container::aligned_vector<T> vector_type;
typedef StdContainerFromPythonList<vector_type, NoProxy>
FromPythonListConverter;
typedef T value_type;
namespace pinocchio
{
namespace python
{
///
/// \brief Expose an container::aligned_vector from a type given as template argument.
///
/// \tparam T Type to expose as container::aligned_vector<T>.
/// \tparam EnableFromPythonListConverter Enables the conversion from a Python list to a container::aligned_vector<T>.
///
/// \sa StdAlignedVectorPythonVisitor
///
template<class T, bool NoProxy = false, bool EnableFromPythonListConverter = true>
struct StdAlignedVectorPythonVisitor
: public ::boost::python::vector_indexing_suite<typename container::aligned_vector<T>,NoProxy, internal::contains_vector_derived_policies<typename container::aligned_vector<T>,NoProxy> >
, public StdContainerFromPythonList< container::aligned_vector<T> >
{
typedef container::aligned_vector<T> vector_type;
typedef StdContainerFromPythonList<vector_type,NoProxy> FromPythonListConverter;
typedef T value_type;
static void expose(const std::string & class_name,
const std::string & doc_string = "")
{
expose(class_name,doc_string,EmptyPythonVisitor());
}
template<typename VisitorDerived>
static void expose(const std::string & class_name,
const boost::python::def_visitor<VisitorDerived> & visitor)
{
expose(class_name,"",visitor);
}
template<typename VisitorDerived>
static void expose(const std::string & class_name,
const std::string & doc_string,
const boost::python::def_visitor<VisitorDerived> & visitor)
{
namespace bp = boost::python;
if(!register_symbolic_link_to_registered_type<vector_type>())
{
bp::class_<vector_type> cl(class_name.c_str(),doc_string.c_str());
cl
.def(StdAlignedVectorPythonVisitor())
.def(bp::init<size_t, const value_type &>(bp::args("self","size","value"),"Constructor from a given size and a given value."))
.def(bp::init<const vector_type &>(bp::args("self","other"),"Copy constructor"))
.def("tolist",&FromPythonListConverter::tolist,bp::arg("self"),
static void expose(const std::string &class_name,
const std::string &doc_string = "") {
expose(class_name, doc_string, EmptyPythonVisitor());
}
template <typename VisitorDerived>
static void expose(
const std::string &class_name,
const boost::python::def_visitor<VisitorDerived> &visitor) {
expose(class_name, "", visitor);
}
template <typename VisitorDerived>
static void expose(
const std::string &class_name, const std::string &doc_string,
const boost::python::def_visitor<VisitorDerived> &visitor) {
namespace bp = boost::python;
if (!register_symbolic_link_to_registered_type<vector_type>()) {
bp::class_<vector_type> cl(class_name.c_str(), doc_string.c_str());
cl.def(StdAlignedVectorPythonVisitor())
.def(bp::init<size_t, const value_type &>(
bp::args("self", "size", "value"),
"Constructor from a given size and a given value."))
.def(bp::init<const vector_type &>(bp::args("self", "other"),
"Copy constructor"))
.def("tolist", &FromPythonListConverter::tolist, bp::arg("self"),
"Returns the aligned_vector as a Python list.")
.def(visitor)
#ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION
.def_pickle(PickleVector<vector_type>())
#endif
.def(CopyableVisitor<vector_type>())
;
// Register conversion
if(EnableFromPythonListConverter)
FromPythonListConverter::register_converter();
}
}
};
} // namespace python
} // namespace pinocchio
.def(CopyableVisitor<vector_type>());
// Register conversion
if (EnableFromPythonListConverter)
FromPythonListConverter::register_converter();
}
}
};
} // namespace python
} // namespace pinocchio
#endif // ifndef __pinocchio_python_utils_std_aligned_vector_hpp__
#endif // ifndef __pinocchio_python_utils_std_aligned_vector_hpp__
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment