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__
31 class registered_class_info;
35 template <template <class> class> class container;
36 typedef container<std::list> lst;
39 /** Unarchiving function (static member function of every GiNaC class). */
40 typedef ex (*unarch_func)(const archive_node &n, lst &sym_lst);
43 /** Head of list of all registered_class_info structures. */
44 extern registered_class_info *first_registered_class;
47 /** This structure stores information about a registered GiNaC class. */
48 struct registered_class_info {
49 registered_class_info(const char *n, const char *s, unsigned int k, unarch_func f)
50 : name(n), super(s), tinfo_key(k), unarchive(f)
52 // Add structure to list
53 next = first_registered_class;
54 first_registered_class = this;
57 registered_class_info *next; /**< Pointer to next registered_class_info in list. */
58 const char *name; /**< Class name. */
59 const char *super; /**< Name of superclass. */
60 unsigned int tinfo_key; /**< TINFO_* key. */
61 unarch_func unarchive; /**< Pointer to unarchiving function. */
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; \
70 static GiNaC::registered_class_info reg_info; \
71 virtual const char *class_name() const; \
73 classname(const GiNaC::archive_node &n, GiNaC::lst &sym_lst); \
74 virtual void archive(GiNaC::archive_node &n) const; \
75 static GiNaC::ex unarchive(const GiNaC::archive_node &n, GiNaC::lst &sym_lst); \
79 virtual void visit(const classname &) = 0; \
82 /** Macro for inclusion in the declaration of each registered class.
83 * It declares some functions that are common to all classes derived
84 * from 'basic' as well as all required stuff for the GiNaC class
85 * registry (mainly needed for archiving). */
86 #define GINAC_DECLARE_REGISTERED_CLASS(classname, supername) \
87 GINAC_DECLARE_REGISTERED_CLASS_NO_CTORS(classname, supername) \
90 classname * duplicate() const { return new classname(*this); } \
92 void accept(GiNaC::visitor & v) const \
94 if (visitor *p = dynamic_cast<visitor *>(&v)) \
97 inherited::accept(v); \
100 int compare_same_type(const GiNaC::basic & other) const; \
103 /** Macro for inclusion in the implementation of each registered class.
104 * It defines some members that are the same in all classes derived from
106 #define GINAC_IMPLEMENT_REGISTERED_CLASS(classname, supername) \
107 GiNaC::registered_class_info classname::reg_info(#classname, #supername, TINFO_##classname, &classname::unarchive); \
108 const char *classname::class_name() const {return reg_info.name;}
111 /** Find TINFO_* key by class name. */
112 extern unsigned int find_tinfo_key(const std::string &class_name);
114 /** Find unarchiving function by class name. */
115 extern unarch_func find_unarch_func(const std::string &class_name);
120 #endif // ndef __GINAC_REGISTRAR_H__