]> www.ginac.de Git - ginac.git/blob - ginac/structure.cpp
- libginac.la no longer includes a dependency on libreadline
[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 #include "debugmsg.h"
27
28 namespace GiNaC {
29
30 //////////
31 // default constructor, destructor, copy constructor assignment operator and helpers
32 //////////
33
34 // public
35
36 structure::structure()
37 {
38     debugmsg("structure default constructor",LOGLEVEL_CONSTRUCT);
39     tinfo_key = TINFO_structure;
40 }
41
42 structure::~structure()
43 {
44     debugmsg("structure destructor",LOGLEVEL_DESTRUCT);
45     destroy(0);
46 }
47
48 structure::structure(structure const & other)
49 {
50     debugmsg("structure copy constructor",LOGLEVEL_CONSTRUCT);
51     copy(other);
52 }
53
54 structure const & structure::operator=(structure const & other)
55 {
56     debugmsg("structure operator=",LOGLEVEL_ASSIGNMENT);
57     if (this != &other) {
58         destroy(1);
59         copy(other);
60     }
61     return *this;
62 }
63
64 // protected
65
66 void structure::copy(structure const & other)
67 {
68     basic::copy(other);
69 }
70
71 void structure::destroy(bool call_parent)
72 {
73     if (call_parent) basic::destroy(call_parent);
74 }
75
76 //////////
77 // other constructors
78 //////////
79
80 // none
81
82 //////////
83 // structures overriding virtual structures from bases classes
84 //////////
85
86 // public
87
88 basic * structure::duplicate() const
89 {
90     debugmsg("structure duplicate",LOGLEVEL_DUPLICATE);
91     return new structure(*this);
92 }
93
94 void structure::printraw(ostream & os) const
95 {
96     debugmsg("structure printraw",LOGLEVEL_PRINT);
97
98     os << "structure(hash=" << hashvalue << ",flags=" << flags << ")";
99 }
100
101 void structure::print(ostream & os, unsigned upper_precedence) const
102 {
103     debugmsg("structure print",LOGLEVEL_PRINT);
104
105     os << "structure()";
106 }
107
108 void structure::printtree(ostream & os, unsigned indent) const
109 {
110     debugmsg("structure printtree",LOGLEVEL_PRINT);
111
112     os << string(indent,' ') << "structure "
113        << "hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
114        << ", flags=" << flags << endl;
115 }
116
117 void structure::printcsrc(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(basic const & other) const
127 {
128     ASSERT(is_of_type(other, structure));
129     return 0; // all structures are the same
130 }
131
132 bool structure::is_equal_same_type(basic const & other) const
133 {
134     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 vector<registered_structure_info> & structure::registered_structures(void)
151 {
152     static vector<registered_structure_info> * rs=new vector<registered_structure_info>;
153     return *rs;
154 }
155
156 // public
157
158 unsigned structure::register_new(char const * nm)
159 {
160     registered_structure_info rsi={nm};
161     registered_structures().push_back(rsi);
162     return registered_structures().size()-1;
163 }
164
165 //////////
166 // static member variables
167 //////////
168
169 // none
170
171 //////////
172 // global constants
173 //////////
174
175 const structure some_structure;
176 type_info const & typeid_structure=typeid(some_structure);
177
178 } // namespace GiNaC