// 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 expand(unsigned options=0) const;
ex eval(int level=0) const;
ex evalf(int level=0) const;
public:
static unsigned register_new(function_options const & opt);
static unsigned find_function(const std::string &name, unsigned nparams);
- unsigned getserial(void) const {return serial;}
+ unsigned get_serial(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;
+ (is_ex_exactly_of_type(OBJ, function) && static_cast<GiNaC::function *>(OBJ.bp)->get_serial() == function_index_##FUNCNAME)
} // namespace GiNaC
#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
+void function::print(const print_context & c, unsigned level) const
{
- debugmsg("function printraw",LOGLEVEL_PRINT);
+ debugmsg("function print", LOGLEVEL_PRINT);
GINAC_ASSERT(serial<registered_functions().size());
- os << "function(name=" << registered_functions()[serial].name;
- for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
- os << ",";
- (*it).bp->print(os);
+ 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 << ")";
+
+ } else {
+ c.s << registered_functions()[serial].name;
+ printseq(c, '(', ',', ')', exprseq::precedence, function::precedence);
}
- os << ")";
}
-void function::print(std::ostream & os, unsigned upper_precedence) const
+ex function::expand(unsigned options) const
{
- debugmsg("function print",LOGLEVEL_PRINT);
-
- GINAC_ASSERT(serial<registered_functions().size());
-
- os << registered_functions()[serial].name;
- printseq(os,'(',',',')',exprseq::precedence,function::precedence);
+ return this->setflag(status_flags::expanded);
}
-void function::printtree(std::ostream & os, unsigned indent) const
+int function::degree(const ex & s) const
{
- debugmsg("function printtree",LOGLEVEL_PRINT);
-
- GINAC_ASSERT(serial<registered_functions().size());
-
- os << std::string(indent,' ') << "function "
- << 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;
+ return is_equal(*s.bp) ? 1 : 0;
}
-void function::printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence) const
+int function::ldegree(const ex & s) const
{
- debugmsg("function print csrc",LOGLEVEL_PRINT);
-
- GINAC_ASSERT(serial<registered_functions().size());
-
- // 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 << ",";
- }
- os << ")";
+ return is_equal(*s.bp) ? 1 : 0;
}
-ex function::expand(unsigned options) const
+ex function::coeff(const ex & s, int n) const
{
- return this->setflag(status_flags::expanded);
+ if (is_equal(*s.bp))
+ return n==1 ? _ex1() : _ex0();
+ else
+ return n==0 ? ex(*this) : _ex0();
}
ex function::eval(int level) const
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