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__
30 class registered_class_info;
36 /** Unarchiving function (static member function of every GiNaC class). */
37 typedef ex (*unarch_func)(const archive_node &n, const lst &sym_lst);
40 /** Head of list of all registered_class_info structures. */
41 extern registered_class_info *first_registered_class;
44 /** This structure stores information about a registered GiNaC class. */
45 struct registered_class_info {
46 registered_class_info(const char *n, const char *s, unsigned int k, unarch_func f)
47 : name(n), super(s), tinfo_key(k), unarchive(f)
49 // Add structure to list
50 next = first_registered_class;
51 first_registered_class = this;
54 registered_class_info *next; /**< Pointer to next registered_class_info in list. */
55 const char *name; /**< Class name. */
56 const char *super; /**< Name of superclass. */
57 unsigned int tinfo_key; /**< TINFO_* key. */
58 unarch_func unarchive; /**< Pointer to unarchiving function. */
62 /** Primary macro for inclusion in the implementation of each registered class. */
63 #define GINAC_DECLARE_REGISTERED_CLASS_NO_CTORS(classname, supername) \
65 typedef supername inherited; \
66 static registered_class_info reg_info; \
67 virtual const char *class_name(void) const; \
68 classname(const archive_node &n, const lst &sym_lst); \
69 virtual void archive(archive_node &n) const; \
70 static ex unarchive(const archive_node &n, const lst &sym_lst);
72 /** Macro for inclusion in the declaration of each registered class.
73 * It declares some functions that are common to all classes derived
74 * from 'basic' as well as all required stuff for the GiNaC class
75 * registry (mainly needed for archiving). */
76 #define GINAC_DECLARE_REGISTERED_CLASS(classname, supername) \
77 GINAC_DECLARE_REGISTERED_CLASS_NO_CTORS(classname, supername) \
80 ~classname() { /*debugmsg(#classname " dtor", LOGLEVEL_DESTRUCT);*/ destroy(false); } \
81 classname(const classname & other); \
82 const classname & operator=(const classname & other); \
83 basic * duplicate() const; \
85 void copy(const classname & other); \
86 void destroy(bool call_parent); \
87 int compare_same_type(const basic & other) const; \
90 /** Primary macro for inclusion in the implementation of each registered class. */
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 assignment operator). */
98 #define GINAC_IMPLEMENT_REGISTERED_CLASS(classname, supername) \
99 GINAC_IMPLEMENT_REGISTERED_CLASS_NO_CTORS(classname, supername) \
100 classname::classname(const classname & other) \
102 /*debugmsg(#classname " copy ctor", LOGLEVEL_CONSTRUCT);*/ \
105 const classname & classname::operator=(const classname & other) \
107 /*debugmsg(#classname " operator=", LOGLEVEL_ASSIGNMENT);*/ \
108 if (this != &other) { \
114 basic * classname::duplicate() const { \
115 /*debugmsg(#classname " duplicate", LOGLEVEL_DUPLICATE);*/ \
116 return new classname(*this); \
120 /** Find TINFO_* key by class name. */
121 extern unsigned int find_tinfo_key(const std::string &class_name);
123 /** Find unarchiving function by class name. */
124 extern unarch_func find_unarch_func(const std::string &class_name);
129 #endif // ndef __GINAC_REGISTRAR_H__