]> www.ginac.de Git - ginac.git/blobdiff - ginac/basic.h
location of C++ FAQ Lite has changed
[ginac.git] / ginac / basic.h
index a68c2eee0411dba6f5dca043789c55eef099bd18..d50c7ca34eb73d916e9f93fb2c38d3d28e0a71e6 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <cstddef> // for size_t
 #include <vector>
+#include <map>
 // CINT needs <algorithm> to work properly with <vector>
 #include <algorithm>
 
@@ -45,6 +46,7 @@ class print_context;
 template <class> class ptr;
 
 typedef std::vector<ex> exvector;
+typedef std::map<ex, ex, ex_is_less> exmap;
 
 
 /** Function object for map(). */
@@ -135,7 +137,7 @@ protected:
 public:
 
        // substitutions
-       virtual ex subs(const lst & ls, const lst & lr, unsigned options = 0) const;
+       virtual ex subs(const exmap & m, unsigned options = 0) const;
 
        // function mapping
        virtual ex map(map_function & f) const;
@@ -163,7 +165,7 @@ public:
        virtual ex series(const relational & r, int order, unsigned options = 0) const;
 
        // rational functions
-       virtual ex normal(lst &sym_lst, lst &repl_lst, int level = 0) const;
+       virtual ex normal(exmap & repl, exmap & rev_lookup, int level = 0) const;
        virtual ex to_rational(lst &repl_lst) const;
        virtual ex to_polynomial(lst &repl_lst) const;
 
@@ -190,8 +192,20 @@ protected: // functions that should be called from class ex only
        
        // non-virtual functions in this class
 public:
-       ex subs(const ex & e, unsigned options = 0) const;
-       ex subs_one_level(const lst & ls, const lst & lr, unsigned options) const;
+       /** Like print(), but dispatch to the specified class. Can be used by
+        *  implementations of print methods to dispatch to the method of the
+        *  superclass.
+        *
+        *  @see basic::print */
+       template <class T>
+       void print_dispatch(const print_context & c, unsigned level) const
+       {
+               print_dispatch(T::get_class_info_static(), c, level);
+       }
+
+       void print_dispatch(const registered_class_info & ri, const print_context & c, unsigned level) const;
+
+       ex subs_one_level(const exmap & m, unsigned options) const;
        ex diff(const symbol & s, unsigned nth = 1) const;
        int compare(const basic & other) const;
        bool is_equal(const basic & other) const;
@@ -207,6 +221,10 @@ public:
 
 protected:
        void ensure_if_modifiable() const;
+
+       void do_print(const print_context & c, unsigned level) const;
+       void do_print_tree(const print_tree & c, unsigned level) const;
+       void do_print_python_repr(const print_python_repr & c, unsigned level) const;
        
        // member variables
 protected:
@@ -236,38 +254,9 @@ inline bool is_a(const basic &obj)
  *  inefficient default.  It should in all time-critical cases be overridden
  *  by template specializations that use the TINFO_* constants directly. */
 template <class T>
-inline bool is_exactly_a(const class basic &obj)
-{
-       return obj.tinfo() == T::reg_info.tinfo_key;
-}
-
-/** Check if ex is a handle to a T, including base classes. */
-template <class T>
-inline bool is_a(const ex &obj)
-{
-       return is_a<T>(*obj.bp);
-}
-
-/** Check if ex is a handle to a T, not including base classes. */
-template <class T>
-inline bool is_exactly_a(const ex &obj)
-{
-       return is_exactly_a<T>(*obj.bp);
-}
-
-/** Return a reference to the basic-derived class T object embedded in an
- *  expression.  This is fast but unsafe: the result is undefined if the
- *  expression does not contain a T object at its top level.  Hence, you
- *  should generally check the type of e first.
- *
- *  @param e expression
- *  @return reference to pseries object
- *  @see is_exactly_a<class T>() */
-template <class T>
-inline const T &ex_to(const ex &e)
+inline bool is_exactly_a(const basic &obj)
 {
-       GINAC_ASSERT(is_a<T>(e));
-       return static_cast<const T &>(*e.bp);
+       return obj.tinfo() == T::get_class_info_static().options.get_id();
 }
 
 } // namespace GiNaC