Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
boost::python::container_utils Namespace Reference

Functions

template<typename Container >
void extend_container (Container &container, object l)
 

Function Documentation

template<typename Container >
void boost::python::container_utils::extend_container ( Container &  container,
object  l 
)

Definition at line 18 of file container_utils.hpp.

19  {
20  typedef typename Container::value_type data_type;
21 
22  // l must be a list or some container
23 
24  for (int i = 0; i < l.attr("__len__")(); i++)
25  {
26  object elem(l[i]);
27  extract<data_type const&> x(elem);
28  // try if elem is an exact data_type type
29  if (x.check())
30  {
31  container.push_back(x());
32  }
33  else
34  {
35  // try to convert elem to data_type type
36  extract<data_type> x(elem);
37  if (x.check())
38  {
39  container.push_back(x());
40  }
41  else
42  {
43  PyErr_SetString(PyExc_TypeError, "Incompatible Data Type");
44  throw_error_already_set();
45  }
46  }
47  }
48  }
tuple x
Definition: test.py:50