Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:26:16

0001 
0002 //  (C) Copyright Joel de Guzman 2003.
0003 //  Distributed under the Boost Software License, Version 1.0. (See
0004 //  accompanying file LICENSE_1_0.txt or copy at
0005 //  http://www.boost.org/LICENSE_1_0.txt)
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         //  l must be iterable
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             //  try if elem is an exact data_type type
0034             if (x.check())
0035             {
0036                 container.push_back(x());
0037             }
0038             else
0039             {
0040                 //  try to convert elem to data_type type
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 }}} // namespace boost::python::container_utils
0056 
0057 #endif