]> www.ginac.de Git - ginac.git/blob - ginac/registrar.h
- ginac-config.1: removed (duplicate).
[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-2001 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 namespace GiNaC {
29
30 class registered_class_info;
31 class ex;
32 class archive_node;
33 class lst;
34
35
36 /** Unarchiving function (static member function of every GiNaC class). */
37 typedef ex (*unarch_func)(const archive_node &n, const lst &sym_lst);
38
39
40 /** Head of list of all registered_class_info structures. */
41 extern registered_class_info *first_registered_class;
42
43
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)
48         {
49                 // Add structure to list
50                 next = first_registered_class;
51                 first_registered_class = this;
52         }
53
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. */
59 };
60
61
62 /** Primary macro for inclusion in the implementation of each registered class. */
63 #define GINAC_DECLARE_REGISTERED_CLASS_NO_CTORS(classname, supername) \
64 public: \
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);
71
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) \
78 public: \
79         classname(); \
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; \
84 protected: \
85         void copy(const classname & other); \
86         void destroy(bool call_parent); \
87         int compare_same_type(const basic & other) const; \
88 private:
89
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;}
94
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) \
101 { \
102         /*debugmsg(#classname " copy ctor", LOGLEVEL_CONSTRUCT);*/ \
103         copy(other); \
104 } \
105 const classname & classname::operator=(const classname & other) \
106 { \
107         /*debugmsg(#classname " operator=", LOGLEVEL_ASSIGNMENT);*/ \
108         if (this != &other) { \
109                 destroy(true); \
110                 copy(other); \
111         } \
112         return *this; \
113 } \
114 basic * classname::duplicate() const { \
115         /*debugmsg(#classname " duplicate", LOGLEVEL_DUPLICATE);*/ \
116         return new classname(*this); \
117 }
118
119
120 /** Find TINFO_* key by class name. */
121 extern unsigned int find_tinfo_key(const std::string &class_name);
122
123 /** Find unarchiving function by class name. */
124 extern unarch_func find_unarch_func(const std::string &class_name);
125
126
127 } // namespace GiNaC
128
129 #endif // ndef __GINAC_REGISTRAR_H__