File indexing completed on 2025-02-22 10:26:16
0001
0002
0003
0004
0005
0006
0007 #ifndef PY_CONTAINER_UTILS_JDG20038_HPP
0008 # define PY_CONTAINER_UTILS_JDG20038_HPP
0009
0010 # include <utility>
0011 # include <boost/foreach.hpp>
0012 # include <boost/python/object.hpp>
0013 # include <boost/python/handle.hpp>
0014 # include <boost/python/extract.hpp>
0015 # include <boost/python/stl_iterator.hpp>
0016
0017 namespace boost { namespace python { namespace container_utils {
0018
0019 template <typename Container>
0020 void
0021 extend_container(Container& container, object l)
0022 {
0023 typedef typename Container::value_type data_type;
0024
0025
0026 BOOST_FOREACH(object elem,
0027 std::make_pair(
0028 boost::python::stl_input_iterator<object>(l),
0029 boost::python::stl_input_iterator<object>()
0030 ))
0031 {
0032 extract<data_type const&> x(elem);
0033
0034 if (x.check())
0035 {
0036 container.push_back(x());
0037 }
0038 else
0039 {
0040
0041 extract<data_type> x(elem);
0042 if (x.check())
0043 {
0044 container.push_back(x());
0045 }
0046 else
0047 {
0048 PyErr_SetString(PyExc_TypeError, "Incompatible Data Type");
0049 throw_error_already_set();
0050 }
0051 }
0052 }
0053 }
0054
0055 }}}
0056
0057 #endif