]> www.ginac.de Git - ginac.git/blobdiff - ginac/container.h
Compilation for GCC 4.2.
[ginac.git] / ginac / container.h
index 5d6fe3ac5ebb3e9a79b4728ba75345e5005d7eb2..b173e35d476ca1fa3f4f9c01f8801e6f8a3bd654 100644 (file)
@@ -3,7 +3,7 @@
  *  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
@@ -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__
@@ -39,7 +39,7 @@ namespace GiNaC {
 
 
 /** Helper template for encapsulating the reserve() mechanics of STL containers. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 class container_storage {
 protected:
        typedef C<ex> STLT;
@@ -125,10 +125,11 @@ private:
 };
 
 /** Wrapper template for making GiNaC classes out of STL containers. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > 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:
@@ -137,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 ')'; }
@@ -187,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);
@@ -369,8 +370,8 @@ public:
 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;
@@ -380,8 +381,8 @@ protected:
                                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);
@@ -393,6 +394,29 @@ protected:
                }
                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
@@ -451,14 +475,14 @@ protected:
 };
 
 /** Default constructor */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 container<C>::container() : inherited(get_tinfo())
 {
        setflag(get_default_flags());
 }
 
 /** Construct object from archive_node. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 container<C>::container(const archive_node &n, lst &sym_lst) : inherited(n, sym_lst)
 {
        setflag(get_default_flags());
@@ -473,14 +497,14 @@ container<C>::container(const archive_node &n, lst &sym_lst) : inherited(n, sym_
 }
 
 /** Unarchive the object. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 ex container<C>::unarchive(const archive_node &n, lst &sym_lst)
 {
        return (new container(n, sym_lst))->setflag(status_flags::dynallocated);
 }
 
 /** Archive the object. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 void container<C>::archive(archive_node &n) const
 {
        inherited::archive(n);
@@ -491,17 +515,17 @@ void container<C>::archive(archive_node &n) const
        }
 }
 
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 void container<C>::do_print(const print_context & c, unsigned level) const
 {
        // always print brackets around seq, ignore upper_precedence
        printseq(c, get_open_delim(), ',', get_close_delim(), precedence(), precedence()+1);
 }
 
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > 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;
@@ -513,20 +537,20 @@ void container<C>::do_print_tree(const print_tree & c, unsigned level) const
        c.s << std::string(level + c.delta_indent,' ') << "=====" << std::endl;
 }
 
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 void container<C>::do_print_python(const print_python & c, unsigned level) const
 {
        printseq(c, '[', ',', ']', precedence(), precedence()+1);
 }
 
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 void container<C>::do_print_python_repr(const print_python_repr & c, unsigned level) const
 {
        c.s << class_name();
        printseq(c, '(', ',', ')', precedence(), precedence()+1);
 }
 
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 ex container<C>::op(size_t i) const
 {
        GINAC_ASSERT(i < nops());
@@ -536,7 +560,7 @@ ex container<C>::op(size_t i) const
        return *it;
 }
 
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 ex & container<C>::let_op(size_t i)
 {
        GINAC_ASSERT(i < nops());
@@ -547,7 +571,7 @@ ex & container<C>::let_op(size_t i)
        return *it;
 }
 
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 ex container<C>::eval(int level) const
 {
        if (level == 1)
@@ -556,7 +580,7 @@ ex container<C>::eval(int level) const
                return thiscontainer(evalchildren(level));
 }
 
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 ex container<C>::subs(const exmap & m, unsigned options) const
 {
        std::auto_ptr<STLT> vp = subschildren(m, options);
@@ -567,7 +591,7 @@ ex container<C>::subs(const exmap & m, unsigned options) const
 }
 
 /** Compare two containers of the same type. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 int container<C>::compare_same_type(const basic & other) const
 {
        GINAC_ASSERT(is_a<container>(other));
@@ -586,7 +610,7 @@ int container<C>::compare_same_type(const basic & other) const
        return (it1 == it1end) ? (it2 == it2end ? 0 : -1) : 1;
 }
 
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 bool container<C>::is_equal_same_type(const basic & other) const
 {
        GINAC_ASSERT(is_a<container>(other));
@@ -606,7 +630,7 @@ bool container<C>::is_equal_same_type(const basic & other) const
 }
 
 /** Add element at front. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 container<C> & container<C>::prepend(const ex & b)
 {
        ensure_if_modifiable();
@@ -615,7 +639,7 @@ container<C> & container<C>::prepend(const ex & b)
 }
 
 /** Add element at back. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 container<C> & container<C>::append(const ex & b)
 {
        ensure_if_modifiable();
@@ -624,7 +648,7 @@ container<C> & container<C>::append(const ex & b)
 }
 
 /** Remove first element. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 container<C> & container<C>::remove_first()
 {
        ensure_if_modifiable();
@@ -633,7 +657,7 @@ container<C> & container<C>::remove_first()
 }
 
 /** Remove last element. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 container<C> & container<C>::remove_last()
 {
        ensure_if_modifiable();
@@ -642,7 +666,7 @@ container<C> & container<C>::remove_last()
 }
 
 /** Remove all elements. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 container<C> & container<C>::remove_all()
 {
        ensure_if_modifiable();
@@ -651,7 +675,7 @@ container<C> & container<C>::remove_all()
 }
 
 /** Sort elements. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 container<C> & container<C>::sort()
 {
        ensure_if_modifiable();
@@ -660,13 +684,13 @@ 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());
 }
 
 /** Remove adjacent duplicate elements. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 container<C> & container<C>::unique()
 {
        ensure_if_modifiable();
@@ -675,7 +699,7 @@ container<C> & container<C>::unique()
 }
 
 /** Print sequence of contained elements. */
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 void container<C>::printseq(const print_context & c, char openbracket, char delim,
                             char closebracket, unsigned this_precedence,
                             unsigned upper_precedence) const
@@ -698,7 +722,7 @@ void container<C>::printseq(const print_context & c, char openbracket, char deli
                c.s << closebracket;
 }
 
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > class C>
 typename container<C>::STLT container<C>::evalchildren(int level) const
 {
        if (level == 1)
@@ -719,12 +743,12 @@ typename container<C>::STLT container<C>::evalchildren(int level) const
        return s;
 }
 
-template <template <class> class C>
+template <template <class T, class = std::allocator<T> > 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) {