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