3 * GiNaC's class registrar (for class basic and all classes derived from it). */
6 * GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #ifndef __GINAC_REGISTRAR_H__
24 #define __GINAC_REGISTRAR_H__
29 #include "class_info.h"
36 template <template <class> class> class container;
37 typedef container<std::list> lst;
40 /** Unarchiving function (static member function of every GiNaC class). */
41 typedef ex (*unarch_func)(const archive_node &n, lst &sym_lst);
44 /** This structure stores information about a registered GiNaC class. */
45 class registered_class_options {
47 registered_class_options(const char *n, const char *p, unsigned ti, unarch_func f)
48 : name(n), parent_name(p), tinfo_key(ti), unarchive(f) {}
50 const char *get_name() const { return name; }
51 const char *get_parent_name() const { return parent_name; }
52 unsigned get_id() const { return tinfo_key; }
53 unarch_func get_unarch_func() const { return unarchive; }
56 const char *name; /**< Class name. */
57 const char *parent_name; /**< Name of superclass. */
58 unsigned tinfo_key; /**< TINFO_* key. */
59 unarch_func unarchive; /**< Pointer to unarchiving function. */
62 typedef class_info<registered_class_options> registered_class_info;
65 /** Primary macro for inclusion in the declaration of each registered class. */
66 #define GINAC_DECLARE_REGISTERED_CLASS_NO_CTORS(classname, supername) \
68 typedef supername inherited; \
69 template <class isexaclass> friend bool is_exactly_a(const GiNaC::basic &obj); \
71 static GiNaC::registered_class_info reg_info; \
73 virtual const GiNaC::registered_class_info &get_class_info() const { return reg_info; } \
74 virtual const char *class_name() const { return reg_info.options.get_name(); } \
76 classname(const GiNaC::archive_node &n, GiNaC::lst &sym_lst); \
77 virtual void archive(GiNaC::archive_node &n) const; \
78 static GiNaC::ex unarchive(const GiNaC::archive_node &n, GiNaC::lst &sym_lst); \
82 virtual void visit(const classname &) = 0; \
85 /** Macro for inclusion in the declaration of each registered class.
86 * It declares some functions that are common to all classes derived
87 * from 'basic' as well as all required stuff for the GiNaC class
88 * registry (mainly needed for archiving). */
89 #define GINAC_DECLARE_REGISTERED_CLASS(classname, supername) \
90 GINAC_DECLARE_REGISTERED_CLASS_NO_CTORS(classname, supername) \
93 classname * duplicate() const { return new classname(*this); } \
95 void accept(GiNaC::visitor & v) const \
97 if (visitor *p = dynamic_cast<visitor *>(&v)) \
100 inherited::accept(v); \
103 int compare_same_type(const GiNaC::basic & other) const; \
106 /** Macro for inclusion in the implementation of each registered class. */
107 #define GINAC_IMPLEMENT_REGISTERED_CLASS(classname, supername) \
108 GiNaC::registered_class_info classname::reg_info = GiNaC::registered_class_info(GiNaC::registered_class_options(#classname, #supername, TINFO_##classname, &classname::unarchive));
110 /** Macro for inclusion in the implementation of each registered class.
111 * Additional options can be specified. */
112 #define GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(classname, supername, options) \
113 GiNaC::registered_class_info classname::reg_info = GiNaC::registered_class_info(GiNaC::registered_class_options(#classname, #supername, TINFO_##classname, &classname::unarchive).options);
116 /** Find TINFO_* key by class name. */
117 extern unsigned find_tinfo_key(const std::string &class_name);
119 /** Find unarchiving function by class name. */
120 extern unarch_func find_unarch_func(const std::string &class_name);
125 #endif // ndef __GINAC_REGISTRAR_H__