#include <algorithm>
#include <vector>
#include <list>
+#include <memory>
#include "ex.h"
#include "print.h"
this->seq = s;
}
- explicit container(STLT * vp) : inherited(get_tinfo())
+ explicit container(std::auto_ptr<STLT> vp) : inherited(get_tinfo())
{
- if (vp == 0) {
- // lst(0) ends up here
- this->seq.push_back(0);
- } else {
- this->seq.swap(*vp);
- delete vp;
- }
+ this->seq.swap(*vp);
}
container(exvector::const_iterator b, exvector::const_iterator e)
// functions overriding virtual functions from base classes
public:
- void print(const print_context & c, unsigned level = 0) const;
bool info(unsigned inf) const { return inherited::info(inf); }
unsigned precedence() const { return 10; }
size_t nops() const { return this->seq.size(); }
/** Similar to duplicate(), but with a preset sequence (which gets
* deleted). Must be overridden by derived classes. */
- virtual ex thiscontainer(STLT * vp) const { return container(vp); }
+ virtual ex thiscontainer(std::auto_ptr<STLT> vp) const { return container(vp); }
virtual void printseq(const print_context & c, char openbracket, char delim,
char closebracket, unsigned this_precedence,
const_reverse_iterator rend() const {return this->seq.rend();}
protected:
+ void do_print(const print_context & c, unsigned level) const;
+ void do_print_tree(const print_tree & c, unsigned level) const;
+ void do_print_python(const print_python & c, unsigned level) const;
+ void do_print_python_repr(const print_python_repr & c, unsigned level) const;
STLT evalchildren(int level) const;
- STLT *subschildren(const exmap & m, unsigned options = 0) const;
+ std::auto_ptr<STLT> subschildren(const exmap & m, unsigned options = 0) const;
};
/** Default constructor */
}
template <template <class> class C>
-void container<C>::print(const print_context & c, unsigned level) const
+void container<C>::do_print(const print_context & c, unsigned level) const
{
- if (is_a<print_tree>(c)) {
- c.s << std::string(level, ' ') << class_name()
- << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
- << ", nops=" << nops()
- << std::endl;
- unsigned delta_indent = static_cast<const print_tree &>(c).delta_indent;
- const_iterator i = this->seq.begin(), end = this->seq.end();
- while (i != end) {
- i->print(c, level + delta_indent);
- ++i;
- }
- c.s << std::string(level + delta_indent,' ') << "=====" << std::endl;
- } else if (is_a<print_python>(c)) {
- printseq(c, '[', ',', ']', precedence(), precedence()+1);
- } else if (is_a<print_python_repr>(c)) {
- c.s << class_name ();
- printseq(c, '(', ',', ')', precedence(), precedence()+1);
- } else {
- // always print brackets around seq, ignore upper_precedence
- printseq(c, get_open_delim(), ',', get_close_delim(), precedence(), precedence()+1);
+ // always print brackets around seq, ignore upper_precedence
+ printseq(c, get_open_delim(), ',', get_close_delim(), precedence(), precedence()+1);
+}
+
+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()
+ << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
+ << ", nops=" << nops()
+ << std::endl;
+ const_iterator i = this->seq.begin(), end = this->seq.end();
+ while (i != end) {
+ i->print(c, level + c.delta_indent);
+ ++i;
}
+ c.s << std::string(level + c.delta_indent,' ') << "=====" << std::endl;
+}
+
+template <template <class> 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>
+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> class C>
ex container<C>::subs(const exmap & m, unsigned options) const
{
- STLT *vp = subschildren(m, options);
- if (vp)
+ std::auto_ptr<STLT> vp = subschildren(m, options);
+ if (vp.get())
return ex_to<basic>(thiscontainer(vp)).subs_one_level(m, options);
else
return subs_one_level(m, options);
}
template <template <class> class C>
-typename container<C>::STLT *container<C>::subschildren(const exmap & m, unsigned options) const
+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
- // (which has to be deleted somewhere else)
+ // (and relinquishes responsibility for the epvector)
const_iterator cit = this->seq.begin(), end = this->seq.end();
while (cit != end) {
if (!are_ex_trivially_equal(*cit, subsed_ex)) {
// copy first part of seq which hasn't changed
- STLT *s = new STLT(this->seq.begin(), cit);
+ std::auto_ptr<STLT> s(new STLT(this->seq.begin(), cit));
reserve(*s, this->seq.size());
// insert changed element
++cit;
}
- return 0; // nothing has changed
+ return std::auto_ptr<STLT>(0); // nothing has changed
}
} // namespace GiNaC