// functions overriding virtual functions from bases classes
public:
- 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;
+ void print(const print_context & c, unsigned level = 0) const;
int degree(const ex & s) const;
int ldegree(const ex & s) const;
ex coeff(const ex & s, int n = 1) const;
ex evalf(int level=0) const;
unsigned calchash(void) const;
ex series(const relational & r, int order, unsigned options = 0) const;
- ex subs(const lst & ls, const lst & lr) const;
ex thisexprseq(const exvector & v) const;
ex thisexprseq(exvector * vp) const;
protected:
static unsigned register_new(function_options const & opt);
static unsigned find_function(const std::string &name, unsigned nparams);
unsigned getserial(void) const {return serial;}
+ std::string get_name(void) const;
// member variables
#define is_ex_the_function(OBJ, FUNCNAME) \\
(is_ex_exactly_of_type(OBJ, function) && static_cast<GiNaC::function *>(OBJ.bp)->getserial() == function_index_##FUNCNAME)
-// global constants
-
-extern const function some_function;
-extern const std::type_info & typeid_function;
-
} // namespace GiNaC
#endif // ndef __GINAC_FUNCTION_H__
#include "function.h"
#include "ex.h"
#include "lst.h"
+#include "print.h"
#include "archive.h"
#include "inifcns.h"
#include "utils.h"
// public
-void function::printraw(std::ostream & os) const
-{
- debugmsg("function printraw",LOGLEVEL_PRINT);
-
- GINAC_ASSERT(serial<registered_functions().size());
-
- os << class_name() << "(name=" << registered_functions()[serial].name;
- for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
- os << ",";
- (*it).bp->print(os);
- }
- os << ")";
-}
-
-void function::print(std::ostream & os, unsigned upper_precedence) const
-{
- debugmsg("function print",LOGLEVEL_PRINT);
-
- GINAC_ASSERT(serial<registered_functions().size());
-
- os << registered_functions()[serial].name;
- printseq(os,'(',',',')',exprseq::precedence,function::precedence);
-}
-
-void function::printtree(std::ostream & os, unsigned indent) const
+void function::print(const print_context & c, unsigned level) const
{
- debugmsg("function printtree",LOGLEVEL_PRINT);
+ debugmsg("function print", LOGLEVEL_PRINT);
GINAC_ASSERT(serial<registered_functions().size());
- os << std::string(indent,' ') << class_name() << " "
- << registered_functions()[serial].name
- << ", hash=" << hashvalue
- << " (0x" << std::hex << hashvalue << std::dec << ")"
- << ", flags=" << flags
- << ", nops=" << nops() << std::endl;
- for (unsigned i=0; i<nops(); ++i) {
- seq[i].printtree(os,indent+delta_indent);
- }
- os << std::string(indent+delta_indent,' ') << "=====" << std::endl;
-}
-
-void function::printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence) const
-{
- debugmsg("function print csrc",LOGLEVEL_PRINT);
-
- GINAC_ASSERT(serial<registered_functions().size());
+ if (is_of_type(c, print_tree)) {
+
+ c.s << std::string(level, ' ') << class_name() << " "
+ << registered_functions()[serial].name
+ << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
+ << ", nops=" << nops()
+ << std::endl;
+ unsigned delta_indent = static_cast<const print_tree &>(c).delta_indent;
+ for (unsigned i=0; i<nops(); ++i)
+ seq[i].print(c, level + delta_indent);
+ c.s << std::string(level + delta_indent, ' ') << "=====" << std::endl;
+
+ } else if (is_of_type(c, print_csrc)) {
+
+ // Print function name in lowercase
+ std::string lname = registered_functions()[serial].name;
+ for (unsigned i=0; i<lname.size(); i++)
+ lname[i] = tolower(lname[i]);
+ c.s << lname << "(";
+
+ // Print arguments, separated by commas
+ exvector::const_iterator it = seq.begin(), itend = seq.end();
+ while (it != itend) {
+ it->print(c);
+ it++;
+ if (it != itend)
+ c.s << ",";
+ }
+ c.s << ")";
- // Print function name in lowercase
- std::string lname;
- lname=registered_functions()[serial].name;
- for (unsigned i=0; i<lname.size(); i++)
- lname[i] = tolower(lname[i]);
- os << lname << "(";
-
- // Print arguments, separated by commas
- exvector::const_iterator it = seq.begin();
- exvector::const_iterator itend = seq.end();
- while (it != itend) {
- it->bp->printcsrc(os, type, 0);
- it++;
- if (it != itend)
- os << ",";
+ } else {
+ c.s << registered_functions()[serial].name;
+ printseq(c, '(', ',', ')', exprseq::precedence, function::precedence);
}
- os << ")";
}
ex function::expand(unsigned options) const
throw(std::logic_error("function::series(): invalid nparams"));
}
-ex function::subs(const lst & ls, const lst & lr) const
-{
- GINAC_ASSERT(ls.nops() == lr.nops());
-
- for (unsigned i=0; i<ls.nops(); i++) {
- if (is_ex_of_type(ls.op(i), function) &&
- compare_same_type(ex_to_function(ls.op(i)))==0)
- return lr.op(i);
- }
-
- return inherited::subs(ls, lr);
-}
-
// protected
throw (std::runtime_error("no function '" + name + "' with " + ToString(nparams) + " parameters defined"));
}
-//////////
-// static member variables
-//////////
-
-// none
-
-//////////
-// global constants
-//////////
-
-const function some_function;
-const std::type_info & typeid_function=typeid(some_function);
+/** Return the print name of the function. */
+std::string function::get_name(void) const
+{
+ GINAC_ASSERT(serial<registered_functions().size());
+ return registered_functions()[serial].name;
+}
} // namespace GiNaC