File:  [CENS] / python / pyGiNaC / wrappers / expair.py
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Wed Apr 11 20:31:30 2001 UTC (16 years, 7 months ago) by pearu
Branches: MAIN
CVS tags: HEAD
Exposed lots of functions. Documented most important classes/functions. minor_version = 2

# This file is part of the PyGiNaC package.
# http://cens.ioc.ee/projects/pyginac/
#
# $Revision: 1.3 $
# $Id: expair.py,v 1.3 2001-04-11 20:31:30 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.
#

depends = ['ex']
uses = []

#STARTPROTO
class expair:
    """A pair of expressions.
    This is similar to STL's pair<>. It is slightly extended since we
    need to account for methods like .compare(). Also, since this is
    meant for use by class expairseq it must satisfy the invariance
    that the member coeff must be of type numeric.
    """
    def __init__(self,r,c):
        """expair(r,c)
        expair(seq) - from 2-sequence
        """
    def is_less(self,other):
        """Member-wise check for canonical ordering lessness."""
    def is_equal(self,other):
        """Member-wise check for canonical ordering equality."""
    def is_canonical_numeric(self):
        """True if this is of the form (numeric,ex(1))."""
    def __setattr__rest__(self,value):
        pass
    def __getattr__rest__(self):
        pass
    def __setattr__coeff__(self,value):
        pass
    def __getattr__coeff__(self):
        pass

#ENDPROTO

wrapperclass = '''

class expair_w : public GiNaC::expair {
  PyObject * self;
public:
  expair_w(const GiNaC::expair & other): GiNaC::expair(other) {
    DEBUG_C("expair_w::expair_w(raw:GiNaC::expair)");
  }
  expair_w(python::ref other);

  expair_w(PyObject * self_): GiNaC::expair(), self(self_) {
    DEBUG_C("expair_w::expair_w()");
  }
  expair_w(PyObject* self_, const GiNaC::expair & other)
  : GiNaC::expair(other), self(self_) {
    DEBUG_C("expair_w::expair_w(expair)");
  }
  expair_w(PyObject * self_, python::ref r, python::ref c)
  : GiNaC::expair(ex_w(r), ex_w(c)), self(self_) {  
    DEBUG_C("expair_w::expair_w(ref,ref)");
  }
  expair_w(PyObject * self_, python::ref obj)
  : GiNaC::expair(expair_w(obj)), self(self_) {
    DEBUG_C("expair_w::expair_w(ref)");
  }

  ~expair_w() {
    DEBUG_C("expair_w::~expair_w()");
  }
  std::string python_repr(void) const {
    std::ostrstream os;
    os << "expair";
    GiNaC::python_repr(os, *this);
    os << std::ends;
    return os.str();
  }
  std::string python_str(void) const {
    std::ostrstream os;
    GiNaC::python_str(os, *this);
    os << std::ends;
    return os.str();
  }
  //std::string tostring(void) const;
  
  inline void set_rest(python::ref r) { this->rest = ex_w(r); }
  inline GiNaC::ex get_rest(void) { return this->rest; }
  inline void set_coeff(python::ref c) { this->coeff = ex_w(c); }
  inline GiNaC::ex get_coeff(void) { return this->coeff; }
};

'''
protos = '''
'''

builder = '''
python::class_builder<expair_w> expair_w_class(this_module, "_expair_w");
python::class_builder<GiNaC::expair, expair_w> expair_class(this_module, "expair");
expair_class.declare_base(expair_w_class);
expair_py_class = python::as_object(expair_class.get_extension_class());
'''

constructors = '''
expair_class.def(python::constructor<>());
expair_class.def(python::constructor<const GiNaC::expair &>());
expair_class.def(python::constructor<python::ref>());
expair_class.def(python::constructor<python::ref, python::ref>());
'''

defs = '''
//expair_class.def(&expair_w::tostring, "__str__");
//expair_class.def(&expair_w::tostringraw, "__repr__");
expair_class.def(&expair_w::python_str, "__str__");
expair_class.def(&expair_w::python_repr, "__repr__");

expair_class.def(&expair_w::is_equal, "is_equal");
expair_class.def(&expair_w::is_less, "is_less");
expair_class.def(&expair_w::is_canonical_numeric, "is_canonical_numeric");
//expair_class.def(&expair_w::compare, "compare"); // for internal use
expair_class.def(&expair_w::set_rest, "__setattr__rest__");
expair_class.def(&expair_w::get_rest, "__getattr__rest__");
expair_class.def(&expair_w::set_coeff, "__setattr__coeff__");
expair_class.def(&expair_w::get_coeff, "__getattr__coeff__");
'''

implementation = '''
expair_w::expair_w(python::ref other): GiNaC::expair(), self()
{
  PyObject * o = other.get();
  DEBUG_C("expair_w::expair_w(raw:ref)");
  if (ExpairInstance_Check(o)) {
    Py_INCREF(o);
    GiNaC::expair p = BOOST_PYTHON_CONVERSION::from_python(o, python::type<const GiNaC::expair &>());
    this->rest = p.rest;
    this->coeff = p.coeff;
  } else if (PySequence_Check(o) && (PySequence_Length(o)==2)) {
    this->rest = ex_w(python::ref(PySequence_GetItem(o,0)));
    this->coeff = ex_w(python::ref(PySequence_GetItem(o,1)));
  } else {
    PyErr_SetString(PyExc_TypeError, "expair() argument must be 2-sequence|expair|ex,ex");
    throw python::error_already_set();
  }
}
/*
std::string expair_w::tostring(void) const {
  std::ostrstream s;
  DEBUG_S("torepr(GiNaC::expair)")
  s << "(";
  this->rest.bp->print(s);
  s << ", ";
  this->coeff.bp->print(s);
  s << ")" << ends;
  return s.str();
}
*/
'''

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