]> www.ginac.de Git - ginac.git/blob - ginac/container.pl
building in separate directory didn't work
[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-2001 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
191 // Cint does not like ${STLHEADER}<..,default_alloc> but malloc_alloc is
192 // unstandardized and not supported by newer GCCs.
193 #if defined(__GNUC__) && ((__GNUC__ == 2) && (__GNUC_MINOR__ < 97))
194 typedef std::${STLHEADER}<ex,malloc_alloc> ${STLT};
195 #else
196 typedef std::${STLHEADER}<ex> ${STLT};
197 #endif
198
199 class ${CONTAINER} : public basic
200 {
201         GINAC_DECLARE_REGISTERED_CLASS(${CONTAINER}, basic)
202
203 public:
204         ${CONTAINER}(${STLT} const & s, bool discardable=0);
205         ${CONTAINER}(${STLT} * vp); // vp will be deleted
206 ${constructors_interface}
207
208 public:
209         void printraw(std::ostream & os) const;
210         void print(std::ostream & os, unsigned upper_precedence=0) const;
211         void printtree(std::ostream & os, unsigned indent) const;
212         bool info(unsigned inf) const;
213         unsigned nops() const;
214         ex & let_op(int i);
215         ex expand(unsigned options=0) const;
216         bool has(const ex & other) const;
217         ex eval(int level=0) const;
218         ex evalf(int level=0) const;
219         ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
220         ex derivative(const symbol & s) const;
221         ex subs(const lst & ls, const lst & lr) const;
222 protected:
223         bool is_equal_same_type(const basic & other) const;
224         unsigned return_type(void) const;
225
226         // new virtual functions which can be overridden by derived classes
227 public:
228         virtual ${CONTAINER} & append(const ex & b);
229 ${PREPEND_INTERFACE}
230 protected:
231         virtual void printseq(std::ostream & os, char openbracket, char delim,
232                               char closebracket, unsigned this_precedence,
233                               unsigned upper_precedence=0) const;
234         virtual ex this${CONTAINER}(${STLT} const & v) const;
235         virtual ex this${CONTAINER}(${STLT} * vp) const;
236
237 protected:
238         bool is_canonical() const;
239         ${STLT} evalchildren(int level) const;
240         ${STLT} evalfchildren(int level) const;
241         ${STLT} normalchildren(int level) const;
242         ${STLT} diffchildren(const symbol & s) const;
243         ${STLT} * subschildren(const lst & ls, const lst & lr) const;
244
245 protected:
246         ${STLT} seq;
247         static unsigned precedence;
248 };
249
250 // global constants
251
252 extern const ${CONTAINER} some_${CONTAINER};
253 extern const std::type_info & typeid_${CONTAINER};
254
255 // utility functions
256 inline const ${CONTAINER} &ex_to_${CONTAINER}(const ex &e)
257 {
258         return static_cast<const ${CONTAINER} &>(*e.bp);
259 }
260
261 inline ${CONTAINER} &ex_to_nonconst_${CONTAINER}(const ex &e)
262 {
263         return static_cast<${CONTAINER} &>(*e.bp);
264 }
265
266 #ifndef NO_NAMESPACE_GINAC
267 } // namespace GiNaC
268 #endif // ndef NO_NAMESPACE_GINAC
269
270 #endif // ndef __GINAC_${CONTAINER_UC}_H__
271
272 END_OF_INTERFACE
273
274 $implementation=<<END_OF_IMPLEMENTATION;
275 /** \@file ${CONTAINER}.cpp
276  *
277  *  Implementation of GiNaC's ${CONTAINER}. */
278
279 /*
280  *  This file was generated automatically by container.pl.
281  *  Please do not modify it directly, edit the perl script instead!
282  *  container.pl options: \$CONTAINER=${CONTAINER}
283  *                        \$STLHEADER=${STLHEADER}
284  *                        \$reserve=${reserve}
285  *                        \$prepend=${prepend}
286  *                        \$let_op=${let_op}
287  *                        \$open_bracket=${open_bracket}
288  *                        \$close_bracket=${close_bracket}
289  *                        \$maxargs=${maxargs}
290  *
291  *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
292  *
293  *  This program is free software; you can redistribute it and/or modify
294  *  it under the terms of the GNU General Public License as published by
295  *  the Free Software Foundation; either version 2 of the License, or
296  *  (at your option) any later version.
297  *
298  *  This program is distributed in the hope that it will be useful,
299  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
300  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
301  *  GNU General Public License for more details.
302  *
303  *  You should have received a copy of the GNU General Public License
304  *  along with this program; if not, write to the Free Software
305  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
306  */
307
308 #include <iostream>
309 #include <stdexcept>
310
311 #include "${CONTAINER}.h"
312 #include "ex.h"
313 #include "archive.h"
314 #include "debugmsg.h"
315
316 #ifndef NO_NAMESPACE_GINAC
317 namespace GiNaC {
318 #endif // ndef NO_NAMESPACE_GINAC
319
320 GINAC_IMPLEMENT_REGISTERED_CLASS(${CONTAINER}, basic)
321
322 ${RESERVE_IMPLEMENTATION}
323
324 //////////
325 // default constructor, destructor, copy constructor assignment operator and helpers
326 //////////
327
328 // public
329
330 ${CONTAINER}::${CONTAINER}() : basic(TINFO_${CONTAINER})
331 {
332         debugmsg("${CONTAINER} default constructor",LOGLEVEL_CONSTRUCT);
333 }
334
335 // protected
336
337 void ${CONTAINER}::copy(${CONTAINER} const & other)
338 {
339         inherited::copy(other);
340         seq=other.seq;
341 }
342
343 void ${CONTAINER}::destroy(bool call_parent)
344 {
345         seq.clear();
346         if (call_parent) inherited::destroy(call_parent);
347 }
348
349 //////////
350 // other constructors
351 //////////
352
353 // public
354
355 ${CONTAINER}::${CONTAINER}(${STLT} const & s, bool discardable) :  basic(TINFO_${CONTAINER})
356 {
357         debugmsg("${CONTAINER} constructor from ${STLT}", LOGLEVEL_CONSTRUCT);
358         if (discardable) {
359                 seq.swap(const_cast<${STLT} &>(s));
360         } else {
361                 seq=s;
362         }
363 }
364
365 ${CONTAINER}::${CONTAINER}(${STLT} * vp) : basic(TINFO_${CONTAINER})
366 {
367         debugmsg("${CONTAINER} constructor from ${STLT} *",LOGLEVEL_CONSTRUCT);
368         GINAC_ASSERT(vp!=0);
369         seq.swap(*vp);
370         delete vp;
371 }
372
373 ${constructors_implementation}
374
375 //////////
376 // archiving
377 //////////
378
379 /** Construct object from archive_node. */
380 ${CONTAINER}::${CONTAINER}(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
381 {
382         debugmsg("${CONTAINER} constructor from archive_node", LOGLEVEL_CONSTRUCT);
383         for (unsigned int i=0; true; i++) {
384                 ex e;
385                 if (n.find_ex("seq", e, sym_lst, i))
386                         seq.push_back(e);
387                 else
388                         break;
389         }
390 }
391
392 /** Unarchive the object. */
393 ex ${CONTAINER}::unarchive(const archive_node &n, const lst &sym_lst)
394 {
395         return (new ${CONTAINER}(n, sym_lst))->setflag(status_flags::dynallocated);
396 }
397
398 /** Archive the object. */
399 void ${CONTAINER}::archive(archive_node &n) const
400 {
401         inherited::archive(n);
402         ${STLT}::const_iterator i = seq.begin(), iend = seq.end();
403         while (i != iend) {
404                 n.add_ex("seq", *i);
405                 i++;
406         }
407 }
408
409 //////////
410 // functions overriding virtual functions from bases classes
411 //////////
412
413 // public
414
415 void ${CONTAINER}::printraw(std::ostream & os) const
416 {
417         debugmsg("${CONTAINER} printraw",LOGLEVEL_PRINT);
418
419         os << "${CONTAINER}(";
420         for (${STLT}::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
421                 (*cit).bp->printraw(os);
422                 os << ",";
423         }
424         os << ")";
425 }
426
427 void ${CONTAINER}::print(std::ostream & os, unsigned upper_precedence) const
428 {
429         debugmsg("${CONTAINER} print",LOGLEVEL_PRINT);
430         // always print brackets around seq, ignore upper_precedence
431         printseq(os,'${open_bracket}',',','${close_bracket}',precedence,precedence+1);
432 }
433
434 void ${CONTAINER}::printtree(std::ostream & os, unsigned indent) const
435 {
436         debugmsg("${CONTAINER} printtree",LOGLEVEL_PRINT);
437
438         os << std::string(indent,' ') << "type=" << class_name()
439            << ", hash=" << hashvalue 
440            << " (0x" << std::hex << hashvalue << std::dec << ")"
441            << ", flags=" << flags
442            << ", nops=" << nops() << std::endl;
443         for (${STLT}::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
444                 (*cit).printtree(os,indent+delta_indent);
445         }
446         os << std::string(indent+delta_indent,' ') << "=====" << std::endl;
447 }
448
449 // ${CONTAINER}::info() will be implemented by user elsewhere";
450
451 unsigned ${CONTAINER}::nops() const
452 {
453         return seq.size();
454 }
455
456 ${LET_OP_IMPLEMENTATION}
457
458 ex ${CONTAINER}::expand(unsigned options) const
459 {
460         ${STLT} s;
461         RESERVE(s,seq.size());
462         for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
463                 s.push_back((*it).expand(options));
464         }
465
466         return this${CONTAINER}(s);
467 }
468
469 // a ${CONTAINER} 'has' an expression if it is this expression itself or a child 'has' it
470
471 bool ${CONTAINER}::has(const ex & other) const
472 {
473         GINAC_ASSERT(other.bp!=0);
474         if (is_equal(*other.bp)) return true;
475         for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
476                 if ((*it).has(other)) return true;
477         }
478         return false;
479 }
480
481 ex ${CONTAINER}::eval(int level) const
482 {
483         if (level==1) {
484                 return this->hold();
485         }
486         return this${CONTAINER}(evalchildren(level));
487 }
488
489 ex ${CONTAINER}::evalf(int level) const
490 {
491         return this${CONTAINER}(evalfchildren(level));
492 }
493
494 /** Implementation of ex::normal() for ${CONTAINER}s. It normalizes the arguments
495  *  and replaces the ${CONTAINER} by a temporary symbol.
496  *  \@see ex::normal */
497 ex ${CONTAINER}::normal(lst &sym_lst, lst &repl_lst, int level) const
498 {
499         ex n=this${CONTAINER}(normalchildren(level));
500         return n.bp->basic::normal(sym_lst,repl_lst,level);
501 }
502
503 ex ${CONTAINER}::derivative(const symbol & s) const
504 {
505         return this${CONTAINER}(diffchildren(s));
506 }
507
508 ex ${CONTAINER}::subs(const lst & ls, const lst & lr) const
509 {
510         ${STLT} * vp=subschildren(ls,lr);
511         if (vp==0) {
512                 return *this;
513         }
514         return this${CONTAINER}(vp);
515 }
516
517 // protected
518
519 int ${CONTAINER}::compare_same_type(const basic & other) const
520 {
521         GINAC_ASSERT(is_of_type(other,${CONTAINER}));
522         ${CONTAINER} const & o=static_cast<${CONTAINER} const &>
523                                                                         (const_cast<basic &>(other));
524         int cmpval;
525         ${STLT}::const_iterator it1=seq.begin();
526         ${STLT}::const_iterator it2=o.seq.begin();
527
528         for (; (it1!=seq.end())&&(it2!=o.seq.end()); ++it1, ++it2) {
529                 cmpval=(*it1).compare(*it2);
530                 if (cmpval!=0) return cmpval;
531         }
532
533         if (it1==seq.end()) {
534                 return (it2==o.seq.end() ? 0 : -1);
535         }
536
537         return 1;
538 }
539
540 bool ${CONTAINER}::is_equal_same_type(const basic & other) const
541 {
542         GINAC_ASSERT(is_of_type(other,${CONTAINER}));
543         ${CONTAINER} const & o=static_cast<${CONTAINER} const &>
544                                                                         (const_cast<basic &>(other));
545         if (seq.size()!=o.seq.size()) return false;
546
547         ${STLT}::const_iterator it1=seq.begin();
548         ${STLT}::const_iterator it2=o.seq.begin();
549
550         for (; it1!=seq.end(); ++it1, ++it2) {
551                 if (!(*it1).is_equal(*it2)) return false;
552         }
553
554         return true;
555 }
556
557 unsigned ${CONTAINER}::return_type(void) const
558 {
559         return return_types::noncommutative_composite;
560 }
561
562 //////////
563 // new virtual functions which can be overridden by derived classes
564 //////////
565
566 // public
567
568 ${CONTAINER} & ${CONTAINER}::append(const ex & b)
569 {
570         ensure_if_modifiable();
571         seq.push_back(b);
572         return *this;
573 }
574
575 ${PREPEND_IMPLEMENTATION}
576
577 // protected
578
579 void ${CONTAINER}::printseq(std::ostream & os, char openbracket, char delim,
580                             char closebracket, unsigned this_precedence,
581                             unsigned upper_precedence) const
582 {
583         if (this_precedence<=upper_precedence) os << openbracket;
584         if (seq.size()!=0) {
585                 ${STLT}::const_iterator it,it_last;
586                 it=seq.begin();
587                 it_last=seq.end();
588                 --it_last;
589                 for (; it!=it_last; ++it) {
590                         (*it).bp->print(os,this_precedence);
591                         os << delim;
592                 }
593                 (*it).bp->print(os,this_precedence);
594         }
595         if (this_precedence<=upper_precedence) os << closebracket;
596 }
597
598 ex ${CONTAINER}::this${CONTAINER}(${STLT} const & v) const
599 {
600         return ${CONTAINER}(v);
601 }
602
603 ex ${CONTAINER}::this${CONTAINER}(${STLT} * vp) const
604 {
605         return ${CONTAINER}(vp);
606 }
607
608 //////////
609 // non-virtual functions in this class
610 //////////
611
612 // public
613
614 // none
615
616 // protected
617
618 bool ${CONTAINER}::is_canonical() const
619 {
620         if (seq.size()<=1) { return 1; }
621
622         ${STLT}::const_iterator it=seq.begin();
623         ${STLT}::const_iterator it_last=it;
624         for (++it; it!=seq.end(); it_last=it, ++it) {
625                 if ((*it_last).compare(*it)>0) {
626                         if ((*it_last).compare(*it)>0) {
627                                 std::cout << *it_last << ">" << *it << "\\n";
628                                 return 0;
629                         }
630                 }
631         }
632         return 1;
633 }
634
635
636 ${STLT} ${CONTAINER}::evalchildren(int level) const
637 {
638         ${STLT} s;
639         RESERVE(s,seq.size());
640
641         if (level==1) {
642                 return seq;
643         }
644         if (level == -max_recursion_level) {
645                 throw(std::runtime_error("max recursion level reached"));
646         }
647         --level;
648         for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
649                 s.push_back((*it).eval(level));
650         }
651         return s;
652 }
653
654 ${STLT} ${CONTAINER}::evalfchildren(int level) const
655 {
656         ${STLT} s;
657         RESERVE(s,seq.size());
658
659         if (level==1) {
660                 return seq;
661         }
662         if (level == -max_recursion_level) {
663                 throw(std::runtime_error("max recursion level reached"));
664         }
665         --level;
666         for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
667                 s.push_back((*it).evalf(level));
668         }
669         return s;
670 }
671
672 ${STLT} ${CONTAINER}::normalchildren(int level) const
673 {
674         ${STLT} s;
675         RESERVE(s,seq.size());
676
677         if (level==1) {
678                 return seq;
679         }
680         if (level == -max_recursion_level) {
681                 throw(std::runtime_error("max recursion level reached"));
682         }
683         --level;
684         for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
685                 s.push_back((*it).normal(level));
686         }
687         return s;
688 }
689
690 ${STLT} ${CONTAINER}::diffchildren(const symbol & y) const
691 {
692         ${STLT} s;
693         RESERVE(s,seq.size());
694         for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
695                 s.push_back((*it).diff(y));
696         }
697         return s;
698 }
699
700 /* obsolete subschildren
701 ${STLT} ${CONTAINER}::subschildren(const lst & ls, const lst & lr) const
702 {
703         ${STLT} s;
704         RESERVE(s,seq.size());
705         for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
706                 s.push_back((*it).subs(ls,lr));
707         }
708         return s;
709 }
710 */
711
712 ${STLT} * ${CONTAINER}::subschildren(const lst & ls, const lst & lr) const
713 {
714         // returns a NULL pointer if nothing had to be substituted
715         // returns a pointer to a newly created epvector otherwise
716         // (which has to be deleted somewhere else)
717
718         ${STLT}::const_iterator last=seq.end();
719         ${STLT}::const_iterator cit=seq.begin();
720         while (cit!=last) {
721                 const ex & subsed_ex=(*cit).subs(ls,lr);
722                 if (!are_ex_trivially_equal(*cit,subsed_ex)) {
723
724                         // something changed, copy seq, subs and return it
725                         ${STLT} *s=new ${STLT};
726                         RESERVE(*s,seq.size());
727
728                         // copy parts of seq which are known not to have changed
729                         ${STLT}::const_iterator cit2=seq.begin();
730                         while (cit2!=cit) {
731                                 s->push_back(*cit2);
732                                 ++cit2;
733                         }
734                         // copy first changed element
735                         s->push_back(subsed_ex);
736                         ++cit2;
737                         // copy rest
738                         while (cit2!=last) {
739                                 s->push_back((*cit2).subs(ls,lr));
740                                 ++cit2;
741                         }
742                         return s;
743                 }
744                 ++cit;
745         }
746         
747         return 0; // nothing has changed
748 }
749
750 //////////
751 // static member variables
752 //////////
753
754 // protected
755
756 unsigned ${CONTAINER}::precedence=10;
757
758 //////////
759 // global constants
760 //////////
761
762 const ${CONTAINER} some_${CONTAINER};
763 const std::type_info & typeid_${CONTAINER} = typeid(some_${CONTAINER});
764
765 #ifndef NO_NAMESPACE_GINAC
766 } // namespace GiNaC
767 #endif // ndef NO_NAMESPACE_GINAC
768
769 END_OF_IMPLEMENTATION
770
771 print "Creating interface file ${CONTAINER}.h...";
772 open OUT,">${CONTAINER}.h" or die "cannot open ${CONTAINER}.h";
773 print OUT $interface;
774 close OUT;
775 print "ok.\n";
776
777 print "Creating implementation file ${CONTAINER}.cpp...";
778 open OUT,">${CONTAINER}.cpp" or die "cannot open ${CONTAINER}.cpp";
779 print OUT $implementation;
780 close OUT;
781 print "ok.\n";
782
783 print "done.\n";