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