]> www.ginac.de Git - ginac.git/blob - ginac/structure.cpp
- added spec file
[ginac.git] / ginac / structure.cpp
1 /** @file structure.cpp
2  *
3  *  Implementation of 'abstract' class structure.
4  *
5  *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <string>
23
24 #include "structure.h"
25
26 //////////
27 // default constructor, destructor, copy constructor assignment operator and helpers
28 //////////
29
30 // public
31
32 structure::structure()
33 {
34     debugmsg("structure default constructor",LOGLEVEL_CONSTRUCT);
35     tinfo_key = TINFO_structure;
36 }
37
38 structure::~structure()
39 {
40     debugmsg("structure destructor",LOGLEVEL_DESTRUCT);
41     destroy(0);
42 }
43
44 structure::structure(structure const & other)
45 {
46     debugmsg("structure copy constructor",LOGLEVEL_CONSTRUCT);
47     copy(other);
48 }
49
50 structure const & structure::operator=(structure const & other)
51 {
52     debugmsg("structure operator=",LOGLEVEL_ASSIGNMENT);
53     if (this != &other) {
54         destroy(1);
55         copy(other);
56     }
57     return *this;
58 }
59
60 // protected
61
62 void structure::copy(structure const & other)
63 {
64     basic::copy(other);
65 }
66
67 void structure::destroy(bool call_parent)
68 {
69     if (call_parent) basic::destroy(call_parent);
70 }
71
72 //////////
73 // other constructors
74 //////////
75
76 // none
77
78 //////////
79 // structures overriding virtual structures from bases classes
80 //////////
81
82 // public
83
84 basic * structure::duplicate() const
85 {
86     debugmsg("structure duplicate",LOGLEVEL_DUPLICATE);
87     return new structure(*this);
88 }
89
90 void structure::printraw(ostream & os) const
91 {
92     debugmsg("structure printraw",LOGLEVEL_PRINT);
93
94     os << "structure(hash=" << hashvalue << ",flags=" << flags << ")";
95 }
96
97 void structure::print(ostream & os, unsigned upper_precedence) const
98 {
99     debugmsg("structure print",LOGLEVEL_PRINT);
100
101     os << "structure()";
102 }
103
104 void structure::printtree(ostream & os, unsigned indent) const
105 {
106     debugmsg("structure printtree",LOGLEVEL_PRINT);
107
108     os << string(indent,' ') << "structure "
109        << "hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
110        << ", flags=" << flags << endl;
111 }
112
113 void structure::printcsrc(ostream & os, unsigned type, unsigned upper_precedence) const
114 {
115     debugmsg("structure print csrc",LOGLEVEL_PRINT);
116
117     os << "structure()";
118 }
119
120 // protected
121
122 int structure::compare_same_type(basic const & other) const
123 {
124     ASSERT(is_of_type(other, structure));
125     return 0; // all structures are the same
126 }
127
128 bool structure::is_equal_same_type(basic const & other) const
129 {
130     ASSERT(is_of_type(other, structure));
131     return true; // all structures are the same
132 }
133
134 //////////
135 // new virtual structures which can be overridden by derived classes
136 //////////
137
138 // none
139
140 //////////
141 // non-virtual structures in this class
142 //////////
143
144 // protected
145
146 vector<registered_structure_info> & structure::registered_structures(void)
147 {
148     static vector<registered_structure_info> * rs=new vector<registered_structure_info>;
149     return *rs;
150 }
151
152 // public
153
154 unsigned structure::register_new(char const * nm)
155 {
156     registered_structure_info rsi={nm};
157     registered_structures().push_back(rsi);
158     return registered_structures().size()-1;
159 }
160
161 //////////
162 // static member variables
163 //////////
164
165 // none
166
167 //////////
168 // global constants
169 //////////
170
171 const structure some_structure;
172 type_info const & typeid_structure=typeid(some_structure);
173