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_NAMESPACE_GINAC
32 #endif // ndef NO_NAMESPACE_GINAC
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(const indexed & other)
56 debugmsg("indexed copy constructor",LOGLEVEL_CONSTRUCT);
60 const indexed & indexed::operator=(const indexed & other)
62 debugmsg("indexed operator=",LOGLEVEL_ASSIGNMENT);
72 void indexed::copy(const indexed & other)
74 inherited::copy(other);
77 void indexed::destroy(bool call_parent)
80 inherited::destroy(call_parent);
90 indexed::indexed(const ex & 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(const ex & i1, const ex & 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(const ex & i1, const ex & i2, const ex & 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(const ex & i1, const ex & i2, const ex & i3, const ex & 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(const exvector & 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);
142 tinfo_key = TINFO_indexed;
145 /** Unarchive the object. */
146 ex indexed::unarchive(const archive_node &n, const lst &sym_lst)
148 return (new indexed(n, sym_lst))->setflag(status_flags::dynallocated);
151 /** Archive the object. */
152 void indexed::archive(archive_node &n) const
154 inherited::archive(n);
158 // functions overriding virtual functions from bases classes
163 basic * indexed::duplicate() const
165 debugmsg("indexed duplicate",LOGLEVEL_DUPLICATE);
166 return new indexed(*this);
169 void indexed::printraw(ostream & os) const
171 debugmsg("indexed printraw",LOGLEVEL_PRINT);
172 os << "indexed(indices=";
174 os << ",hash=" << hashvalue << ",flags=" << flags << ")";
177 void indexed::printtree(ostream & os, unsigned indent) const
179 debugmsg("indexed printtree",LOGLEVEL_PRINT);
180 os << string(indent,' ') << "indexed: " << seq.size() << " indices";
181 os << ",hash=" << hashvalue << ",flags=" << flags << endl;
182 printtreeindices(os,indent);
185 void indexed::print(ostream & os, unsigned upper_precedence) const
187 debugmsg("indexed print",LOGLEVEL_PRINT);
188 os << "UNNAMEDINDEX";
192 void indexed::printcsrc(ostream & os, unsigned type,
193 unsigned upper_precedence) const
195 debugmsg("indexed print csrc",LOGLEVEL_PRINT);
196 print(os,upper_precedence);
199 bool indexed::info(unsigned inf) const
201 if (inf==info_flags::indexed) return true;
202 if (inf==info_flags::has_indices) return seq.size()!=0;
203 return inherited::info(inf);
206 exvector indexed::get_indices(void) const
211 idxvector filtered_indices;
212 filtered_indices.reserve(indices.size());
213 for (idxvector::const_iterator cit=indices.begin(); cit!=indices.end(); ++cit) {
214 if ((*cit).get_type()==t) {
215 filtered_indices.push_back(*cit);
218 return filtered_indices;
224 /** Implementation of ex::diff() for an indexed object. It always returns 0.
226 ex indexed::derivative(const symbol & s) const
231 int indexed::compare_same_type(const basic & other) const
233 GINAC_ASSERT(is_of_type(other,indexed));
234 return inherited::compare_same_type(other);
237 bool indexed::is_equal_same_type(const basic & other) const
239 GINAC_ASSERT(is_of_type(other,indexed));
240 return inherited::is_equal_same_type(other);
243 unsigned indexed::return_type(void) const
245 return return_types::noncommutative;
248 unsigned indexed::return_type_tinfo(void) const
253 ex indexed::thisexprseq(const exvector & v) const
258 ex indexed::thisexprseq(exvector * vp) const
264 // virtual functions which can be overridden by derived classes
270 // non-virtual functions in this class
275 void indexed::printrawindices(ostream & os) const
278 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
285 void indexed::printtreeindices(ostream & os, unsigned indent) const
288 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
289 os << string(indent+delta_indent,' ');
296 void indexed::printindices(ostream & os) const
302 exvector::const_iterator last=seq.end()-1;
303 exvector::const_iterator cit=seq.begin();
304 for (; cit!=last; ++cit) {
315 bool indexed::all_of_type_idx(void) const
317 // used only inside of ASSERTs
318 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
319 if (!is_ex_of_type(*cit,idx)) return false;
325 // static member variables
334 const indexed some_indexed;
335 const type_info & typeid_indexed=typeid(some_indexed);
337 #ifndef NO_NAMESPACE_GINAC
339 #endif // ndef NO_NAMESPACE_GINAC