File:  [CENS] / python / pyGiNaC / wrappers4 / lst.cpp
Revision 1.6: download - view: text, annotated - select for diffs - revision graph
Mon Nov 26 22:37:44 2001 UTC (16 years ago) by pearu
Branches: MAIN
CVS tags: HEAD
See NEWS.txt (impl. matrix)

/*
  This file is part of the PyGiNaC package.
  http://cens.ioc.ee/projects/pyginac/

  $Revision: 1.6 $
  $Id: lst.cpp,v 1.6 2001-11-26 22:37:44 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.
*/

#ifndef PYGINAC_LST_CPP
#define PYGINAC_LST_CPP
/* prototypes */

GiNaC::ex lst(const GiNaC::exlist & v);
PyObject * lst_to_list(const GiNaC::lst & l);
void lst_append(GiNaC::lst & l,const GiNaC::ex & item);
void lst_prepend(GiNaC::lst & l,const GiNaC::ex & item);
void lst_sort(GiNaC::lst & l);
void lst_unique(GiNaC::lst & l);
void lst_remove_last(GiNaC::lst & l);
void lst_remove_first(GiNaC::lst & l);

BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE

GiNaC::lst & from_python(PyObject* o, py::type<GiNaC::lst &>);
const GiNaC::lst & from_python(PyObject* o, py::type<const GiNaC::lst &>);

BOOST_PYTHON_END_CONVERSION_NAMESPACE

#else
#ifndef PYGINAC_LST_CPP_1
#define PYGINAC_LST_CPP_1
/* definitions */

this_module.def(lst, "lst");
ex_class.def(lst_to_list, "lst_to_list");
ex_class.def(lst_append, "lst_append");
ex_class.def(lst_prepend, "lst_prepend");
ex_class.def(lst_sort, "lst_sort");
ex_class.def(lst_unique, "lst_unique");
ex_class.def(lst_remove_last, "lst_remove_last");
ex_class.def(lst_remove_first, "lst_remove_first");

#else
/* implementation */

GiNaC::ex lst(const GiNaC::exlist & v) {
  return GiNaC::lst(v);
}

PyObject * lst_to_list(const GiNaC::lst & l) {
  unsigned n = l.nops();
  PyObject * r = PyList_New(n);
  for (unsigned i=0;i<n;++i)
    PyList_SetItem(r,i,BOOST_PYTHON_CONVERSION::to_python(l.op(i)));
  return r;
}

void lst_append(GiNaC::lst & l,const GiNaC::ex & item) {
  l.append(item);
}
void lst_prepend(GiNaC::lst & l,const GiNaC::ex & item) {
  l.prepend(item);
}
void lst_sort(GiNaC::lst & l) {
  l.sort();
}
void lst_unique(GiNaC::lst & l) {
  l.unique();
}
void lst_remove_last(GiNaC::lst & l) {
  l.remove_last();
}
void lst_remove_first(GiNaC::lst & l) {
  l.remove_first();
}

BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE

GiNaC::lst & from_python(PyObject* o, py::type<GiNaC::lst &>) {
  if (PYOBJ_IS_EX(o)) {
    GiNaC::ex & e = pyobj_get_ex_nonconst(o);
    if (GiNaC::is_a<GiNaC::lst>(e))
      return GiNaC::ex_to_nonconst<GiNaC::lst>(e);
  }
  return *(new GiNaC::lst(from_python(o, py::type<const GiNaC::exlist &>())));
}

const GiNaC::lst & from_python(PyObject* o, py::type<const GiNaC::lst &>) {
  return from_python(o, py::type<GiNaC::lst &>());
}

BOOST_PYTHON_END_CONVERSION_NAMESPACE

#endif
#endif

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