]> www.ginac.de Git - ginac.git/blob - ginac/registrar.h
- inline int csgn(const numeric &): fixed a typo.
[ginac.git] / ginac / registrar.h
1 /** @file registrar.h
2  *
3  *  GiNaC's class registrar (for class basic and all classes derived from it). */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #ifndef __GINAC_REGISTRAR_H__
24 #define __GINAC_REGISTRAR_H__
25
26 #include <string>
27
28 #ifndef NO_NAMESPACE_GINAC
29 namespace GiNaC {
30 #endif // ndef NO_NAMESPACE_GINAC
31
32 class registered_class_info;
33 class ex;
34 class archive_node;
35 class lst;
36
37
38 /** Unarchiving function (static member function of every GiNaC class). */
39 typedef ex (*unarch_func)(const archive_node &n, const lst &sym_lst);
40
41
42 /** Head of list of all registered_class_info structures. */
43 extern registered_class_info *first_registered_class;
44
45
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)
50     {
51         // Add structure to list
52         next = first_registered_class;
53         first_registered_class = this;
54     }
55
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. */
61 };
62
63
64 /** Macro for inclusion in the declaration of each registered class. */
65 #define GINAC_DECLARE_REGISTERED_CLASS(classname, supername) \
66 public: \
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); \
73 private:
74
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;}
79
80
81 /** Find TINFO_* key by class name. */
82 extern unsigned int find_tinfo_key(const string &class_name);
83
84 /** Find unarchiving function by class name. */
85 extern unarch_func find_unarch_func(const string &class_name);
86
87
88 #ifndef NO_NAMESPACE_GINAC
89 } // namespace GiNaC
90 #endif // ndef NO_NAMESPACE_GINAC
91
92 #endif // ndef __GINAC_REGISTRAR_H__