]> www.ginac.de Git - ginac.git/blob - ginac/container.pl
- Derivatives are now assembled in a slightly different manner (i.e. they
[ginac.git] / ginac / container.pl
1 if (($#ARGV!=0) and ($#ARGV!=1)) {
2     die 'usage: container.pl type [maxargs] (type=lst or exprseq)';
3 }
4
5 if ($ARGV[0] eq 'lst') {
6     $type='lst';
7 } elsif ($ARGV[0] eq 'exprseq') {
8     $type='exprseq';
9 } else {
10     die 'only lst and exprseq supported';
11 }
12
13 if ($#ARGV==1) {
14     $maxargs=$ARGV[1];
15 } else {
16     $maxargs=15; # must be greater or equal than the value used in function.pl
17 }
18
19 if ($type eq 'exprseq') {
20
21     # settings for exprseq
22     $CONTAINER="exprseq";
23     $STLHEADER="vector";
24     $reserve=1;
25     $prepend=0;
26     $let_op=0;
27     $open_bracket='(';
28     $close_bracket=')';
29     
30 } elsif ($type eq 'lst') {
31  
32     # settings for lst
33     $CONTAINER="lst";
34     $STLHEADER="list";
35     $reserve=0;
36     $prepend=1;
37     $let_op=1;
38     $open_bracket='[';
39     $close_bracket=']';
40
41 } else {
42     die "invalid type $type";
43 }
44
45 $CONTAINER_UC=uc(${CONTAINER});
46 $STLT="ex".$STLHEADER;
47
48 if ($reserve) {
49     $RESERVE_IMPLEMENTATION="#define RESERVE(s,size) (s).reserve(size)";
50 } else {
51     $RESERVE_IMPLEMENTATION="#define RESERVE(s,size) // no reserve needed for ${STLHEADER}";
52 }
53
54 if ($prepend) {
55     $PREPEND_INTERFACE=<<END_OF_PREPEND_INTERFACE;
56     virtual ${CONTAINER} & prepend(const ex & b);
57 END_OF_PREPEND_INTERFACE
58
59     $PREPEND_IMPLEMENTATION=<<END_OF_PREPEND_IMPLEMENTATION;
60 ${CONTAINER} & ${CONTAINER}::prepend(const ex & b)
61 {
62     ensure_if_modifiable();
63     seq.push_front(b);
64     return *this;
65 }
66 END_OF_PREPEND_IMPLEMENTATION
67 } else {
68     $PREPEND_INTERFACE="    // no prepend possible for ${CONTAINER}";
69     $PREPEND_IMPLEMENTATION="";
70 }
71
72 if ($let_op) {
73     $LET_OP_IMPLEMENTATION=<<END_OF_LET_OP_IMPLEMENTATION
74 ex & ${CONTAINER}::let_op(int i)
75 {
76     GINAC_ASSERT(i>=0);
77     GINAC_ASSERT(i<nops());
78
79     ${STLT}::iterator it=seq.begin();
80     for (int j=0; j<i; j++) {
81         ++it;
82     }
83     return *it;
84 }
85 END_OF_LET_OP_IMPLEMENTATION
86 } else {
87     $LET_OP_IMPLEMENTATION="// ${CONTAINER}::let_op() will be implemented by user elsewhere";
88 }
89
90 sub generate_seq {
91     my ($seq_template,$n,$separator)=@_;
92     my ($res,$N);
93     
94     $res='';
95     for ($N=1; $N<=$n; $N++) {
96         $res .= eval('"' . $seq_template . '"');
97         if ($N!=$n) {
98             $res .= $separator;
99         }
100     }
101     return $res;
102 }
103
104 sub generate_from_to {
105     my ($template,$seq_template1,$seq_separator1,$seq_template2,
106         $seq_separator2,$from,$to)=@_;
107     my ($res,$N,$SEQ);
108
109     $res='';
110     for ($N=$from; $N<=$to; $N++) {
111         $SEQ1=generate_seq($seq_template1,$N,$seq_separator1);
112         $SEQ2=generate_seq($seq_template2,$N,$seq_separator2);
113         $res .= eval('"' . $template . '"');
114         $SEQ1=''; # to avoid main::SEQ1 used only once warning
115         $SEQ2=''; # same as above
116     }
117     return $res;
118 }
119
120 sub generate {
121     my ($template,$seq_template1,$seq_separator1,$seq_template2,
122         $seq_separator2)=@_;
123     return generate_from_to($template,$seq_template1,$seq_separator1,
124                             $seq_template2,$seq_separator2,1,$maxargs);
125 }
126
127 $constructors_interface=generate(
128 '    explicit ${CONTAINER}(${SEQ1});'."\n",
129 'const ex & param${N}',', ','','');
130
131 $constructors_implementation=generate(
132     <<'END_OF_CONSTRUCTORS_IMPLEMENTATION','const ex & param${N}',', ','    seq.push_back(param${N});',"\n");
133 ${CONTAINER}::${CONTAINER}(${SEQ1}) : basic(TINFO_${CONTAINER})
134 {
135     debugmsg(\"${CONTAINER} constructor from ${N}*ex\",LOGLEVEL_CONSTRUCT);
136     RESERVE(seq,${N});
137 ${SEQ2}
138 }
139 END_OF_CONSTRUCTORS_IMPLEMENTATION
140
141 $interface=<<END_OF_INTERFACE;
142 /** \@file ${CONTAINER}.h
143  *
144  *  Definition of GiNaC's ${CONTAINER}. */
145
146 /*
147  *  This file was generated automatically by container.pl.
148  *  Please do not modify it directly, edit the perl script instead!
149  *  container.pl options: \$CONTAINER=${CONTAINER}
150  *                        \$STLHEADER=${STLHEADER}
151  *                        \$reserve=${reserve}
152  *                        \$prepend=${prepend}
153  *                        \$let_op=${let_op}
154  *                        \$open_bracket=${open_bracket}
155  *                        \$close_bracket=${close_bracket}
156  *                        \$maxargs=${maxargs}
157  *
158  *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
159  *
160  *  This program is free software; you can redistribute it and/or modify
161  *  it under the terms of the GNU General Public License as published by
162  *  the Free Software Foundation; either version 2 of the License, or
163  *  (at your option) any later version.
164  *
165  *  This program is distributed in the hope that it will be useful,
166  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
167  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
168  *  GNU General Public License for more details.
169  *
170  *  You should have received a copy of the GNU General Public License
171  *  along with this program; if not, write to the Free Software
172  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
173  */
174
175 #ifndef __GINAC_${CONTAINER_UC}_H__
176 #define __GINAC_${CONTAINER_UC}_H__
177
178 #include <${STLHEADER}>
179
180 // CINT needs <algorithm> to work properly with <vector> and <list> 
181 #include <algorithm>
182
183 #include "basic.h"
184 #include "ex.h"
185
186 #ifndef NO_NAMESPACE_GINAC
187 namespace GiNaC {
188 #endif // ndef NO_NAMESPACE_GINAC
189
190 // typedef std::${STLHEADER}<ex> ${STLT};
191 typedef std::${STLHEADER}<ex,malloc_alloc> ${STLT}; // CINT does not like ${STLHEADER}<...,default_alloc>
192
193 class ${CONTAINER} : public basic
194 {
195     GINAC_DECLARE_REGISTERED_CLASS(${CONTAINER}, basic)
196
197 public:
198     ${CONTAINER}();
199     ~${CONTAINER}();
200     ${CONTAINER}(${CONTAINER} const & other);
201     ${CONTAINER} const & operator=(${CONTAINER} const & other);
202 protected:
203     void copy(${CONTAINER} const & other);
204     void destroy(bool call_parent);
205
206 public:
207     ${CONTAINER}(${STLT} const & s, bool discardable=0);
208     ${CONTAINER}(${STLT} * vp); // vp will be deleted
209 ${constructors_interface}
210
211 public:
212     basic * duplicate() const;
213     void printraw(std::ostream & os) const;
214     void print(std::ostream & os, unsigned upper_precedence=0) const;
215     void printtree(std::ostream & os, unsigned indent) const;
216     bool info(unsigned inf) const;
217     unsigned nops() const;
218     ex & let_op(int i);
219     ex expand(unsigned options=0) const;
220     bool has(const ex & other) const;
221     ex eval(int level=0) const;
222     ex evalf(int level=0) const;
223     ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
224     ex derivative(const symbol & s) const;
225     ex subs(const lst & ls, const lst & lr) const;
226 protected:
227     int compare_same_type(const basic & other) const;
228     bool is_equal_same_type(const basic & other) const;
229     unsigned return_type(void) const;
230
231     // new virtual functions which can be overridden by derived classes
232 public:
233     virtual ${CONTAINER} & append(const ex & b);
234 ${PREPEND_INTERFACE}
235 protected:
236     virtual void printseq(std::ostream & os, char openbracket, char delim,
237                           char closebracket, unsigned this_precedence,
238                           unsigned upper_precedence=0) const;
239     virtual ex this${CONTAINER}(${STLT} const & v) const;
240     virtual ex this${CONTAINER}(${STLT} * vp) const;
241
242 protected:
243     bool is_canonical() const;
244     ${STLT} evalchildren(int level) const;
245     ${STLT} evalfchildren(int level) const;
246     ${STLT} normalchildren(int level) const;
247     ${STLT} diffchildren(const symbol & s) const;
248     ${STLT} * subschildren(const lst & ls, const lst & lr) const;
249
250 protected:
251     ${STLT} seq;
252     static unsigned precedence;
253 };
254
255 // global constants
256
257 extern const ${CONTAINER} some_${CONTAINER};
258 extern const type_info & typeid_${CONTAINER};
259
260 // utility functions
261 inline const ${CONTAINER} &ex_to_${CONTAINER}(const ex &e)
262 {
263     return static_cast<const ${CONTAINER} &>(*e.bp);
264 }
265
266 inline ${CONTAINER} &ex_to_nonconst_${CONTAINER}(const ex &e)
267 {
268     return static_cast<${CONTAINER} &>(*e.bp);
269 }
270
271 #ifndef NO_NAMESPACE_GINAC
272 } // namespace GiNaC
273 #endif // ndef NO_NAMESPACE_GINAC
274
275 #endif // ndef __GINAC_${CONTAINER_UC}_H__
276
277 END_OF_INTERFACE
278
279 $implementation=<<END_OF_IMPLEMENTATION;
280 /** \@file ${CONTAINER}.cpp
281  *
282  *  Implementation of GiNaC's ${CONTAINER}. */
283
284 /*
285  *  This file was generated automatically by container.pl.
286  *  Please do not modify it directly, edit the perl script instead!
287  *  container.pl options: \$CONTAINER=${CONTAINER}
288  *                        \$STLHEADER=${STLHEADER}
289  *                        \$reserve=${reserve}
290  *                        \$prepend=${prepend}
291  *                        \$let_op=${let_op}
292  *                        \$open_bracket=${open_bracket}
293  *                        \$close_bracket=${close_bracket}
294  *                        \$maxargs=${maxargs}
295  *
296  *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
297  *
298  *  This program is free software; you can redistribute it and/or modify
299  *  it under the terms of the GNU General Public License as published by
300  *  the Free Software Foundation; either version 2 of the License, or
301  *  (at your option) any later version.
302  *
303  *  This program is distributed in the hope that it will be useful,
304  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
305  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
306  *  GNU General Public License for more details.
307  *
308  *  You should have received a copy of the GNU General Public License
309  *  along with this program; if not, write to the Free Software
310  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
311  */
312
313 #include <iostream>
314 #include <stdexcept>
315
316 #include "${CONTAINER}.h"
317 #include "ex.h"
318 #include "archive.h"
319 #include "debugmsg.h"
320
321 #ifndef NO_NAMESPACE_GINAC
322 namespace GiNaC {
323 #endif // ndef NO_NAMESPACE_GINAC
324
325 GINAC_IMPLEMENT_REGISTERED_CLASS(${CONTAINER}, basic)
326
327 ${RESERVE_IMPLEMENTATION}
328
329 //////////
330 // default constructor, destructor, copy constructor assignment operator and helpers
331 //////////
332
333 // public
334
335 ${CONTAINER}::${CONTAINER}() : basic(TINFO_${CONTAINER})
336 {
337     debugmsg("${CONTAINER} default constructor",LOGLEVEL_CONSTRUCT);
338 }
339
340 ${CONTAINER}::~${CONTAINER}()
341 {
342     debugmsg("${CONTAINER} destructor",LOGLEVEL_DESTRUCT);
343     destroy(0);
344 }
345
346 ${CONTAINER}::${CONTAINER}(${CONTAINER} const & other)
347 {
348     debugmsg("${CONTAINER} copy constructor",LOGLEVEL_CONSTRUCT);
349     copy(other);
350 }
351
352 ${CONTAINER} const & ${CONTAINER}::operator=(${CONTAINER} const & other)
353 {
354     debugmsg("${CONTAINER} operator=",LOGLEVEL_ASSIGNMENT);
355     if (this != &other) {
356         destroy(1);
357         copy(other);
358     }
359     return *this;
360 }
361
362 // protected
363
364 void ${CONTAINER}::copy(${CONTAINER} const & other)
365 {
366     inherited::copy(other);
367     seq=other.seq;
368 }
369
370 void ${CONTAINER}::destroy(bool call_parent)
371 {
372     seq.clear();
373     if (call_parent) inherited::destroy(call_parent);
374 }
375
376 //////////
377 // other constructors
378 //////////
379
380 // public
381
382 ${CONTAINER}::${CONTAINER}(${STLT} const & s, bool discardable) :  basic(TINFO_${CONTAINER})
383 {
384     debugmsg("${CONTAINER} constructor from ${STLT}",
385              LOGLEVEL_CONSTRUCT);
386     if (discardable) {
387         seq.swap(const_cast<${STLT} &>(s));
388     } else {
389         seq=s;
390     }
391 }
392
393 ${CONTAINER}::${CONTAINER}(${STLT} * vp) : basic(TINFO_${CONTAINER})
394 {
395     debugmsg("${CONTAINER} constructor from ${STLT} *",LOGLEVEL_CONSTRUCT);
396     GINAC_ASSERT(vp!=0);
397     seq.swap(*vp);
398     delete vp;
399 }
400
401 ${constructors_implementation}
402
403 //////////
404 // archiving
405 //////////
406
407 /** Construct object from archive_node. */
408 ${CONTAINER}::${CONTAINER}(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
409 {
410     debugmsg("${CONTAINER} constructor from archive_node", LOGLEVEL_CONSTRUCT);
411     for (unsigned int i=0; true; i++) {
412         ex e;
413         if (n.find_ex("seq", e, sym_lst, i))
414             seq.push_back(e);
415         else
416             break;
417     }
418 }
419
420 /** Unarchive the object. */
421 ex ${CONTAINER}::unarchive(const archive_node &n, const lst &sym_lst)
422 {
423     return (new ${CONTAINER}(n, sym_lst))->setflag(status_flags::dynallocated);
424 }
425
426 /** Archive the object. */
427 void ${CONTAINER}::archive(archive_node &n) const
428 {
429     inherited::archive(n);
430     ${STLT}::const_iterator i = seq.begin(), iend = seq.end();
431     while (i != iend) {
432         n.add_ex("seq", *i);
433         i++;
434     }
435 }
436
437 //////////
438 // functions overriding virtual functions from bases classes
439 //////////
440
441 // public
442
443 basic * ${CONTAINER}::duplicate() const
444 {
445     debugmsg("${CONTAINER} duplicate",LOGLEVEL_DUPLICATE);
446     return new ${CONTAINER}(*this);
447 }
448
449 void ${CONTAINER}::printraw(std::ostream & os) const
450 {
451     debugmsg("${CONTAINER} printraw",LOGLEVEL_PRINT);
452
453     os << "${CONTAINER}(";
454     for (${STLT}::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
455         (*cit).bp->printraw(os);
456         os << ",";
457     }
458     os << ")";
459 }
460
461 void ${CONTAINER}::print(std::ostream & os, unsigned upper_precedence) const
462 {
463     debugmsg("${CONTAINER} print",LOGLEVEL_PRINT);
464     // always print brackets around seq, ignore upper_precedence
465     printseq(os,'${open_bracket}',',','${close_bracket}',precedence,precedence+1);
466 }
467
468 void ${CONTAINER}::printtree(std::ostream & os, unsigned indent) const
469 {
470     debugmsg("${CONTAINER} printtree",LOGLEVEL_PRINT);
471
472     os << std::string(indent,' ') << "type=" << typeid(*this).name()
473        << ", hash=" << hashvalue 
474        << " (0x" << std::hex << hashvalue << std::dec << ")"
475        << ", flags=" << flags
476        << ", nops=" << nops() << std::endl;
477     for (${STLT}::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
478         (*cit).printtree(os,indent+delta_indent);
479     }
480     os << std::string(indent+delta_indent,' ') << "=====" << std::endl;
481 }
482
483 // ${CONTAINER}::info() will be implemented by user elsewhere";
484
485 unsigned ${CONTAINER}::nops() const
486 {
487     return seq.size();
488 }
489
490 ${LET_OP_IMPLEMENTATION}
491
492 ex ${CONTAINER}::expand(unsigned options) const
493 {
494     ${STLT} s;
495     RESERVE(s,seq.size());
496     for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
497         s.push_back((*it).expand(options));
498     }
499
500     return this${CONTAINER}(s);
501 }
502
503 // a ${CONTAINER} 'has' an expression if it is this expression itself or a child 'has' it
504
505 bool ${CONTAINER}::has(const ex & other) const
506 {
507     GINAC_ASSERT(other.bp!=0);
508     if (is_equal(*other.bp)) return true;
509     for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
510         if ((*it).has(other)) return true;
511     }
512     return false;
513 }
514
515 ex ${CONTAINER}::eval(int level) const
516 {
517     if (level==1) {
518         return this->hold();
519     }
520     return this${CONTAINER}(evalchildren(level));
521 }
522
523 ex ${CONTAINER}::evalf(int level) const
524 {
525     return this${CONTAINER}(evalfchildren(level));
526 }
527
528 /** Implementation of ex::normal() for ${CONTAINER}s. It normalizes the arguments
529  *  and replaces the ${CONTAINER} by a temporary symbol.
530  *  \@see ex::normal */
531 ex ${CONTAINER}::normal(lst &sym_lst, lst &repl_lst, int level) const
532 {
533     ex n=this${CONTAINER}(normalchildren(level));
534     return n.bp->basic::normal(sym_lst,repl_lst,level);
535 }
536
537 ex ${CONTAINER}::derivative(const symbol & s) const
538 {
539     return this${CONTAINER}(diffchildren(s));
540 }
541
542 ex ${CONTAINER}::subs(const lst & ls, const lst & lr) const
543 {
544     ${STLT} * vp=subschildren(ls,lr);
545     if (vp==0) {
546         return *this;
547     }
548     return this${CONTAINER}(vp);
549 }
550
551 // protected
552
553 int ${CONTAINER}::compare_same_type(const basic & other) const
554 {
555     GINAC_ASSERT(is_of_type(other,${CONTAINER}));
556     ${CONTAINER} const & o=static_cast<${CONTAINER} const &>
557                                     (const_cast<basic &>(other));
558     int cmpval;
559     ${STLT}::const_iterator it1=seq.begin();
560     ${STLT}::const_iterator it2=o.seq.begin();
561
562     for (; (it1!=seq.end())&&(it2!=o.seq.end()); ++it1, ++it2) {
563         cmpval=(*it1).compare(*it2);
564         if (cmpval!=0) return cmpval;
565     }
566
567     if (it1==seq.end()) {
568         return (it2==o.seq.end() ? 0 : -1);
569     }
570
571     return 1;
572 }
573
574 bool ${CONTAINER}::is_equal_same_type(const basic & other) const
575 {
576     GINAC_ASSERT(is_of_type(other,${CONTAINER}));
577     ${CONTAINER} const & o=static_cast<${CONTAINER} const &>
578                                     (const_cast<basic &>(other));
579     if (seq.size()!=o.seq.size()) return false;
580
581     ${STLT}::const_iterator it1=seq.begin();
582     ${STLT}::const_iterator it2=o.seq.begin();
583
584     for (; it1!=seq.end(); ++it1, ++it2) {
585         if (!(*it1).is_equal(*it2)) return false;
586     }
587
588     return true;
589 }
590
591 unsigned ${CONTAINER}::return_type(void) const
592 {
593     return return_types::noncommutative_composite;
594 }
595
596 //////////
597 // new virtual functions which can be overridden by derived classes
598 //////////
599
600 // public
601
602 ${CONTAINER} & ${CONTAINER}::append(const ex & b)
603 {
604     ensure_if_modifiable();
605     seq.push_back(b);
606     return *this;
607 }
608
609 ${PREPEND_IMPLEMENTATION}
610
611 // protected
612
613 void ${CONTAINER}::printseq(std::ostream & os, char openbracket, char delim,
614                          char closebracket, unsigned this_precedence,
615                          unsigned upper_precedence) const
616 {
617     if (this_precedence<=upper_precedence) os << openbracket;
618     if (seq.size()!=0) {
619         ${STLT}::const_iterator it,it_last;
620         it=seq.begin();
621         it_last=seq.end();
622         --it_last;
623         for (; it!=it_last; ++it) {
624             (*it).bp->print(os,this_precedence);
625             os << delim;
626         }
627         (*it).bp->print(os,this_precedence);
628     }
629     if (this_precedence<=upper_precedence) os << closebracket;
630 }
631
632 ex ${CONTAINER}::this${CONTAINER}(${STLT} const & v) const
633 {
634     return ${CONTAINER}(v);
635 }
636
637 ex ${CONTAINER}::this${CONTAINER}(${STLT} * vp) const
638 {
639     return ${CONTAINER}(vp);
640 }
641
642 //////////
643 // non-virtual functions in this class
644 //////////
645
646 // public
647
648 // none
649
650 // protected
651
652 bool ${CONTAINER}::is_canonical() const
653 {
654     if (seq.size()<=1) { return 1; }
655
656     ${STLT}::const_iterator it=seq.begin();
657     ${STLT}::const_iterator it_last=it;
658     for (++it; it!=seq.end(); it_last=it, ++it) {
659         if ((*it_last).compare(*it)>0) {
660             if ((*it_last).compare(*it)>0) {
661                 std::cout << *it_last << ">" << *it << "\\n";
662                 return 0;
663                 }
664         }
665     }
666     return 1;
667 }
668
669
670 ${STLT} ${CONTAINER}::evalchildren(int level) const
671 {
672     ${STLT} s;
673     RESERVE(s,seq.size());
674
675     if (level==1) {
676         return seq;
677     }
678     if (level == -max_recursion_level) {
679         throw(std::runtime_error("max recursion level reached"));
680     }
681     --level;
682     for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
683         s.push_back((*it).eval(level));
684     }
685     return s;
686 }
687
688 ${STLT} ${CONTAINER}::evalfchildren(int level) const
689 {
690     ${STLT} s;
691     RESERVE(s,seq.size());
692
693     if (level==1) {
694         return seq;
695     }
696     if (level == -max_recursion_level) {
697         throw(std::runtime_error("max recursion level reached"));
698     }
699     --level;
700     for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
701         s.push_back((*it).evalf(level));
702     }
703     return s;
704 }
705
706 ${STLT} ${CONTAINER}::normalchildren(int level) const
707 {
708     ${STLT} s;
709     RESERVE(s,seq.size());
710
711     if (level==1) {
712         return seq;
713     }
714     if (level == -max_recursion_level) {
715         throw(std::runtime_error("max recursion level reached"));
716     }
717     --level;
718     for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
719         s.push_back((*it).normal(level));
720     }
721     return s;
722 }
723
724 ${STLT} ${CONTAINER}::diffchildren(const symbol & y) const
725 {
726     ${STLT} s;
727     RESERVE(s,seq.size());
728     for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
729         s.push_back((*it).diff(y));
730     }
731     return s;
732 }
733
734 /* obsolete subschildren
735 ${STLT} ${CONTAINER}::subschildren(const lst & ls, const lst & lr) const
736 {
737     ${STLT} s;
738     RESERVE(s,seq.size());
739     for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
740         s.push_back((*it).subs(ls,lr));
741     }
742     return s;
743 }
744 */
745
746 ${STLT} * ${CONTAINER}::subschildren(const lst & ls, const lst & lr) const
747 {
748     // returns a NULL pointer if nothing had to be substituted
749     // returns a pointer to a newly created epvector otherwise
750     // (which has to be deleted somewhere else)
751
752     ${STLT}::const_iterator last=seq.end();
753     ${STLT}::const_iterator cit=seq.begin();
754     while (cit!=last) {
755         const ex & subsed_ex=(*cit).subs(ls,lr);
756         if (!are_ex_trivially_equal(*cit,subsed_ex)) {
757
758             // something changed, copy seq, subs and return it
759             ${STLT} *s=new ${STLT};
760             RESERVE(*s,seq.size());
761
762             // copy parts of seq which are known not to have changed
763             ${STLT}::const_iterator cit2=seq.begin();
764             while (cit2!=cit) {
765                 s->push_back(*cit2);
766                 ++cit2;
767             }
768             // copy first changed element
769             s->push_back(subsed_ex);
770             ++cit2;
771             // copy rest
772             while (cit2!=last) {
773                 s->push_back((*cit2).subs(ls,lr));
774                 ++cit2;
775             }
776             return s;
777         }
778         ++cit;
779     }
780     
781     return 0; // nothing has changed
782 }
783
784 //////////
785 // static member variables
786 //////////
787
788 // protected
789
790 unsigned ${CONTAINER}::precedence=10;
791
792 //////////
793 // global constants
794 //////////
795
796 const ${CONTAINER} some_${CONTAINER};
797 const type_info & typeid_${CONTAINER}=typeid(some_${CONTAINER});
798
799 #ifndef NO_NAMESPACE_GINAC
800 } // namespace GiNaC
801 #endif // ndef NO_NAMESPACE_GINAC
802
803 END_OF_IMPLEMENTATION
804
805 print "Creating interface file ${CONTAINER}.h...";
806 open OUT,">${CONTAINER}.h" or die "cannot open ${CONTAINER}.h";
807 print OUT $interface;
808 close OUT;
809 print "ok.\n";
810
811 print "Creating implementation file ${CONTAINER}.cpp...";
812 open OUT,">${CONTAINER}.cpp" or die "cannot open ${CONTAINER}.cpp";
813 print OUT $implementation;
814 close OUT;
815 print "ok.\n";
816
817 print "done.\n";