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 /** Macro for inclusion in the declaration of each registered class. */
65 #define GINAC_DECLARE_REGISTERED_CLASS(classname, supername) \
67 typedef supername inherited; \
68 static registered_class_info reg_info; \
69 virtual const char *class_name(void) const; \
70 classname(const archive_node &n, const lst &sym_lst); \
71 virtual void archive(archive_node &n) const; \
72 static ex unarchive(const archive_node &n, const lst &sym_lst); \
75 /** Macro for inclusion in the implementation of each registered class. */
76 #define GINAC_IMPLEMENT_REGISTERED_CLASS(classname, supername) \
77 registered_class_info classname::reg_info(#classname, #supername, TINFO_##classname, &classname::unarchive); \
78 const char *classname::class_name(void) const {return reg_info.name;}
81 /** Find TINFO_* key by class name. */
82 extern unsigned int find_tinfo_key(const std::string &class_name);
84 /** Find unarchiving function by class name. */
85 extern unarch_func find_unarch_func(const std::string &class_name);
88 #ifndef NO_NAMESPACE_GINAC
90 #endif // ndef NO_NAMESPACE_GINAC
92 #endif // ndef __GINAC_REGISTRAR_H__