]> www.ginac.de Git - ginac.git/blob - ginac/structure.cpp
GINAC_DECLARE_REGISTERED_CLASS declares duplicate() and compare_same_type(),
[ginac.git] / ginac / structure.cpp
1 /** @file structure.cpp
2  *
3  *  Implementation of 'abstract' class structure. */
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 #include <string>
24
25 #include "structure.h"
26 #include "archive.h"
27 #include "debugmsg.h"
28
29 #ifndef NO_NAMESPACE_GINAC
30 namespace GiNaC {
31 #endif // ndef NO_NAMESPACE_GINAC
32
33 GINAC_IMPLEMENT_REGISTERED_CLASS(structure, basic)
34
35 //////////
36 // default constructor, destructor, copy constructor assignment operator and helpers
37 //////////
38
39 // public
40
41 structure::structure()
42 {
43         debugmsg("structure default constructor",LOGLEVEL_CONSTRUCT);
44         tinfo_key = TINFO_structure;
45 }
46
47 // protected
48
49 void structure::copy(const structure & other)
50 {
51         basic::copy(other);
52 }
53
54 void structure::destroy(bool call_parent)
55 {
56         if (call_parent) basic::destroy(call_parent);
57 }
58
59 //////////
60 // other constructors
61 //////////
62
63 // none
64
65 //////////
66 // archiving
67 //////////
68
69 /** Construct object from archive_node. */
70 structure::structure(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
71 {
72         debugmsg("structure constructor from archive_node", LOGLEVEL_CONSTRUCT);
73 }
74
75 /** Unarchive the object. */
76 ex structure::unarchive(const archive_node &n, const lst &sym_lst)
77 {
78         return (new structure(n, sym_lst))->setflag(status_flags::dynallocated);
79 }
80
81 /** Archive the object. */
82 void structure::archive(archive_node &n) const
83 {
84         inherited::archive(n);
85 }
86
87 //////////
88 // structures overriding virtual structures from bases classes
89 //////////
90
91 // public
92
93 void structure::printraw(std::ostream & os) const
94 {
95         debugmsg("structure printraw",LOGLEVEL_PRINT);
96
97         os << "structure(hash=" << hashvalue << ",flags=" << flags << ")";
98 }
99
100 void structure::print(std::ostream & os, unsigned upper_precedence) const
101 {
102         debugmsg("structure print",LOGLEVEL_PRINT);
103
104         os << "structure()";
105 }
106
107 void structure::printtree(std::ostream & os, unsigned indent) const
108 {
109         debugmsg("structure printtree",LOGLEVEL_PRINT);
110
111         os << std::string(indent,' ') << "structure "
112            << "hash=" << hashvalue
113            << " (0x" << std::hex << hashvalue << std::dec << ")"
114            << ", flags=" << flags << std::endl;
115 }
116
117 void structure::printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence) const
118 {
119         debugmsg("structure print csrc",LOGLEVEL_PRINT);
120
121         os << "structure()";
122 }
123
124 // protected
125
126 int structure::compare_same_type(const basic & other) const
127 {
128         GINAC_ASSERT(is_of_type(other, structure));
129         return 0; // all structures are the same
130 }
131
132 bool structure::is_equal_same_type(const basic & other) const
133 {
134         GINAC_ASSERT(is_of_type(other, structure));
135         return true; // all structures are the same
136 }
137
138 //////////
139 // new virtual structures which can be overridden by derived classes
140 //////////
141
142 // none
143
144 //////////
145 // non-virtual structures in this class
146 //////////
147
148 // protected
149
150 std::vector<registered_structure_info> & structure::registered_structures(void)
151 {
152         static std::vector<registered_structure_info> * rs = new std::vector<registered_structure_info>;
153         return *rs;
154 }
155
156 // public
157
158 unsigned structure::register_new(const char * nm)
159 {
160         registered_structure_info rsi={nm};
161         registered_structures().push_back(rsi);
162         return registered_structures().size()-1;
163 }
164
165 #ifndef NO_NAMESPACE_GINAC
166 } // namespace GiNaC
167 #endif // ndef NO_NAMESPACE_GINAC