3 * Implementation of GiNaC's index carrying objects. */
6 * GiNaC Copyright (C) 1999-2001 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 /** Construct indexed object with one index. The index must be of class idx
94 * @return newly constructed indexed object */
95 indexed::indexed(const ex & i1) : inherited(i1)
97 debugmsg("indexed constructor from ex",LOGLEVEL_CONSTRUCT);
98 tinfo_key=TINFO_indexed;
99 GINAC_ASSERT(all_of_type_idx());
102 /** Construct indexed object with two indices. The indices must be of class
105 * @param i1 First index
106 * @param i2 Second index
107 * @return newly constructed indexed object */
108 indexed::indexed(const ex & i1, const ex & i2) : inherited(i1,i2)
110 debugmsg("indexed constructor from ex,ex",LOGLEVEL_CONSTRUCT);
111 tinfo_key=TINFO_indexed;
112 GINAC_ASSERT(all_of_type_idx());
115 /** Construct indexed object with three indices. The indices must be of class
118 * @param i1 First index
119 * @param i2 Second index
120 * @param i3 Third index
121 * @return newly constructed indexed object */
122 indexed::indexed(const ex & i1, const ex & i2, const ex & i3)
123 : inherited(i1,i2,i3)
125 debugmsg("indexed constructor from ex,ex,ex",LOGLEVEL_CONSTRUCT);
126 tinfo_key=TINFO_indexed;
127 GINAC_ASSERT(all_of_type_idx());
130 /** Construct indexed object with four indices. The indices must be of class
133 * @param i1 First index
134 * @param i2 Second index
135 * @param i3 Third index
136 * @param i4 Fourth index
137 * @return newly constructed indexed object */
138 indexed::indexed(const ex & i1, const ex & i2, const ex & i3, const ex & i4)
139 : inherited(i1,i2,i3,i4)
141 debugmsg("indexed constructor from ex,ex,ex,ex",LOGLEVEL_CONSTRUCT);
142 tinfo_key=TINFO_indexed;
143 GINAC_ASSERT(all_of_type_idx());
146 /** Construct indexed object with a specified vector of indices. The indices
147 * must be of class idx or a subclass.
149 * @param iv Vector of indices
150 * @return newly constructed indexed object */
151 indexed::indexed(const exvector & iv) : inherited(iv)
153 debugmsg("indexed constructor from exvector",LOGLEVEL_CONSTRUCT);
154 tinfo_key=TINFO_indexed;
155 GINAC_ASSERT(all_of_type_idx());
158 indexed::indexed(exvector * ivp) : inherited(ivp)
160 debugmsg("indexed constructor from exvector *",LOGLEVEL_CONSTRUCT);
161 tinfo_key=TINFO_indexed;
162 GINAC_ASSERT(all_of_type_idx());
169 /** Construct object from archive_node. */
170 indexed::indexed(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
172 debugmsg("indexed constructor from archive_node", LOGLEVEL_CONSTRUCT);
173 tinfo_key = TINFO_indexed;
176 /** Unarchive the object. */
177 ex indexed::unarchive(const archive_node &n, const lst &sym_lst)
179 return (new indexed(n, sym_lst))->setflag(status_flags::dynallocated);
182 /** Archive the object. */
183 void indexed::archive(archive_node &n) const
185 inherited::archive(n);
189 // functions overriding virtual functions from bases classes
194 basic * indexed::duplicate() const
196 debugmsg("indexed duplicate",LOGLEVEL_DUPLICATE);
197 return new indexed(*this);
200 void indexed::printraw(std::ostream & os) const
202 debugmsg("indexed printraw",LOGLEVEL_PRINT);
203 os << "indexed(indices=";
205 os << ",hash=" << hashvalue << ",flags=" << flags << ")";
208 void indexed::printtree(std::ostream & os, unsigned indent) const
210 debugmsg("indexed printtree",LOGLEVEL_PRINT);
211 os << std::string(indent,' ') << "indexed: " << seq.size() << " indices";
212 os << ",hash=" << hashvalue << ",flags=" << flags << std::endl;
213 printtreeindices(os,indent);
216 void indexed::print(std::ostream & os, unsigned upper_precedence) const
218 debugmsg("indexed print",LOGLEVEL_PRINT);
219 os << "UNNAMEDINDEX";
223 void indexed::printcsrc(std::ostream & os, unsigned type,
224 unsigned upper_precedence) const
226 debugmsg("indexed print csrc",LOGLEVEL_PRINT);
227 print(os,upper_precedence);
230 bool indexed::info(unsigned inf) const
232 if (inf==info_flags::indexed) return true;
233 if (inf==info_flags::has_indices) return seq.size()!=0;
234 return inherited::info(inf);
239 /** Implementation of ex::diff() for an indexed object. It always returns 0.
241 ex indexed::derivative(const symbol & s) const
246 int indexed::compare_same_type(const basic & other) const
248 GINAC_ASSERT(is_of_type(other,indexed));
249 return inherited::compare_same_type(other);
252 bool indexed::is_equal_same_type(const basic & other) const
254 GINAC_ASSERT(is_of_type(other,indexed));
255 return inherited::is_equal_same_type(other);
258 unsigned indexed::return_type(void) const
260 return return_types::noncommutative;
263 unsigned indexed::return_type_tinfo(void) const
268 ex indexed::thisexprseq(const exvector & v) const
273 ex indexed::thisexprseq(exvector * vp) const
279 // virtual functions which can be overridden by derived classes
285 // non-virtual functions in this class
290 void indexed::printrawindices(std::ostream & os) const
293 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
300 void indexed::printtreeindices(std::ostream & os, unsigned indent) const
303 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
304 os << std::string(indent+delta_indent,' ');
311 void indexed::printindices(std::ostream & os) const
317 exvector::const_iterator last=seq.end()-1;
318 exvector::const_iterator cit=seq.begin();
319 for (; cit!=last; ++cit) {
330 /** Check whether all indices are of class idx or a subclass. This function
331 * is used internally to make sure that all constructed indexed objects
332 * really carry indices and not some other classes. */
333 bool indexed::all_of_type_idx(void) const
335 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
336 if (!is_ex_of_type(*cit,idx)) return false;
342 // static member variables
351 const indexed some_indexed;
352 const std::type_info & typeid_indexed = typeid(some_indexed);
354 #ifndef NO_NAMESPACE_GINAC
356 #endif // ndef NO_NAMESPACE_GINAC