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