3 * GiNaC's class registrar (for class basic and all classes derived from it). */
6 * GiNaC Copyright (C) 1999-2001 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__
28 #ifndef NO_NAMESPACE_GINAC
30 #endif // ndef NO_NAMESPACE_GINAC
32 class registered_class_info;
38 /** Unarchiving function (static member function of every GiNaC class). */
39 typedef ex (*unarch_func)(const archive_node &n, const lst &sym_lst);
42 /** Head of list of all registered_class_info structures. */
43 extern registered_class_info *first_registered_class;
46 /** This structure stores information about a registered GiNaC class. */
47 struct registered_class_info {
48 registered_class_info(const char *n, const char *s, unsigned int k, unarch_func f)
49 : name(n), super(s), tinfo_key(k), unarchive(f)
51 // Add structure to list
52 next = first_registered_class;
53 first_registered_class = this;
56 registered_class_info *next; /**< Pointer to next registered_class_info in list. */
57 const char *name; /**< Class name. */
58 const char *super; /**< Name of superclass. */
59 unsigned int tinfo_key; /**< TINFO_* key. */
60 unarch_func unarchive; /**< Pointer to unarchiving function. */
64 #define GINAC_DECLARE_REGISTERED_CLASS_NO_CTORS(classname, supername) \
66 typedef supername inherited; \
67 static registered_class_info reg_info; \
68 virtual const char *class_name(void) const; \
69 classname(const archive_node &n, const lst &sym_lst); \
70 virtual void archive(archive_node &n) const; \
71 static ex unarchive(const archive_node &n, const lst &sym_lst);
73 /** Macro for inclusion in the declaration of each registered class.
74 * It declares some functions that are common to all classes derived
75 * from 'basic' as well as all required stuff for the GiNaC class
76 * registry (mainly needed for archiving). */
77 #define GINAC_DECLARE_REGISTERED_CLASS(classname, supername) \
78 GINAC_DECLARE_REGISTERED_CLASS_NO_CTORS(classname, supername) \
82 classname(const classname & other); \
83 const classname & operator=(const classname & other); \
84 basic * duplicate() const; \
86 void copy(const classname & other); \
87 void destroy(bool call_parent); \
88 int compare_same_type(const basic & other) const; \
91 #define GINAC_IMPLEMENT_REGISTERED_CLASS_NO_CTORS(classname, supername) \
92 registered_class_info classname::reg_info(#classname, #supername, TINFO_##classname, &classname::unarchive); \
93 const char *classname::class_name(void) const {return reg_info.name;}
95 /** Macro for inclusion in the implementation of each registered class.
96 * It implements some functions that are the same in all classes derived
97 * from 'basic' (such as the destructor, the copy constructor and the
98 * assignment operator). */
99 #define GINAC_IMPLEMENT_REGISTERED_CLASS(classname, supername) \
100 GINAC_IMPLEMENT_REGISTERED_CLASS_NO_CTORS(classname, supername) \
101 classname::~classname() \
103 debugmsg(#classname " destructor", LOGLEVEL_DESTRUCT); \
106 classname::classname(const classname & other) \
108 debugmsg(#classname " copy constructor", LOGLEVEL_CONSTRUCT); \
111 const classname & classname::operator=(const classname & other) \
113 debugmsg(#classname " operator=", LOGLEVEL_ASSIGNMENT); \
114 if (this != &other) { \
120 basic * classname::duplicate() const \
122 debugmsg(#classname " duplicate", LOGLEVEL_DUPLICATE); \
123 return new classname(*this); \
127 /** Find TINFO_* key by class name. */
128 extern unsigned int find_tinfo_key(const std::string &class_name);
130 /** Find unarchiving function by class name. */
131 extern unarch_func find_unarch_func(const std::string &class_name);
134 #ifndef NO_NAMESPACE_GINAC
136 #endif // ndef NO_NAMESPACE_GINAC
138 #endif // ndef __GINAC_REGISTRAR_H__