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