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