From: Alexander Frink Date: Tue, 14 Dec 1999 20:41:18 +0000 (+0000) Subject: some changes to allow GiNaC to cooperate with cint: X-Git-Tag: release_0-5-0~92 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=721cff7b2f8d555e085202f6f3f47801b92d0413 some changes to allow GiNaC to cooperate with cint: matrix.h/.cpp: vector replaced with exvector where typedef vector exvector constant.h/.cpp: typedef for evalffunction color.h/.cpp: replaced vector with exvectorvector where typedef vector exvectorvector ex.h: OBSCURE_CINT_HACK defines around some weird code. Never define OBSCURE_CINT_HACK when compiling libginac --- diff --git a/ginac/color.cpp b/ginac/color.cpp index 468645dd..696d70f7 100644 --- a/ginac/color.cpp +++ b/ginac/color.cpp @@ -440,9 +440,9 @@ ex color::simplify_ncmul(exvector const & v) const exvector delta8vec; exvector fvec; exvector dvec; - vector Tvecs; + exvectorvector Tvecs; Tvecs.resize(MAX_REPRESENTATION_LABELS); - vector ONEvecs; + exvectorvector ONEvecs; ONEvecs.resize(MAX_REPRESENTATION_LABELS); exvector unknownvec; @@ -656,8 +656,8 @@ color color_delta8(ex const & a, ex const & b) void split_color_string_in_parts(exvector const & v, exvector & delta8vec, exvector & fvec, exvector & dvec, - vector & Tvecs, - vector & ONEvecs, + exvectorvector & Tvecs, + exvectorvector & ONEvecs, exvector & unknownvec) { // if not all elements are of type color, put all Ts in unknownvec to @@ -704,8 +704,8 @@ void split_color_string_in_parts(exvector const & v, exvector & delta8vec, } exvector recombine_color_string(exvector & delta8vec, exvector & fvec, - exvector & dvec, vector & Tvecs, - vector & ONEvecs, exvector & unknownvec) + exvector & dvec, exvectorvector & Tvecs, + exvectorvector & ONEvecs, exvector & unknownvec) { unsigned sz=delta8vec.size()+fvec.size()+dvec.size()+unknownvec.size(); for (unsigned rl=0; rl Tvecs; + exvectorvector Tvecs; Tvecs.resize(MAX_REPRESENTATION_LABELS); - vector ONEvecs; + exvectorvector ONEvecs; ONEvecs.resize(MAX_REPRESENTATION_LABELS); exvector unknownvec; @@ -817,9 +817,9 @@ ex simplify_pure_color_string(ex const & e) exvector delta8vec; exvector fvec; exvector dvec; - vector Tvecs; + exvectorvector Tvecs; Tvecs.resize(MAX_REPRESENTATION_LABELS); - vector ONEvecs; + exvectorvector ONEvecs; ONEvecs.resize(MAX_REPRESENTATION_LABELS); exvector unknownvec; diff --git a/ginac/color.h b/ginac/color.h index f72034d8..ecc0ddfd 100644 --- a/ginac/color.h +++ b/ginac/color.h @@ -36,6 +36,8 @@ const unsigned MAX_REPRESENTATION_LABELS = 4; const unsigned COLOR_EIGHT = 8; // N*N-1 const unsigned COLOR_THREE = 3; // N +typedef vector exvectorvector; + /** Base class for color object */ class color : public indexed { @@ -50,12 +52,12 @@ class color : public indexed friend unsigned subs_index_in_exvector(exvector & v, ex const & is, ex const & ir); friend void split_color_string_in_parts(exvector const & v, exvector & delta8vec, exvector & fvec, exvector & dvec, - vector & Tvecs, - vector & ONEvecs, + exvectorvector & Tvecs, + exvectorvector & ONEvecs, exvector & unknownvec); friend exvector recombine_color_string(exvector & delta8vec, exvector & fvec, - exvector & dvec, vector & Tvecs, - vector & ONEvecs, exvector & unknownvec); + exvector & dvec, exvectorvector & Tvecs, + exvectorvector & ONEvecs, exvector & unknownvec); friend ex color_trace_of_one_representation_label(exvector const & v); friend ex color_trace(exvector const & v, unsigned const rl); friend ex simplify_pure_color_string(ex const & e); @@ -149,12 +151,12 @@ ex color_h(ex const & a, ex const & b, ex const & c); color color_delta8(ex const & a, ex const & b); void split_color_string_in_parts(exvector const & v, exvector & delta8vec, exvector & fvec, exvector & dvec, - vector & Tvecs, - vector & ONEvecs, + exvectorvector & Tvecs, + exvectorvector & ONEvecs, exvector & unknownvec); exvector recombine_color_string(exvector & delta8vec, exvector & fvec, - exvector & dvec, vector & Tvecs, - vector & ONEvecs, exvector & unknownvec); + exvector & dvec, exvectorvector & Tvecs, + exvectorvector & ONEvecs, exvector & unknownvec); ex color_trace_of_one_representation_label(exvector const & v); ex color_trace(exvector const & v, unsigned const rl=0); ex simplify_pure_color_string(ex const & e); diff --git a/ginac/constant.cpp b/ginac/constant.cpp index f16a00f7..166b53e9 100644 --- a/ginac/constant.cpp +++ b/ginac/constant.cpp @@ -86,7 +86,7 @@ void constant::destroy(bool call_parent) // public -constant::constant(string const & initname, ex (*efun)()) : +constant::constant(string const & initname, evalffunctype efun) : basic(TINFO_constant), name(initname), ef(efun), // number(0), fct_assigned(true), serial(next_serial++) number(0), serial(next_serial++) diff --git a/ginac/constant.h b/ginac/constant.h index f6adc649..9d0151e3 100644 --- a/ginac/constant.h +++ b/ginac/constant.h @@ -30,6 +30,8 @@ namespace GiNaC { #endif // ndef NO_GINAC_NAMESPACE +typedef ex (*evalffunctype)(void); + /** This class holds constants, symbols with specific numerical value. Each * object of this class must either provide their own function to evaluate it * to class numeric or provide the constant as a numeric (if it's an exact @@ -51,7 +53,7 @@ protected: // other constructors public: - constant(string const & initname, ex (*efun)()=0); + constant(string const & initname, evalffunctype efun=0); constant(string const & initname, numeric const & initnumber); // functions overriding virtual functions from bases classes @@ -77,7 +79,7 @@ protected: private: string name; - ex (*ef)(); + evalffunctype ef; numeric * number; // bool fct_assigned; unsigned serial; //!< unique serial number for comparision diff --git a/ginac/ex.h b/ginac/ex.h index 29b9b077..f2c0a03e 100644 --- a/ginac/ex.h +++ b/ginac/ex.h @@ -71,6 +71,9 @@ public: GINAC_ASSERT(exZERO().bp->flags & status_flags::dynallocated); GINAC_ASSERT(bp!=0); ++bp->refcount; +#ifdef OBSCURE_CINT_HACK + update_last_created_or_assigned_bp(); +#endif // def OBSCURE_CINT_HACK } #else ; @@ -96,6 +99,9 @@ public: GINAC_ASSERT(bp!=0); GINAC_ASSERT((bp->flags) & status_flags::dynallocated); ++bp->refcount; +#ifdef OBSCURE_CINT_HACK + update_last_created_or_assigned_bp(); +#endif // def OBSCURE_CINT_HACK } #else ; @@ -114,6 +120,9 @@ public: delete bp; } bp=tmpbp; +#ifdef OBSCURE_CINT_HACK + update_last_created_or_assigned_bp(); +#endif // def OBSCURE_CINT_HACK return *this; } #else @@ -124,9 +133,12 @@ public: public: ex(basic const & other) #ifdef INLINE_EX_CONSTRUCTORS - { - construct_from_basic(other); - } + { + construct_from_basic(other); +#ifdef OBSCURE_CINT_HACK + update_last_created_or_assigned_bp(); +#endif // def OBSCURE_CINT_HACK + } #else ; #endif // def INLINE_EX_CONSTRUCTORS @@ -225,10 +237,39 @@ private: void construct_from_basic(basic const & other); void makewriteable(); +#ifdef OBSCURE_CINT_HACK +public: + static bool last_created_or_assigned_bp_can_be_converted_to_ex(void) + { + if (last_created_or_assigned_bp==0) return false; + if ((last_created_or_assigned_bp->flags & + status_flags::dynallocated)==0) return false; + if ((last_created_or_assigned_bp->flags & + status_flags::evaluated)==0) return false; + return true; + } +protected: + void update_last_created_or_assigned_bp(void) + { + if (last_created_or_assigned_bp!=0) { + if (--last_created_or_assigned_bp->refcount == 0) { + delete last_created_or_assigned_bp; + } + } + last_created_or_assigned_bp=bp; + ++last_created_or_assigned_bp->refcount; + last_created_or_assigned_bp_modified=true; + } +#endif // def OBSCURE_CINT_HACK + // member variables public: basic *bp; +#ifdef OBSCURE_CINT_HACK + static basic *last_created_or_assigned_bp; + static bool last_created_or_assigned_bp_modified; +#endif // def OBSCURE_CINT_HACK }; // utility functions diff --git a/ginac/matrix.cpp b/ginac/matrix.cpp index a4db03dd..dd0caa55 100644 --- a/ginac/matrix.cpp +++ b/ginac/matrix.cpp @@ -101,10 +101,10 @@ matrix::matrix(int r, int c) // protected /** Ctor from representation, for internal use only. */ -matrix::matrix(int r, int c, vector const & m2) +matrix::matrix(int r, int c, exvector const & m2) : basic(TINFO_matrix), row(r), col(c), m(m2) { - debugmsg("matrix constructor from int,int,vector",LOGLEVEL_CONSTRUCT); + debugmsg("matrix constructor from int,int,exvector",LOGLEVEL_CONSTRUCT); } ////////// @@ -170,7 +170,7 @@ ex & matrix::let_op(int const i) /** expands the elements of a matrix entry by entry. */ ex matrix::expand(unsigned options) const { - vector tmp(row*col); + exvector tmp(row*col); for (int i=0; i::const_iterator r=m.begin(); r!=m.end(); ++r) { + for (exvector::const_iterator r=m.begin(); r!=m.end(); ++r) { if ((*r).has(other)) return true; } return false; @@ -209,7 +209,7 @@ ex matrix::eval(int level) const } // eval() entry by entry - vector m2(row*col); + exvector m2(row*col); --level; for (int r=0; r m2(row*col); + exvector m2(row*col); --level; for (int r=0; r sum(this->m); - vector::iterator i; - vector::const_iterator ci; + exvector sum(this->m); + exvector::iterator i; + exvector::const_iterator ci; for (i=sum.begin(), ci=other.m.begin(); i!=sum.end(); ++i, ++ci) { @@ -311,9 +311,9 @@ matrix matrix::sub(matrix const & other) const throw (std::logic_error("matrix::sub(): incompatible matrices")); } - vector dif(this->m); - vector::iterator i; - vector::const_iterator ci; + exvector dif(this->m); + exvector::iterator i; + exvector::const_iterator ci; for (i=dif.begin(), ci=other.m.begin(); i!=dif.end(); ++i, ++ci) { @@ -331,7 +331,7 @@ matrix matrix::mul(matrix const & other) const throw (std::logic_error("matrix::mul(): incompatible matrices")); } - vector prod(row*other.col); + exvector prod(row*other.col); for (int i=0; i trans(col*row); + exvector trans(col*row); for (int r=0; r::const_iterator r=m.begin(); r!=m.end(); ++r) { + for (exvector::const_iterator r=m.begin(); r!=m.end(); ++r) { if (!(*r).info(info_flags::numeric)) { if (normalized) { return determinant_symbolic_minor(*this).normal(); @@ -861,7 +861,7 @@ matrix matrix::solve(matrix const & v) const } // assemble the solution matrix - vector sol(v.row*v.col); + exvector sol(v.row*v.col); for (int c=0; c=0; --r) { sol[r*v.col+c] = tmp[r*tmp.col+c]; diff --git a/ginac/matrix.h b/ginac/matrix.h index cf6b1699..8e7ab39e 100644 --- a/ginac/matrix.h +++ b/ginac/matrix.h @@ -54,7 +54,7 @@ protected: // other constructors public: matrix(int r, int c); - matrix(int r, int c, vector const & m2); + matrix(int r, int c, exvector const & m2); // functions overriding virtual functions from bases classes public: @@ -102,7 +102,7 @@ protected: protected: int row; /**< number of rows */ int col; /**< number of columns */ - vector m; /**< representation (cols indexed first) */ + exvector m; /**< representation (cols indexed first) */ static unsigned precedence; };