X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fcontainer.pl;h=bab6a88c34919824a46bd7dd0202ca65eb1ed533;hp=0ef3b896d47908f8c4355b1a86637b75c9120d59;hb=5184d67c0ec1056ac039419e08558632793a4e2c;hpb=b2613f4b583961c3b3fe46dc6ddd2bd1f1b2684c diff --git a/ginac/container.pl b/ginac/container.pl index 0ef3b896..bab6a88c 100755 --- a/ginac/container.pl +++ b/ginac/container.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl -w -if ($#ARGV!=0) { - die 'usage: container.pl type (type=lst or exprseq)'; +if (($#ARGV!=0) and ($#ARGV!=1)) { + die 'usage: container.pl type [maxargs] (type=lst or exprseq)'; } if ($ARGV[0] eq 'lst') { @@ -12,8 +12,11 @@ if ($ARGV[0] eq 'lst') { die 'only lst and exprseq supported'; } -#$type='lst'; -#$type='exprseq'; +if ($#ARGV==1) { + $maxargs=$ARGV[1]; +} else { + $maxargs=15; # must be greater or equal than the value used in function.pl +} if ($type eq 'exprseq') { @@ -86,6 +89,57 @@ END_OF_LET_OP_IMPLEMENTATION $LET_OP_IMPLEMENTATION="// ${CONTAINER}::let_op() will be implemented by user elsewhere"; } +sub generate_seq { + my ($seq_template,$n,$separator)=@_; + my ($res,$N); + + $res=''; + for ($N=1; $N<=$n; $N++) { + $res .= eval('"' . $seq_template . '"'); + if ($N!=$n) { + $res .= $separator; + } + } + return $res; +} + +sub generate_from_to { + my ($template,$seq_template1,$seq_separator1,$seq_template2, + $seq_separator2,$from,$to)=@_; + my ($res,$N,$SEQ); + + $res=''; + for ($N=$from; $N<=$to; $N++) { + $SEQ1=generate_seq($seq_template1,$N,$seq_separator1); + $SEQ2=generate_seq($seq_template2,$N,$seq_separator2); + $res .= eval('"' . $template . '"'); + $SEQ1=''; # to avoid main::SEQ1 used only once warning + $SEQ2=''; # same as above + } + return $res; +} + +sub generate { + my ($template,$seq_template1,$seq_separator1,$seq_template2, + $seq_separator2)=@_; + return generate_from_to($template,$seq_template1,$seq_separator1, + $seq_template2,$seq_separator2,1,$maxargs); +} + +$constructors_interface=generate( +' explicit ${CONTAINER}(${SEQ1});'."\n", +'const ex & param${N}',', ','',''); + +$constructors_implementation=generate( + <<'END_OF_CONSTRUCTORS_IMPLEMENTATION','const ex & param${N}',', ',' seq.push_back(param${N});',"\n"); +${CONTAINER}::${CONTAINER}(${SEQ1}) : basic(TINFO_${CONTAINER}) +{ + debugmsg(\"${CONTAINER} constructor from ${N}*ex\",LOGLEVEL_CONSTRUCT); + RESERVE(seq,${N}); +${SEQ2} +} +END_OF_CONSTRUCTORS_IMPLEMENTATION + $interface=<