]> www.ginac.de Git - ginac.git/blobdiff - ginac/container.h
Bug in expand_dummy_sum is fixed.
[ginac.git] / ginac / container.h
index 2459b364ffb0d36c70004f530cdc1cd147dd1751..7f9210027d9779c2974d794e9b0c6ee5c2779310 100644 (file)
@@ -3,7 +3,7 @@
  *  Wrapper template for making GiNaC classes out of STL containers. */
 
 /*
- *  GiNaC Copyright (C) 1999-2003 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
@@ -17,7 +17,7 @@
  *
  *  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__
@@ -124,12 +124,12 @@ private:
        STLT & stlt;
 };
 
-
 /** Wrapper template for making GiNaC classes out of STL containers. */
 template <template <class> class C>
 class container : public basic, public container_storage<C> {
        GINAC_DECLARE_REGISTERED_CLASS(container, basic)
 
+protected:
        typedef typename container_storage<C>::STLT STLT;
 
 public:
@@ -138,7 +138,7 @@ 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 ')'; }
@@ -188,7 +188,7 @@ public:
        }
 
        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);
@@ -368,6 +368,55 @@ public:
        ex subs(const exmap & m, unsigned options = 0) const;
 
 protected:
+       ex conjugate() const
+       {
+               STLT *newcont = NULL;
+               for (const_iterator i=this->seq.begin(); i!=this->seq.end(); ++i) {
+                       if (newcont) {
+                               newcont->push_back(i->conjugate());
+                               continue;
+                       }
+                       ex x = i->conjugate();
+                       if (are_ex_trivially_equal(x, *i)) {
+                               continue;
+                       }
+                       newcont = new STLT;
+                       reserve(*newcont, this->seq.size());
+                       for (const_iterator j=this->seq.begin(); j!=i; ++j) {
+                               newcont->push_back(*j);
+                       }
+                       newcont->push_back(x);
+               }
+               if (newcont) {
+                       ex result = thiscontainer(*newcont);
+                       delete newcont;
+                       return result;
+               }
+               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
@@ -476,7 +525,7 @@ void container<C>::do_print(const print_context & c, unsigned level) const
 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;
@@ -635,7 +684,7 @@ container<C> & container<C>::sort()
 }
 
 /** 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());
 }
@@ -698,8 +747,8 @@ template <template <class> class C>
 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) {