File:  [CENS] / python / pyGiNaC / wrappers3 / ginac_enhancements.cpp
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Tue Apr 24 17:32:25 2001 UTC (16 years, 7 months ago) by pearu
Branches: MAIN
CVS tags: HEAD
Impl. constant,started matrix


#include <ginac/ginac.h>
#include <Python.h>
#include <boost/python/class_builder.hpp>

namespace py = boost::python;

namespace pyginac {
  GiNaC::ex constant_dummy(void);
  GiNaC::ex ex_from_ref(py::ref obj, bool flag=true);
}

namespace GiNaC {

  std::map<unsigned, py::ref> & constant_w_cache(void);

  ex constant::evalf(int level) const {
	std::map<unsigned, py::ref> & constant_cache = GiNaC::constant_w_cache();
	if (ef==pyginac::constant_dummy) {
	  const std::map<unsigned, py::ref>::const_iterator viter = constant_cache.find(this->gethash());
	  if (viter==constant_cache.end()) {
		PyErr_SetString(PyExc_RuntimeError,"constant() internal error (cache failed)");
		throw py::error_already_set();
	  }
	  PyObject * ret = viter->second.get();
	  if (PyCallable_Check(ret))
		ret = PyObject_CallFunction(ret,NULL);
	  if (ret==NULL)
		throw py::error_already_set();
	  ex r = pyginac::ex_from_ref(ret);
	  return r.evalf();
	}
	if (ef!=0) {
	  return ef();
	} else if (number != 0) {
	  return number->evalf();
	}
	return *this;
  }
}

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