File:  [CENS] / python / pyGiNaC / wrappers3 / seq_py.cpp
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Thu Apr 26 19:44:48 2001 UTC (16 years, 7 months ago) by pearu
Branches: MAIN
CVS tags: HEAD
Impl. pseries,ncmul. Preparing for a release.

/*
# This file is part of the PyGiNaC package.
# http://cens.ioc.ee/projects/pyginac/
#
# $Revision: 1.3 $
# $Id: seq_py.cpp,v 1.3 2001-04-26 19:44:48 pearu Exp $
#
# Copyright 2001 Pearu Peterson all rights reserved,
# Pearu Peterson <pearu@cens.ioc.ee>
# Permission to use, modify, and distribute this software is given under the
# terms of the LGPL.  See http://www.fsf.org
#
# NO WARRANTY IS EXPRESSED OR IMPLIED.  USE AT YOUR OWN RISK.
#
*/
/*DT
  Seq
  ---
  
 */


#ifdef PYGINAC_DEFS
//this_module.def(&fun, "fun");
//ex_class.def(&ex::mth, "mth");
#else
#ifdef PYGINAC_EX_PROTOS
#define PYGINAC_PROTOS
#endif
#ifdef PYGINAC_PROTOS
#ifdef PYGINAC_EX_PROTOS

#else // PYGINAC_EX_PROTOS
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
GiNaC::exvector & from_python (PyObject* o, py::type<const GiNaC::exvector &>);
GiNaC::exlist & from_python (PyObject* o, py::type<const GiNaC::exlist &>);
GiNaC::epvector & from_python (PyObject* o, py::type<const GiNaC::epvector &>);
GiNaC::expair & from_python (PyObject* o, py::type<const GiNaC::expair &>);
BOOST_PYTHON_END_CONVERSION_NAMESPACE
#endif // !PYGINAC_EX_PROTOS
#else  // PYGINAC_PROTOS
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
GiNaC::expair & from_python (PyObject* o, py::type<const GiNaC::expair &>) {
  if (PySequence_Check(o)) {
    std::size_t l = PySequence_Length(o);
    if (l==2)
      return *new GiNaC::expair(ex_from_ref(PySequence_GetItem(o,0)),
				ex_from_ref(PySequence_GetItem(o,1)));
  }
  PYGINAC_FROMPYTHON_TYPEERROR(expair,2-sequence);
}
GiNaC::epvector & from_python (PyObject* o, py::type<const GiNaC::epvector &>) {
  GiNaC::epvector &v = *new GiNaC::epvector();
  if (ExInstance_Check(o))
    v.push_back(from_python(o, py::type<const GiNaC::expair &>()));
  else if (Sequence_Check(o)) {
    std::size_t l = PySequence_Length(o);
    if (l>0 && !Sequence_Check(PySequence_GetItem(o,0)))
      v.push_back(from_python(o, py::type<const GiNaC::expair &>()));
    else
      for(std::size_t i = 0; i < l; ++i)
	v.push_back(from_python(PySequence_GetItem(o,i), py::type<const GiNaC::expair &>()));
  }
  else
    v.push_back(from_python(o, py::type<const GiNaC::expair &>()));
  return v;
}
GiNaC::exvector & from_python (PyObject* o, py::type<const GiNaC::exvector &>) {
  GiNaC::exvector &v = *new GiNaC::exvector();
  if (ExInstance_Check(o))
    v.push_back(from_python(o, py::type<GiNaC::ex &>()));
  else if (PySequence_Check(o)) {
    std::size_t l = PySequence_Length(o);
    for(std::size_t i = 0; i < l; ++i)
      v.push_back(ex_from_ref(PySequence_GetItem(o,i)));
  }
  else {
    v.push_back(ex_from_ref(o));
  }
  return v;
}
GiNaC::exlist & from_python (PyObject* o, py::type<const GiNaC::exlist &>) {
  GiNaC::exlist &v = *new GiNaC::exlist();
  if (ExInstance_Check(o))
    v.push_back(from_python(o, py::type<GiNaC::ex &>()));
  else if (PySequence_Check(o)) {
    std::size_t l = PySequence_Length(o);
    for(std::size_t i = 0; i < l; ++i)
      v.push_back(ex_from_ref(PySequence_GetItem(o,i)));
  }
  else {
    v.push_back(ex_from_ref(o));
  }
  return v;
}
BOOST_PYTHON_END_CONVERSION_NAMESPACE
#endif // !PYGINAC_PROTOS
#endif // !PYGINAC_DEFS




FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>