3 * Interface to GiNaC's ABC. */
6 * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #ifndef __GINAC_BASIC_H__
24 #define __GINAC_BASIC_H__
30 // CINT needs <algorithm> to work properly with <vector>
33 #include <ginac/flags.h>
34 #include <ginac/tinfos.h>
35 #include <ginac/assertion.h>
36 #include <ginac/registrar.h>
38 #ifndef NO_GINAC_NAMESPACE
40 #endif // ndef NO_GINAC_NAMESPACE
49 //typedef vector<ex> exvector;
50 typedef vector<ex,malloc_alloc> exvector; // CINT does not like vector<...,default_alloc>
52 #define INLINE_BASIC_CONSTRUCTORS
54 /** This class is the ABC (abstract base class) of GiNaC's class hierarchy.
55 * It is responsible for the reference counting. */
58 GINAC_DECLARE_REGISTERED_CLASS(basic, void)
64 // default constructor, destructor, copy constructor assignment operator and helpers
67 #ifdef INLINE_BASIC_CONSTRUCTORS
68 : tinfo_key(TINFO_basic), flags(0), refcount(0)
73 #endif // def INLINE_BASIC_CONSTRUCTORS
76 #ifdef INLINE_BASIC_CONSTRUCTORS
79 GINAC_ASSERT((!(flags & status_flags::dynallocated))||(refcount==0));
83 #endif // def INLINE_BASIC_CONSTRUCTORS
85 basic(basic const & other)
86 #ifdef INLINE_BASIC_CONSTRUCTORS
92 #endif // def INLINE_BASIC_CONSTRUCTORS
94 virtual basic const & operator=(basic const & other);
97 void copy(basic const & other)
99 flags = other.flags & ~status_flags::dynallocated;
100 hashvalue = other.hashvalue;
101 tinfo_key = other.tinfo_key;
103 void destroy(bool call_parent) {}
105 // other constructors
107 #ifdef INLINE_BASIC_CONSTRUCTORS
108 : tinfo_key(ti), flags(0), refcount(0)
113 #endif // def INLINE_BASIC_CONSTRUCTORS
115 // functions overriding virtual functions from bases classes
118 // new virtual functions which can be overridden by derived classes
119 public: // only const functions please (may break reference counting)
120 virtual basic * duplicate() const;
121 virtual void print(ostream & os,unsigned upper_precedence=0) const;
122 virtual void printraw(ostream & os) const;
123 virtual void printtree(ostream & os, unsigned indent) const;
124 virtual void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
125 virtual void dbgprint(void) const;
126 virtual void dbgprinttree(void) const;
127 virtual bool info(unsigned inf) const;
128 virtual unsigned nops() const;
129 virtual ex op(int const i) const;
130 virtual ex & let_op(int const i);
131 virtual ex operator[](ex const & index) const;
132 virtual ex operator[](int const i) const;
133 virtual bool has(ex const & other) const;
134 virtual int degree(symbol const & s) const;
135 virtual int ldegree(symbol const & s) const;
136 virtual ex coeff(symbol const & s, int const n=1) const;
137 virtual ex collect(symbol const & s) const;
138 virtual ex eval(int level=0) const;
139 virtual ex evalf(int level=0) const;
140 virtual ex diff(symbol const & s) const;
141 virtual ex series(symbol const & s, ex const & point, int order) const;
142 virtual ex subs(lst const & ls, lst const & lr) const;
143 virtual ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
144 virtual numeric integer_content(void) const;
145 virtual ex smod(const numeric &xi) const;
146 virtual numeric max_coefficient(void) const;
147 virtual exvector get_indices(void) const;
148 virtual ex simplify_ncmul(exvector const & v) const;
149 protected: // non-const functions should be called from class ex only
150 virtual int compare_same_type(basic const & other) const;
151 virtual bool is_equal_same_type(basic const & other) const;
152 virtual unsigned return_type(void) const;
153 virtual unsigned return_type_tinfo(void) const;
154 virtual unsigned calchash(void) const;
155 virtual ex expand(unsigned options=0) const;
157 // non-virtual functions in this class
159 ex subs(ex const & e) const;
160 int compare(basic const & other) const;
161 bool is_equal(basic const & other) const;
162 basic const & hold(void) const;
163 unsigned gethash(void) const {if (flags & status_flags::hash_calculated) return hashvalue; else return calchash();}
164 unsigned tinfo(void) const {return tinfo_key;}
166 basic const & setflag(unsigned f) const {flags |= f; return *this;}
167 basic const & clearflag(unsigned f) const {flags &= ~f; return *this;}
168 void ensure_if_modifiable(void) const;
174 mutable unsigned flags;
175 mutable unsigned hashvalue;
176 static unsigned precedence;
177 static unsigned delta_indent;
184 extern const basic some_basic;
185 extern type_info const & typeid_basic;
189 extern int max_recursion_level;
191 // convenience macros
193 #ifndef NO_GINAC_NAMESPACE
195 #define is_of_type(OBJ,TYPE) \
196 (dynamic_cast<TYPE *>(const_cast<GiNaC::basic *>(&OBJ))!=0)
198 #define is_exactly_of_type(OBJ,TYPE) \
199 ((OBJ).tinfo()==GiNaC::TINFO_##TYPE)
201 #define is_ex_of_type(OBJ,TYPE) \
202 (dynamic_cast<TYPE *>(const_cast<GiNaC::basic *>((OBJ).bp))!=0)
204 #define is_ex_exactly_of_type(OBJ,TYPE) \
205 ((*(OBJ).bp).tinfo()==GiNaC::TINFO_##TYPE)
207 #else // ndef NO_GINAC_NAMESPACE
209 #define is_of_type(OBJ,TYPE) \
210 (dynamic_cast<TYPE *>(const_cast<basic *>(&OBJ))!=0)
212 #define is_exactly_of_type(OBJ,TYPE) \
213 ((OBJ).tinfo()==TINFO_##TYPE)
215 #define is_ex_of_type(OBJ,TYPE) \
216 (dynamic_cast<TYPE *>(const_cast<basic *>((OBJ).bp))!=0)
218 #define is_ex_exactly_of_type(OBJ,TYPE) \
219 ((*(OBJ).bp).tinfo()==TINFO_##TYPE)
221 #endif // ndef NO_GINAC_NAMESPACE
223 #ifndef NO_GINAC_NAMESPACE
225 #endif // ndef NO_GINAC_NAMESPACE
227 #endif // ndef __GINAC_BASIC_H__