2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-21 17:12:22 +00:00
Files
python/example/ivect.h
Ralf W. Grosse-Kunstleve 52ab91e34c Add examples that were meant to go here in the first place, but
were accidentally added to the main branch.


[SVN r9022]
2001-02-08 01:51:09 +00:00

33 lines
801 B
C++

#ifndef IVECT_H
#define IVECT_H
#include <vector>
#include <boost/python/class_builder.hpp>
namespace vects {
struct ivect : public std::vector<int>
{
ivect() : std::vector<int>() {}
ivect(size_t n) : std::vector<int>(n) {}
ivect(boost::python::tuple tuple) : std::vector<int>(tuple.size())
{
std::vector<int>::iterator v_it = begin();
for (int i = 0; i < tuple.size(); i++)
v_it[i] = BOOST_PYTHON_CONVERSION::from_python(tuple[i].get(),
boost::python::type<int>());
}
boost::python::tuple as_tuple() const
{
boost::python::tuple t(size());
for (int i = 0; i < size(); i++)
t.set_item(i,
boost::python::ref(BOOST_PYTHON_CONVERSION::to_python((*this)[i])));
return t;
}
};
}
#endif // IVECT_H