// public
-basic * add::duplicate() const
-{
- debugmsg("add duplicate",LOGLEVEL_DUPLICATE);
- return new add(*this);
-}
-
void add::print(std::ostream & os, unsigned upper_precedence) const
{
debugmsg("add print",LOGLEVEL_PRINT);
// functions overriding virtual functions from bases classes
public:
- basic * duplicate() const;
void print(std::ostream & os, unsigned upper_precedence=0) const;
void printraw(std::ostream & os) const;
void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence=0) const;
ex simplify_ncmul(const exvector & v) const;
protected:
ex derivative(const symbol & s) const;
- int compare_same_type(const basic & other) const;
bool is_equal_same_type(const basic & other) const;
unsigned return_type(void) const;
unsigned return_type_tinfo(void) const;
// public
-basic * clifford::duplicate() const
-{
- debugmsg("clifford duplicate",LOGLEVEL_DUPLICATE);
- return new clifford(*this);
-}
-
void clifford::printraw(std::ostream & os) const
{
debugmsg("clifford printraw",LOGLEVEL_PRINT);
// functions overriding virtual functions from base classes
public:
- basic * duplicate() const;
void printraw(std::ostream & os) const;
void printtree(std::ostream & os, unsigned indent) const;
void print(std::ostream & os, unsigned upper_precedence=0) const;
bool info(unsigned inf) const;
// ex eval(int level=0) const;
protected:
- int compare_same_type(const basic & other) const;
bool is_equal_same_type(const basic & other) const;
ex simplify_ncmul(const exvector & v) const;
ex thisexprseq(const exvector & v) const;
// public
-basic * color::duplicate() const
-{
- debugmsg("color duplicate",LOGLEVEL_DUPLICATE);
- return new color(*this);
-}
-
void color::printraw(std::ostream & os) const
{
debugmsg("color printraw",LOGLEVEL_PRINT);
// functions overriding virtual functions from base classes
public:
- basic * duplicate() const;
void printraw(std::ostream & os) const;
void printtree(std::ostream & os, unsigned indent) const;
void print(std::ostream & os, unsigned upper_precedence=0) const;
bool info(unsigned inf) const;
ex eval(int level=0) const;
protected:
- int compare_same_type(const basic & other) const;
bool is_equal_same_type(const basic & other) const;
ex simplify_ncmul(const exvector & v) const;
ex thisexprseq(const exvector & v) const;
// public
-basic * coloridx::duplicate() const
-{
- debugmsg("coloridx duplicate",LOGLEVEL_DUPLICATE);
- return new coloridx(*this);
-}
-
void coloridx::printraw(std::ostream & os) const
{
debugmsg("coloridx printraw",LOGLEVEL_PRINT);
return idx::info(inf);
}
+int coloridx::compare_same_type(const basic & other) const
+{
+ return inherited::compare_same_type(other);
+}
+
#ifndef NO_NAMESPACE_GINAC
} // namespace GiNaC
#endif // ndef NO_NAMESPACE_GINAC
// functions overriding virtual functions from bases classes
public:
- basic * duplicate() const;
void printraw(std::ostream & os) const;
void printtree(std::ostream & os, unsigned indent) const;
void print(std::ostream & os, unsigned upper_precedence=0) const;
// public
-basic * constant::duplicate() const
-{
- debugmsg("constant duplicate",LOGLEVEL_DUPLICATE);
- return new constant(*this);
-}
-
void constant::print(std::ostream & os, unsigned upper_precedence) const
{
debugmsg("constant print",LOGLEVEL_PRINT);
// functions overriding virtual functions from bases classes
public:
- basic * duplicate() const;
void print(std::ostream & os, unsigned upper_precedence=0) const;
void printraw(std::ostream & os) const;
void printtree(std::ostream & os, unsigned indent) const;
ex evalf(int level=0) const;
protected:
ex derivative(const symbol & s) const;
- int compare_same_type(const basic & other) const;
bool is_equal_same_type(const basic & other) const;
// new virtual functions which can be overridden by derived classes
${constructors_interface}
public:
- basic * duplicate() const;
void printraw(std::ostream & os) const;
void print(std::ostream & os, unsigned upper_precedence=0) const;
void printtree(std::ostream & os, unsigned indent) const;
ex derivative(const symbol & s) const;
ex subs(const lst & ls, const lst & lr) const;
protected:
- int compare_same_type(const basic & other) const;
bool is_equal_same_type(const basic & other) const;
unsigned return_type(void) const;
// public
-basic * ${CONTAINER}::duplicate() const
-{
- debugmsg("${CONTAINER} duplicate",LOGLEVEL_DUPLICATE);
- return new ${CONTAINER}(*this);
-}
-
void ${CONTAINER}::printraw(std::ostream & os) const
{
debugmsg("${CONTAINER} printraw",LOGLEVEL_PRINT);
// public
-basic * fail::duplicate() const
-{
- debugmsg("fail duplicate",LOGLEVEL_DUPLICATE);
- return new fail(*this);
-}
-
void fail::print(std::ostream & os, unsigned upper_precedence) const
{
debugmsg("fail print",LOGLEVEL_PRINT);
// functions overriding virtual functions from bases classes
public:
- basic * duplicate() const;
void print(std::ostream & os, unsigned upper_precedence=0) const;
void printraw(std::ostream & os) const;
protected:
- int compare_same_type(const basic & other) const;
unsigned return_type(void) const { return return_types::noncommutative_composite; };
// new virtual functions which can be overridden by derived classes
// functions overriding virtual functions from bases classes
public:
- basic * duplicate() const;
void printraw(std::ostream & os) const;
void print(std::ostream & os, unsigned upper_precedence=0) const;
void printtree(std::ostream & os, unsigned indent) const;
ex thisexprseq(exvector * vp) const;
protected:
ex derivative(const symbol & s) const;
- int compare_same_type(const basic & other) const;
bool is_equal_same_type(const basic & other) const;
unsigned return_type(void) const;
unsigned return_type_tinfo(void) const;
// public
-basic * function::duplicate() const
-{
- debugmsg("function duplicate",LOGLEVEL_DUPLICATE);
- return new function(*this);
-}
-
void function::printraw(std::ostream & os) const
{
debugmsg("function printraw",LOGLEVEL_PRINT);
// public
-basic * idx::duplicate() const
-{
- debugmsg("idx duplicate",LOGLEVEL_DUPLICATE);
- return new idx(*this);
-}
-
void idx::printraw(std::ostream & os) const
{
debugmsg("idx printraw",LOGLEVEL_PRINT);
int idx::compare_same_type(const basic & other) const
{
GINAC_ASSERT(is_of_type(other,idx));
- const idx &o = static_cast<const idx &>(&other);
+ const idx &o = static_cast<const idx &>(other);
if (covariant!=o.covariant) {
// different co/contravariant
// functions overriding virtual functions from bases classes
public:
- basic * duplicate() const;
void printraw(std::ostream & os) const;
void printtree(std::ostream & os, unsigned indent) const;
void print(std::ostream & os, unsigned upper_precedence=0) const;
bool info(unsigned inf) const;
protected:
- int compare_same_type(const basic & other) const;
bool is_equal_same_type(const basic & other) const;
unsigned calchash(void) const;
ex subs(const lst & ls, const lst & lr) const;
// public
-basic * indexed::duplicate() const
-{
- debugmsg("indexed duplicate",LOGLEVEL_DUPLICATE);
- return new indexed(*this);
-}
-
void indexed::printraw(std::ostream & os) const
{
debugmsg("indexed printraw",LOGLEVEL_PRINT);
// functions overriding virtual functions from base classes
public:
- basic * duplicate() const;
void printraw(std::ostream & os) const;
void printtree(std::ostream & os, unsigned indent) const;
void print(std::ostream & os, unsigned upper_precedence=0) const;
protected:
ex derivative(const symbol & s) const;
- int compare_same_type(const basic & other) const;
bool is_equal_same_type(const basic & other) const;
unsigned return_type(void) const;
unsigned return_type_tinfo(void) const;
// public
-basic * isospin::duplicate() const
-{
- debugmsg("isospin duplicate",LOGLEVEL_DUPLICATE);
- return new isospin(*this);
-}
-
void isospin::printraw(std::ostream & os) const
{
debugmsg("isospin printraw",LOGLEVEL_PRINT);
// functions overriding virtual functions from base classes
public:
- basic * duplicate() const;
void printraw(std::ostream & os) const;
void printtree(std::ostream & os, unsigned indent) const;
void print(std::ostream & os, unsigned upper_precedence=0) const;
void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence=0) const;
bool info(unsigned inf) const;
protected:
- int compare_same_type(const basic & other) const;
ex simplify_ncmul(const exvector & v) const;
unsigned calchash(void) const;
// public
-basic * lorentzidx::duplicate() const
-{
- debugmsg("lorentzidx duplicate",LOGLEVEL_DUPLICATE);
- return new lorentzidx(*this);
-}
-
void lorentzidx::printraw(std::ostream & os) const
{
debugmsg("lorentzidx printraw",LOGLEVEL_PRINT);
return inherited::info(inf);
}
+int lorentzidx::compare_same_type(const basic & other) const
+{
+ GINAC_ASSERT(is_of_type(other, lorentzidx));
+ const lorentzidx &o = static_cast<const lorentzidx &>(other);
+
+ if (orthogonal_only != o.orthogonal_only)
+ return orthogonal_only ? -1 : 1;
+ if (dim_parallel_space != o.dim_parallel_space)
+ return dim_parallel_space < o.dim_parallel_space ? -1 : 1;
+ return inherited::compare_same_type(other);
+}
+
//////////
// non-virtual functions in this class
//////////
// functions overriding virtual functions from bases classes
public:
- basic * duplicate() const;
void printraw(std::ostream & os) const;
void printtree(std::ostream & os, unsigned indent) const;
void print(std::ostream & os, unsigned upper_precedence=0) const;
//public
-basic * lortensor::duplicate() const
-{
- debugmsg("lortensor duplicate",LOGLEVEL_DUPLICATE);
- return new lortensor(*this);
-}
-
void lortensor::printraw(std::ostream & os) const
{
debugmsg("lortensor printraw",LOGLEVEL_PRINT);
//functions overriding virtual functions from base classes
public:
- basic * duplicate() const;
void printraw(std::ostream & os) const;
void printtree(std::ostream & os, unsigned indent) const;
void print(std::ostream & os, unsigned upper_precedence=0) const;
bool info(unsigned inf) const;
ex eval(int level=0) const;
protected:
- int compare_same_type(const basic & other) const;
bool is_equal_same_type(const basic & other) const;
unsigned return_type(void) const;
unsigned return_type_tinfo(void) const;
// public
-basic * matrix::duplicate() const
-{
- debugmsg("matrix duplicate",LOGLEVEL_DUPLICATE);
- return new matrix(*this);
-}
-
void matrix::print(std::ostream & os, unsigned upper_precedence) const
{
debugmsg("matrix print",LOGLEVEL_PRINT);
// functions overriding virtual functions from bases classes
public:
- basic * duplicate() const;
void print(std::ostream & os, unsigned upper_precedence=0) const;
void printraw(std::ostream & os) const;
unsigned nops() const;
ex evalf(int level=0) const;
// ex subs(const lst & ls, const lst & lr) const;
protected:
- int compare_same_type(const basic & other) const;
unsigned return_type(void) const { return return_types::noncommutative; };
// new virtual functions which can be overridden by derived classes
// (none)
// public
-basic * mul::duplicate() const
-{
- debugmsg("mul duplicate",LOGLEVEL_ASSIGNMENT);
- return new mul(*this);
-}
-
void mul::print(std::ostream & os, unsigned upper_precedence) const
{
debugmsg("mul print",LOGLEVEL_PRINT);
// functions overriding virtual functions from bases classes
public:
- basic * duplicate() const;
void print(std::ostream & os, unsigned upper_precedence) const;
void printraw(std::ostream & os) const;
void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence) const;
ex simplify_ncmul(const exvector & v) const;
protected:
ex derivative(const symbol & s) const;
- int compare_same_type(const basic & other) const;
bool is_equal_same_type(const basic & other) const;
unsigned return_type(void) const;
unsigned return_type_tinfo(void) const;
// public
-basic * ncmul::duplicate() const
-{
- debugmsg("ncmul duplicate",LOGLEVEL_ASSIGNMENT);
- return new ncmul(*this);
-}
-
void ncmul::print(std::ostream & os, unsigned upper_precedence) const
{
debugmsg("ncmul print",LOGLEVEL_PRINT);
// functions overriding virtual functions from bases classes
public:
- basic * duplicate() const;
void print(std::ostream & os, unsigned upper_precedence) const;
void printraw(std::ostream & os) const;
void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence = 0) const;
ex thisexprseq(exvector * vp) const;
protected:
ex derivative(const symbol & s) const;
- int compare_same_type(const basic & other) const;
unsigned return_type(void) const;
unsigned return_type_tinfo(void) const;
// functions overriding virtual functions from bases classes
//////////
-// public
-
-basic * numeric::duplicate() const
-{
- debugmsg("numeric duplicate", LOGLEVEL_DUPLICATE);
- return new numeric(*this);
-}
-
-
/** Helper function to print a real number in a nicer way than is CLN's
* default. Instead of printing 42.0L0 this just prints 42.0 to ostream os
* and instead of 3.99168L7 it prints 3.99168E7. This is fine in GiNaC as
// functions overriding virtual functions from bases classes
public:
- basic * duplicate() const;
void print(std::ostream & os, unsigned precedence=0) const;
void printraw(std::ostream & os) const;
void printtree(std::ostream & os, unsigned indent) const;
numeric max_coefficient(void) const;
protected:
ex derivative(const symbol & s) const;
- int compare_same_type(const basic & other) const;
bool is_equal_same_type(const basic & other) const;
unsigned calchash(void) const;
// public
-basic * power::duplicate() const
-{
- debugmsg("power duplicate",LOGLEVEL_DUPLICATE);
- return new power(*this);
-}
-
void power::print(std::ostream & os, unsigned upper_precedence) const
{
debugmsg("power print",LOGLEVEL_PRINT);
// functions overriding virtual functions from bases classes
public:
- basic * duplicate() const;
void print(std::ostream & os, unsigned upper_precedence = 0) const;
void printraw(std::ostream & os) const;
void printtree(std::ostream & os, unsigned indent) const;
ex simplify_ncmul(const exvector & v) const;
protected:
ex derivative(const symbol & s) const;
- int compare_same_type(const basic & other) const;
unsigned return_type(void) const;
unsigned return_type_tinfo(void) const;
ex expand(unsigned options = 0) const;
// functions overriding virtual functions from bases classes
//////////
-basic *pseries::duplicate() const
-{
- debugmsg("pseries duplicate", LOGLEVEL_DUPLICATE);
- return new pseries(*this);
-}
-
void pseries::print(std::ostream &os, unsigned upper_precedence) const
{
debugmsg("pseries print", LOGLEVEL_PRINT);
point.printtree(os, indent+delta_indent);
}
+int pseries::compare_same_type(const basic & other) const
+{
+ GINAC_ASSERT(is_of_type(other, pseries));
+ const pseries &o = static_cast<const pseries &>(other);
+
+ int cmpval = var.compare(o.var);
+ if (cmpval)
+ return cmpval;
+ cmpval = point.compare(o.point);
+ if (cmpval)
+ return cmpval;
+
+ epvector::const_iterator it1 = seq.begin(), it2 = o.seq.begin(), it1end = seq.end(), it2end = o.seq.end();
+ while ((it1 != it1end) && (it2 != it2end)) {
+ cmpval = it1->compare(*it2);
+ if (cmpval)
+ return cmpval;
+ it1++; it2++;
+ }
+ if (it1 == it1end)
+ return it2 == it2end ? 0 : -1;
+
+ return 0;
+}
+
/** Return the number of operands including a possible order term. */
unsigned pseries::nops(void) const
{
// functions overriding virtual functions from base classes
public:
- basic *duplicate() const;
void print(std::ostream &os, unsigned upper_precedence = 0) const;
void printraw(std::ostream &os) const;
void printtree(std::ostream & os, unsigned indent) const;
/** Expansion point */
ex point;
+
static unsigned precedence;
};
virtual void archive(archive_node &n) const; \
static ex unarchive(const archive_node &n, const lst &sym_lst);
-/** Macro for inclusion in the declaration of each registered class. */
+/** Macro for inclusion in the declaration of each registered class.
+ * It declares some functions that are common to all classes derived
+ * from 'basic' as well as all required stuff for the GiNaC class
+ * registry (mainly needed for archiving). */
#define GINAC_DECLARE_REGISTERED_CLASS(classname, supername) \
GINAC_DECLARE_REGISTERED_CLASS_NO_CTORS(classname, supername) \
public: \
~classname(); \
classname(const classname & other); \
const classname & operator=(const classname & other); \
+ basic * duplicate() const; \
protected: \
void copy(const classname & other); \
void destroy(bool call_parent); \
+ int compare_same_type(const basic & other) const; \
private:
#define GINAC_IMPLEMENT_REGISTERED_CLASS_NO_CTORS(classname, supername) \
registered_class_info classname::reg_info(#classname, #supername, TINFO_##classname, &classname::unarchive); \
const char *classname::class_name(void) const {return reg_info.name;}
-/** Macro for inclusion in the implementation of each registered class. */
+/** Macro for inclusion in the implementation of each registered class.
+ * It implements some functions that are the same in all classes derived
+ * from 'basic' (such as the destructor, the copy constructor and the
+ * assignment operator). */
#define GINAC_IMPLEMENT_REGISTERED_CLASS(classname, supername) \
GINAC_IMPLEMENT_REGISTERED_CLASS_NO_CTORS(classname, supername) \
classname::~classname() \
copy(other); \
} \
return *this; \
+} \
+basic * classname::duplicate() const \
+{ \
+ debugmsg(#classname " duplicate", LOGLEVEL_DUPLICATE); \
+ return new classname(*this); \
}
+
/** Find TINFO_* key by class name. */
extern unsigned int find_tinfo_key(const std::string &class_name);
// public
-basic * relational::duplicate() const
-{
- debugmsg("relational duplicate",LOGLEVEL_DUPLICATE);
- return new relational(*this);
-}
-
void relational::print(std::ostream & os, unsigned upper_precedence) const
{
debugmsg("relational print",LOGLEVEL_PRINT);
// functions overriding virtual functions from bases classes
public:
- basic * duplicate() const;
void print(std::ostream & os, unsigned upper_precedence=0) const;
void printraw(std::ostream & os) const;
void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence=0) const;
ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
ex simplify_ncmul(const exvector & v) const;
protected:
- int compare_same_type(const basic & other) const;
unsigned return_type(void) const;
unsigned return_type_tinfo(void) const;
// public
-basic * simp_lor::duplicate() const
-{
- debugmsg("simp_lor duplicate",LOGLEVEL_DUPLICATE);
- return new simp_lor(*this);
-}
-
void simp_lor::printraw(std::ostream & os) const
{
debugmsg("simp_lor printraw",LOGLEVEL_PRINT);
// functions overriding virtual functions from base classes
public:
- basic * duplicate() const;
void printraw(std::ostream & os) const;
void printtree(std::ostream & os, unsigned indent) const;
void print(std::ostream & os, unsigned upper_precedence=0) const;
bool info(unsigned inf) const;
ex eval(int level=0) const;
protected:
- int compare_same_type(const basic & other) const;
bool is_equal_same_type(const basic & other) const;
unsigned return_type(void) const;
unsigned return_type_tinfo(void) const;
// public
-basic * structure::duplicate() const
-{
- debugmsg("structure duplicate",LOGLEVEL_DUPLICATE);
- return new structure(*this);
-}
-
void structure::printraw(std::ostream & os) const
{
debugmsg("structure printraw",LOGLEVEL_PRINT);
// functions overriding virtual functions from bases classes
public:
- basic * duplicate() const;
void printraw(std::ostream & os) const;
void print(std::ostream & os, unsigned upper_precedence=0) const;
void printtree(std::ostream & os, unsigned indent) const;
void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence=0) const;
protected:
- int compare_same_type(const basic & other) const;
bool is_equal_same_type(const basic & other) const;
// new virtual functions which can be overridden by derived classes