File:  [CENS] / python / pyGiNaC / wrappers4 / relational.cpp
Revision 1.4: download - view: text, annotated - select for diffs - revision graph
Thu Nov 22 14:50:04 2001 UTC (16 years ago) by pearu
Branches: MAIN
CVS tags: HEAD
See NEWS.txt for changes. There too many changes to list them here

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

  $Revision: 1.4 $
  $Id: relational.cpp,v 1.4 2001-11-22 14:50:04 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_RELATIONAL_CPP
#define PYGINAC_RELATIONAL_CPP
/* prototypes */

GiNaC::ex relational(const GiNaC::ex &, const GiNaC::ex &, GiNaC::relational::operators);
bool relational_bool(const GiNaC::relational & r);

BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE

GiNaC::relational::operators from_python (PyObject*, py::type<GiNaC::relational::operators>);
GiNaC::relational & from_python(PyObject*, py::type<GiNaC::relational &>);
const GiNaC::relational & from_python(PyObject*, py::type<const GiNaC::relational &>);

BOOST_PYTHON_END_CONVERSION_NAMESPACE

#else
#ifndef PYGINAC_RELATIONAL_CPP_1
#define PYGINAC_RELATIONAL_CPP_1
/* definitions */

this_module.def(&relational, "relational");
ex_class.def(&relational_bool, "relational_bool");

#else
/* implementation */

GiNaC::ex relational(const GiNaC::ex & lhs, const GiNaC::ex & rhs, GiNaC::relational::operators oper) {
  return GiNaC::relational(lhs,rhs,oper);
}

bool relational_bool(const GiNaC::relational & r) {
  return r;
}

BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE

GiNaC::relational::operators from_python (PyObject* o, py::type<GiNaC::relational::operators>) {
  if (PyString_Check(o)) {
    std::string s(PyString_AsString(o));
    if (s=="==") return GiNaC::relational::equal;
    if (s=="!=") return GiNaC::relational::not_equal;
    if (s=="<") return GiNaC::relational::less;
    if (s=="<=") return GiNaC::relational::less_or_equal;
    if (s==">") return GiNaC::relational::greater;
    if (s==">=") return GiNaC::relational::greater_or_equal;
  }
  PyErr_SetString(PyExc_TypeError,(std::string("from_python(relational::operators) expected string ==|!=|<|<=|>|>= but got ")+PyString_AsString(PyObject_Repr(PyObject_Type(o)))).c_str());
  throw py::error_already_set();
}

GiNaC::relational & from_python(PyObject* o, py::type<GiNaC::relational &>) {
  if (PYOBJ_IS_EX(o)) {
    GiNaC::ex & e = pyobj_get_ex_nonconst(o);
    if (GiNaC::is_a<GiNaC::relational>(e))
      return GiNaC::ex_to_nonconst<GiNaC::relational>(e);
  }
  PyErr_SetString(PyExc_TypeError,(std::string("from_python(relational) expected relational but got ")+PyString_AsString(PyObject_Repr(PyObject_Type(o)))).c_str());
  throw py::error_already_set();
}

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

BOOST_PYTHON_END_CONVERSION_NAMESPACE
#endif
#endif

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