]> www.ginac.de Git - ginac.git/blob - ginac/structure.cpp
* power::expand_add(): allocate the precise amount needed for representing
[ginac.git] / ginac / structure.cpp
1 /** @file structure.cpp
2  *
3  *  Implementation of 'abstract' class structure. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2002 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 <iostream>
24 #include <string>
25
26 #include "structure.h"
27 #include "archive.h"
28 #include "utils.h"
29 #include "print.h"
30
31 namespace GiNaC {
32
33 GINAC_IMPLEMENT_REGISTERED_CLASS(structure, basic)
34
35 //////////
36 // default ctor, dtor, copy ctor, assignment operator and helpers
37 //////////
38
39 DEFAULT_CTORS(structure)
40
41 //////////
42 // archiving
43 //////////
44
45 DEFAULT_ARCHIVING(structure)
46
47 //////////
48 // functions overriding virtual functions from base classes
49 //////////
50
51 void structure::print(const print_context & c, unsigned level) const
52 {
53         if (is_a<print_tree>(c)) {
54
55                 c.s << std::string(level, ' ') << class_name()
56                     << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
57                     << std::endl;
58
59         } else
60                 c.s << class_name() << "()";
61 }
62
63 // protected
64
65 DEFAULT_COMPARE(structure)
66
67 bool structure::is_equal_same_type(const basic & other) const
68 {
69         GINAC_ASSERT(is_a<structure>(other));
70         return true; // all structures are the same
71 }
72
73 //////////
74 // non-virtual functions in this class
75 //////////
76
77 // protected
78
79 std::vector<registered_structure_info> & structure::registered_structures(void)
80 {
81         static std::vector<registered_structure_info> * rs = new std::vector<registered_structure_info>;
82         return *rs;
83 }
84
85 // public
86
87 unsigned structure::register_new(const char * nm)
88 {
89         registered_structure_info rsi={nm};
90         registered_structures().push_back(rsi);
91         return registered_structures().size()-1;
92 }
93
94 } // namespace GiNaC