3 * Implementation of GiNaC's index carrying objects. */
6 * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
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.
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.
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
30 #ifndef NO_GINAC_NAMESPACE
32 #endif // ndef NO_GINAC_NAMESPACE
34 GINAC_IMPLEMENT_REGISTERED_CLASS(indexed, exprseq)
37 // default constructor, destructor, copy constructor assignment operator and helpers
44 debugmsg("indexed default constructor",LOGLEVEL_CONSTRUCT);
45 tinfo_key=TINFO_indexed;
50 debugmsg("indexed destructor",LOGLEVEL_DESTRUCT);
54 indexed::indexed(indexed const & other)
56 debugmsg("indexed copy constructor",LOGLEVEL_CONSTRUCT);
60 indexed const & indexed::operator=(indexed const & other)
62 debugmsg("indexed operator=",LOGLEVEL_ASSIGNMENT);
72 void indexed::copy(indexed const & other)
74 inherited::copy(other);
77 void indexed::destroy(bool call_parent)
80 inherited::destroy(call_parent);
90 indexed::indexed(ex const & i1) : inherited(i1)
92 debugmsg("indexed constructor from ex",LOGLEVEL_CONSTRUCT);
93 tinfo_key=TINFO_indexed;
94 GINAC_ASSERT(all_of_type_idx());
97 indexed::indexed(ex const & i1, ex const & i2) : inherited(i1,i2)
99 debugmsg("indexed constructor from ex,ex",LOGLEVEL_CONSTRUCT);
100 tinfo_key=TINFO_indexed;
101 GINAC_ASSERT(all_of_type_idx());
104 indexed::indexed(ex const & i1, ex const & i2, ex const & i3)
105 : inherited(i1,i2,i3)
107 debugmsg("indexed constructor from ex,ex,ex",LOGLEVEL_CONSTRUCT);
108 tinfo_key=TINFO_indexed;
109 GINAC_ASSERT(all_of_type_idx());
112 indexed::indexed(ex const & i1, ex const & i2, ex const & i3, ex const & i4)
113 : inherited(i1,i2,i3,i4)
115 debugmsg("indexed constructor from ex,ex,ex,ex",LOGLEVEL_CONSTRUCT);
116 tinfo_key=TINFO_indexed;
117 GINAC_ASSERT(all_of_type_idx());
120 indexed::indexed(exvector const & iv) : inherited(iv)
122 debugmsg("indexed constructor from exvector",LOGLEVEL_CONSTRUCT);
123 tinfo_key=TINFO_indexed;
124 GINAC_ASSERT(all_of_type_idx());
127 indexed::indexed(exvector * ivp) : inherited(ivp)
129 debugmsg("indexed constructor from exvector *",LOGLEVEL_CONSTRUCT);
130 tinfo_key=TINFO_indexed;
131 GINAC_ASSERT(all_of_type_idx());
138 /** Construct object from archive_node. */
139 indexed::indexed(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
141 debugmsg("indexed constructor from archive_node", LOGLEVEL_CONSTRUCT);
144 /** Unarchive the object. */
145 ex indexed::unarchive(const archive_node &n, const lst &sym_lst)
147 return (new indexed(n, sym_lst))->setflag(status_flags::dynallocated);
150 /** Archive the object. */
151 void indexed::archive(archive_node &n) const
153 inherited::archive(n);
157 // functions overriding virtual functions from bases classes
162 basic * indexed::duplicate() const
164 debugmsg("indexed duplicate",LOGLEVEL_DUPLICATE);
165 return new indexed(*this);
168 void indexed::printraw(ostream & os) const
170 debugmsg("indexed printraw",LOGLEVEL_PRINT);
171 os << "indexed(indices=";
173 os << ",hash=" << hashvalue << ",flags=" << flags << ")";
176 void indexed::printtree(ostream & os, unsigned indent) const
178 debugmsg("indexed printtree",LOGLEVEL_PRINT);
179 os << string(indent,' ') << "indexed: " << seq.size() << " indices";
180 os << ",hash=" << hashvalue << ",flags=" << flags << endl;
181 printtreeindices(os,indent);
184 void indexed::print(ostream & os, unsigned upper_precedence) const
186 debugmsg("indexed print",LOGLEVEL_PRINT);
187 os << "UNNAMEDINDEX";
191 void indexed::printcsrc(ostream & os, unsigned type,
192 unsigned upper_precedence) const
194 debugmsg("indexed print csrc",LOGLEVEL_PRINT);
195 print(os,upper_precedence);
198 bool indexed::info(unsigned inf) const
200 if (inf==info_flags::indexed) return true;
201 if (inf==info_flags::has_indices) return seq.size()!=0;
202 return inherited::info(inf);
205 exvector indexed::get_indices(void) const
210 idxvector filtered_indices;
211 filtered_indices.reserve(indices.size());
212 for (idxvector::const_iterator cit=indices.begin(); cit!=indices.end(); ++cit) {
213 if ((*cit).get_type()==t) {
214 filtered_indices.push_back(*cit);
217 return filtered_indices;
223 int indexed::compare_same_type(basic const & other) const
225 GINAC_ASSERT(is_of_type(other,indexed));
226 return inherited::compare_same_type(other);
229 bool indexed::is_equal_same_type(basic const & other) const
231 GINAC_ASSERT(is_of_type(other,indexed));
232 return inherited::is_equal_same_type(other);
235 unsigned indexed::return_type(void) const
237 return return_types::noncommutative;
240 unsigned indexed::return_type_tinfo(void) const
245 ex indexed::thisexprseq(exvector const & v) const
250 ex indexed::thisexprseq(exvector * vp) const
256 // virtual functions which can be overridden by derived classes
262 // non-virtual functions in this class
267 void indexed::printrawindices(ostream & os) const
270 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
277 void indexed::printtreeindices(ostream & os, unsigned indent) const
280 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
281 os << string(indent+delta_indent,' ');
288 void indexed::printindices(ostream & os) const
294 exvector::const_iterator last=seq.end()-1;
295 exvector::const_iterator cit=seq.begin();
296 for (; cit!=last; ++cit) {
307 bool indexed::all_of_type_idx(void) const
309 // used only inside of ASSERTs
310 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
311 if (!is_ex_of_type(*cit,idx)) return false;
317 // static member variables
326 const indexed some_indexed;
327 type_info const & typeid_indexed=typeid(some_indexed);
329 #ifndef NO_GINAC_NAMESPACE
331 #endif // ndef NO_GINAC_NAMESPACE