]> www.ginac.de Git - ginac.git/blob - ginac/structure.cpp
- more indentation fixes
[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(false);
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(true);
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(std::ostream & os) const
97 {
98         debugmsg("structure printraw",LOGLEVEL_PRINT);
99
100         os << "structure(hash=" << hashvalue << ",flags=" << flags << ")";
101 }
102
103 void structure::print(std::ostream & os, unsigned upper_precedence) const
104 {
105         debugmsg("structure print",LOGLEVEL_PRINT);
106
107         os << "structure()";
108 }
109
110 void structure::printtree(std::ostream & os, unsigned indent) const
111 {
112         debugmsg("structure printtree",LOGLEVEL_PRINT);
113
114         os << std::string(indent,' ') << "structure "
115            << "hash=" << hashvalue
116            << " (0x" << std::hex << hashvalue << std::dec << ")"
117            << ", flags=" << flags << std::endl;
118 }
119
120 void structure::printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence) const
121 {
122         debugmsg("structure print csrc",LOGLEVEL_PRINT);
123
124         os << "structure()";
125 }
126
127 // protected
128
129 int structure::compare_same_type(const basic & other) const
130 {
131         GINAC_ASSERT(is_of_type(other, structure));
132         return 0; // all structures are the same
133 }
134
135 bool structure::is_equal_same_type(const basic & other) const
136 {
137         GINAC_ASSERT(is_of_type(other, structure));
138         return true; // all structures are the same
139 }
140
141 //////////
142 // new virtual structures which can be overridden by derived classes
143 //////////
144
145 // none
146
147 //////////
148 // non-virtual structures in this class
149 //////////
150
151 // protected
152
153 std::vector<registered_structure_info> & structure::registered_structures(void)
154 {
155         static std::vector<registered_structure_info> * rs = new std::vector<registered_structure_info>;
156         return *rs;
157 }
158
159 // public
160
161 unsigned structure::register_new(const char * nm)
162 {
163         registered_structure_info rsi={nm};
164         registered_structures().push_back(rsi);
165         return registered_structures().size()-1;
166 }
167
168 //////////
169 // static member variables
170 //////////
171
172 // none
173
174 //////////
175 // global constants
176 //////////
177
178 const structure some_structure;
179 const type_info & typeid_structure=typeid(some_structure);
180
181 #ifndef NO_NAMESPACE_GINAC
182 } // namespace GiNaC
183 #endif // ndef NO_NAMESPACE_GINAC