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