Chris@16: Chris@16: // (C) Copyright Joel de Guzman 2003. Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef PY_CONTAINER_UTILS_JDG20038_HPP Chris@16: # define PY_CONTAINER_UTILS_JDG20038_HPP Chris@16: Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: Chris@16: namespace boost { namespace python { namespace container_utils { Chris@16: Chris@16: template Chris@16: void Chris@16: extend_container(Container& container, object l) Chris@16: { Chris@16: typedef typename Container::value_type data_type; Chris@16: Chris@16: // l must be iterable Chris@16: BOOST_FOREACH(object elem, Chris@16: std::make_pair( Chris@16: boost::python::stl_input_iterator(l), Chris@16: boost::python::stl_input_iterator() Chris@16: )) Chris@16: { Chris@16: extract x(elem); Chris@16: // try if elem is an exact data_type type Chris@16: if (x.check()) Chris@16: { Chris@16: container.push_back(x()); Chris@16: } Chris@16: else Chris@16: { Chris@16: // try to convert elem to data_type type Chris@16: extract x(elem); Chris@16: if (x.check()) Chris@16: { Chris@16: container.push_back(x()); Chris@16: } Chris@16: else Chris@16: { Chris@16: PyErr_SetString(PyExc_TypeError, "Incompatible Data Type"); Chris@16: throw_error_already_set(); Chris@16: } Chris@16: } Chris@16: } Chris@16: } Chris@16: Chris@16: }}} // namespace boost::python::container_utils Chris@16: Chris@16: #endif