]> www.ginac.de Git - ginac.git/blobdiff - ginac/registrar.h
implemented double dispatch for print(); methods are specified with
[ginac.git] / ginac / registrar.h
index e6c083f32f98f72e60824ed3f20b892ab10c6374..9610f6c0f7a7e9fcc66a41c6b3d3b024df3d4a41 100644 (file)
 
 #include <string>
 #include <list>
+#include <vector>
 
 #include "class_info.h"
+#include "print.h"
 
 namespace GiNaC {
 
@@ -41,7 +43,7 @@ typedef container<std::list> lst;
 typedef ex (*unarch_func)(const archive_node &n, lst &sym_lst);
 
 
-/** This structure stores information about a registered GiNaC class. */
+/** This class stores information about a registered GiNaC class. */
 class registered_class_options {
 public:
        registered_class_options(const char *n, const char *p, unsigned ti, unarch_func f)
@@ -51,12 +53,42 @@ public:
        const char *get_parent_name() const { return parent_name; }
        unsigned get_id() const { return tinfo_key; }
        unarch_func get_unarch_func() const { return unarchive; }
+       const std::vector<print_functor> &get_print_dispatch_table() const { return print_dispatch_table; }
+
+       template <class Ctx, class T, class C>
+       registered_class_options & print_func(void f(const T &, const C & c, unsigned))
+       {
+               set_print_func(Ctx::reg_info.options.get_id(), f);
+               return *this;
+       }
+
+       template <class Ctx, class T, class C>
+       registered_class_options & print_func(void (T::*f)(const C &, unsigned))
+       {
+               set_print_func(Ctx::reg_info.options.get_id(), f);
+               return *this;
+       }
+
+       template <class Ctx>
+       registered_class_options & print_func(const print_functor & f)
+       {
+               set_print_func(Ctx::reg_info.options.get_id(), f);
+               return *this;
+       }
 
 private:
+       void set_print_func(unsigned id, const print_functor & f)
+       {
+               if (id >= print_dispatch_table.size())
+                       print_dispatch_table.resize(id + 1);
+               print_dispatch_table[id] = f;
+       }
+
        const char *name;         /**< Class name. */
        const char *parent_name;  /**< Name of superclass. */
        unsigned tinfo_key;       /**< TINFO_* key. */
        unarch_func unarchive;    /**< Pointer to unarchiving function. */
+       std::vector<print_functor> print_dispatch_table; /**< Method table for print() dispatch */
 };
 
 typedef class_info<registered_class_options> registered_class_info;