* Wrapper template for making GiNaC classes out of STL containers. */
/*
- * GiNaC Copyright (C) 1999-2004 Johannes Gutenberg University Mainz, Germany
+ * GiNaC Copyright (C) 1999-2006 Johannes Gutenberg University Mainz, Germany
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __GINAC_CONTAINER_H__
class container : public basic, public container_storage<C> {
GINAC_DECLARE_REGISTERED_CLASS(container, basic)
+protected:
typedef typename container_storage<C>::STLT STLT;
public:
protected:
// helpers
- static unsigned get_tinfo() { return TINFO_fail; }
+ static tinfo_t get_tinfo() { return NULL; }
static unsigned get_default_flags() { return 0; }
static char get_open_delim() { return '('; }
static char get_close_delim() { return ')'; }
}
container(const ex & p1, const ex & p2, const ex & p3,
- const ex & p4) : inherited(get_tinfo())
+ const ex & p4) : inherited(get_tinfo())
{
setflag(get_default_flags());
reserve(this->seq, 4);
protected:
ex conjugate() const
{
- STLT* newcont = 0;
- for (const_iterator i=seq.begin(); i!=seq.end(); ++i) {
+ STLT *newcont = NULL;
+ for (const_iterator i=this->seq.begin(); i!=this->seq.end(); ++i) {
if (newcont) {
newcont->push_back(i->conjugate());
continue;
continue;
}
newcont = new STLT;
- reserve (*newcont, seq.size());
- for (const_iterator j=seq.begin(); j!=i; ++j) {
+ reserve(*newcont, this->seq.size());
+ for (const_iterator j=this->seq.begin(); j!=i; ++j) {
newcont->push_back(*j);
}
newcont->push_back(x);
}
return *this;
}
+
+ ex real_part() const
+ {
+ STLT cont;
+ reserve(cont, nops());
+ const_iterator b = begin();
+ const_iterator e = end();
+ for(const_iterator i=b; i!=e; ++i)
+ cont.push_back(i->real_part());
+ return thiscontainer(cont);
+ }
+
+ ex imag_part() const
+ {
+ STLT cont;
+ reserve(cont, nops());
+ const_iterator b = begin();
+ const_iterator e = end();
+ for(const_iterator i=b; i!=e; ++i)
+ cont.push_back(i->imag_part());
+ return thiscontainer(cont);
+ }
+
bool is_equal_same_type(const basic & other) const;
// new virtual functions which can be overridden by derived classes
template <template <class> class C>
void container<C>::do_print_tree(const print_tree & c, unsigned level) const
{
- c.s << std::string(level, ' ') << class_name()
+ c.s << std::string(level, ' ') << class_name() << " @" << this
<< std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
<< ", nops=" << nops()
<< std::endl;
}
/** Specialization of container::unique_() for std::list. */
-inline void container<std::list>::unique_()
+template<> inline void container<std::list>::unique_()
{
this->seq.unique(ex_is_equal());
}
std::auto_ptr<typename container<C>::STLT> container<C>::subschildren(const exmap & m, unsigned options) const
{
// returns a NULL pointer if nothing had to be substituted
- // returns a pointer to a newly created epvector otherwise
- // (and relinquishes responsibility for the epvector)
+ // returns a pointer to a newly created STLT otherwise
+ // (and relinquishes responsibility for the STLT)
const_iterator cit = this->seq.begin(), end = this->seq.end();
while (cit != end) {