Commit 0c0e089a authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Guilhem Saurel
Browse files

[Python] Add constructor of Flags from list or tuple.

parent c1c85134
......@@ -37,7 +37,7 @@ protected:
public:
Flags(const bool &b = false);
Flags(const char *flags);
Flags(std::vector<bool> &&flags);
Flags(const std::vector<bool> &flags);
void add(const bool &b);
......
......@@ -50,7 +50,16 @@ BOOST_PYTHON_MODULE(wrap)
using dgs::Flags;
bp::class_<Flags>("Flags", bp::init<>())
.def(bp::init<const char*>())
//TODO .def(bp::init<std::vector<bool>&& >())
.def("__init__", bp::make_constructor(+[](bp::list bools) {
std::vector<bool> flags (bp::len(bools));
for (std::size_t i = 0; i < flags.size(); ++i) flags[i] = bp::extract<bool>(bools[i]);
return new Flags(flags);
}))
.def("__init__", bp::make_constructor(+[](bp::tuple bools) {
std::vector<bool> flags (bp::len(bools));
for (std::size_t i = 0; i < flags.size(); ++i) flags[i] = bp::extract<bool>(bools[i]);
return new Flags(flags);
}))
.def("add", &Flags::add)
.def("set", &Flags::set)
.def("unset", &Flags::unset)
......
......@@ -47,7 +47,7 @@ Flags::Flags(const char *_flags)
}
}
Flags::Flags(std::vector<bool> &&_flags)
Flags::Flags(const std::vector<bool> &_flags)
: flags(_flags), outOfRangeFlag(false) {}
Flags::operator bool(void) const {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment