]> www.ginac.de Git - ginac.git/blob - ginac/registrar.h
fixes for gcc 3.4
[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-2003 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 #include <list>
28
29 namespace GiNaC {
30
31 class registered_class_info;
32 class ex;
33 class archive_node;
34
35 template <template <class> class> class container;
36 typedef container<std::list> lst;
37
38
39 /** Unarchiving function (static member function of every GiNaC class). */
40 typedef ex (*unarch_func)(const archive_node &n, lst &sym_lst);
41
42
43 /** Head of list of all registered_class_info structures. */
44 extern registered_class_info *first_registered_class;
45
46
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)
51         {
52                 // Add structure to list
53                 next = first_registered_class;
54                 first_registered_class = this;
55         }
56
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. */
62 };
63
64
65 /** Primary macro for inclusion in the declaration of each registered class. */
66 #define GINAC_DECLARE_REGISTERED_CLASS_NO_CTORS(classname, supername) \
67 public: \
68         typedef supername inherited; \
69         \
70         static GiNaC::registered_class_info reg_info; \
71         virtual const char *class_name() const; \
72         \
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); \
76         \
77         class visitor { \
78         public: \
79                 virtual void visit(const classname &) = 0; \
80         };
81
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) \
88 public: \
89         classname(); \
90         classname * duplicate() const { return new classname(*this); } \
91         \
92         void accept(GiNaC::visitor & v) const \
93         { \
94                 if (visitor *p = dynamic_cast<visitor *>(&v)) \
95                         p->visit(*this); \
96                 else \
97                         inherited::accept(v); \
98         } \
99 protected: \
100         int compare_same_type(const GiNaC::basic & other) const; \
101 private:
102
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
105  *  'basic'. */
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;}
109
110
111 /** Find TINFO_* key by class name. */
112 extern unsigned int find_tinfo_key(const std::string &class_name);
113
114 /** Find unarchiving function by class name. */
115 extern unarch_func find_unarch_func(const std::string &class_name);
116
117
118 } // namespace GiNaC
119
120 #endif // ndef __GINAC_REGISTRAR_H__