3 * Implementation of GiNaC's index carrying objects. */
10 // default constructor, destructor, copy constructor assignment operator and helpers
17 debugmsg("indexed default constructor",LOGLEVEL_CONSTRUCT);
18 tinfo_key=TINFO_INDEXED;
23 debugmsg("indexed destructor",LOGLEVEL_DESTRUCT);
27 indexed::indexed(indexed const & other)
29 debugmsg("indexed copy constructor",LOGLEVEL_CONSTRUCT);
33 indexed const & indexed::operator=(indexed const & other)
35 debugmsg("indexed operator=",LOGLEVEL_ASSIGNMENT);
45 void indexed::copy(indexed const & other)
50 void indexed::destroy(bool call_parent)
53 exprseq::destroy(call_parent);
63 indexed::indexed(ex const & i1) : exprseq(i1)
65 debugmsg("indexed constructor from ex",LOGLEVEL_CONSTRUCT);
66 tinfo_key=TINFO_INDEXED;
67 ASSERT(all_of_type_idx());
70 indexed::indexed(ex const & i1, ex const & i2) : exprseq(i1,i2)
72 debugmsg("indexed constructor from ex,ex",LOGLEVEL_CONSTRUCT);
73 tinfo_key=TINFO_INDEXED;
74 ASSERT(all_of_type_idx());
77 indexed::indexed(ex const & i1, ex const & i2, ex const & i3)
80 debugmsg("indexed constructor from ex,ex,ex",LOGLEVEL_CONSTRUCT);
81 tinfo_key=TINFO_INDEXED;
82 ASSERT(all_of_type_idx());
85 indexed::indexed(exvector const & iv) : exprseq(iv)
87 debugmsg("indexed constructor from exvector",LOGLEVEL_CONSTRUCT);
88 tinfo_key=TINFO_INDEXED;
89 ASSERT(all_of_type_idx());
92 indexed::indexed(exvector * ivp) : exprseq(ivp)
94 debugmsg("indexed constructor from exvector *",LOGLEVEL_CONSTRUCT);
95 tinfo_key=TINFO_INDEXED;
96 ASSERT(all_of_type_idx());
100 // functions overriding virtual functions from bases classes
105 basic * indexed::duplicate() const
107 debugmsg("indexed duplicate",LOGLEVEL_DUPLICATE);
108 return new indexed(*this);
111 void indexed::printraw(ostream & os) const
113 debugmsg("indexed printraw",LOGLEVEL_PRINT);
114 os << "indexed(indices=";
116 os << ",hash=" << hashvalue << ",flags=" << flags << ")";
119 void indexed::printtree(ostream & os, unsigned indent) const
121 debugmsg("indexed printtree",LOGLEVEL_PRINT);
122 os << string(indent,' ') << "indexed: " << seq.size() << " indices";
123 os << ",hash=" << hashvalue << ",flags=" << flags << endl;
124 printtreeindices(os,indent);
127 void indexed::print(ostream & os, unsigned upper_precedence) const
129 debugmsg("indexed print",LOGLEVEL_PRINT);
130 os << "UNNAMEDINDEX";
134 void indexed::printcsrc(ostream & os, unsigned type,
135 unsigned upper_precedence) const
137 debugmsg("indexed print csrc",LOGLEVEL_PRINT);
138 print(os,upper_precedence);
141 bool indexed::info(unsigned inf) const
143 if (inf==info_flags::indexed) return true;
144 if (inf==info_flags::has_indices) return seq.size()!=0;
145 return exprseq::info(inf);
148 exvector indexed::get_indices(void) const
153 idxvector filtered_indices;
154 filtered_indices.reserve(indices.size());
155 for (idxvector::const_iterator cit=indices.begin(); cit!=indices.end(); ++cit) {
156 if ((*cit).get_type()==t) {
157 filtered_indices.push_back(*cit);
160 return filtered_indices;
166 int indexed::compare_same_type(basic const & other) const
168 ASSERT(is_of_type(other,indexed));
169 return exprseq::compare_same_type(other);
172 bool indexed::is_equal_same_type(basic const & other) const
174 ASSERT(is_of_type(other,indexed));
175 return exprseq::is_equal_same_type(other);
178 unsigned indexed::return_type(void) const
180 return return_types::noncommutative;
183 unsigned indexed::return_type_tinfo(void) const
188 ex indexed::thisexprseq(exvector const & v) const
193 ex indexed::thisexprseq(exvector * vp) const
199 // virtual functions which can be overridden by derived classes
205 // non-virtual functions in this class
210 void indexed::printrawindices(ostream & os) const
213 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
220 void indexed::printtreeindices(ostream & os, unsigned indent) const
223 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
224 os << string(indent+delta_indent,' ');
231 void indexed::printindices(ostream & os) const
237 exvector::const_iterator last=seq.end()-1;
238 exvector::const_iterator cit=seq.begin();
239 for (; cit!=last; ++cit) {
250 bool indexed::all_of_type_idx(void) const
252 // used only inside of ASSERTs
253 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
254 if (!is_ex_of_type(*cit,idx)) return false;
260 // static member variables
269 const indexed some_indexed;
270 type_info const & typeid_indexed=typeid(some_indexed);