[system] / trunk / pg / lib / Parser / BOP / union.pm Repository:
ViewVC logotype

View of /trunk/pg/lib/Parser/BOP/union.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2625 - (download) (as text) (annotate)
Mon Aug 16 18:35:12 2004 UTC (15 years, 3 months ago) by dpvc
File size: 1557 byte(s)
Added string comparison to all Value object classes (to compare the
string value of an object to another string).

Overloaded perl '.' operator to do dot product when the operands are
formulas returning vectors.  (Part of the auto-generation of
formulas).

A few improvements to real and complex class output results.

Made Union class slightly more robust and removed need for makeUnion
method other than in the Union itself.

    1 #########################################################################
    2 #
    3 #  Implement the Union operand
    4 #
    5 
    6 package Parser::BOP::union;
    7 use strict; use vars qw(@ISA);
    8 @ISA = qw(Parser::BOP);
    9 
   10 #
   11 #  Check that the two operands are Intervals, Unions,
   12 #    or points of length two (which can be promoted).
   13 #
   14 sub _check {
   15   my $self = shift;
   16   return if ($self->checkStrings());
   17   if ($self->{lop}->{canBeInterval} && $self->{rop}->{canBeInterval}) {
   18     $self->{type} = Value::Type('Union',2,$Value::Type{number});
   19     $self->{canBeInterval} = 1;
   20     foreach my $op ('lop','rop') {
   21       if ($self->{$op}->type !~ m/^(Interval|Union)$/) {
   22   $self->{$op} = bless $self->{$op}, 'Parser::List::Interval';
   23   $self->{$op}->typeRef->{name} = $self->{equation}{context}{parens}{interval}{type};
   24       }
   25     }
   26   } else {$self->Error("Operands of '$self->{bop}' must be intervals")}
   27 }
   28 
   29 
   30 #
   31 #  Make a union of the two operands.
   32 #
   33 sub _eval {shift; Value::Union->new(@_)}
   34 
   35 #
   36 #  Make a union of intervals.
   37 #
   38 sub perl {
   39   my $self = shift; my $parens = shift; my @union = ();
   40   foreach my $x ($self->makeUnion) {push(@union,$x->perl)}
   41   my $perl = 'Union('.join(',',@union).')';
   42   $perl = '('.$perl.')' if $parens;
   43   return $perl;
   44 }
   45 
   46 #
   47 #  Turn a union into a list of the intervals in the union.
   48 #
   49 sub makeUnion {
   50   my $self = shift;
   51   return (
   52     $self->{lop}{def}{isUnion}? $self->{lop}->makeUnion : $self->{lop},
   53     $self->{rop}{def}{isUnion}? $self->{rop}->makeUnion : $self->{rop},
   54   );
   55 }
   56 
   57 #########################################################################
   58 
   59 1;
   60 

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9