[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GT] SVN Commit r573 - trunk/GT/Indicators/Generic



Author: ras
Date: 2008-03-19 07:58:41 +0100 (Wed, 19 Mar 2008)
New Revision: 573

Modified:
   trunk/GT/Indicators/Generic/ByName.pm
Log:
revision ensures the named indicator can be relocated in
the registry



Modified: trunk/GT/Indicators/Generic/ByName.pm
===================================================================
--- trunk/GT/Indicators/Generic/ByName.pm	2008-03-19 06:49:35 UTC (rev 572)
+++ trunk/GT/Indicators/Generic/ByName.pm	2008-03-19 06:58:41 UTC (rev 573)
@@ -1,7 +1,7 @@
 package GT::Indicators::Generic::ByName;
 
 # Copyright 2000-2002 Rapha�Hertzog, Oliver Bossert
-# Corrections and documention Copyright 2008 Thomas Weigert
+# Copyright 2008 Thomas Weigert
 # This file is distributed under the terms of the General Public License
 # version 2 or (at your option) any later version.
 
@@ -13,6 +13,7 @@
 use vars qw(@ISA @NAMES @DEFAULT_ARGS);
 
 use GT::Indicators;
+use GT::ArgsTree;
 use GT::Prices;
 
 @ISA = qw(GT::Indicators);
@@ -31,7 +32,7 @@
 due to the dependency mechanism.
 
 This indicator resolves the recursion. This indicator is nothing more than
-an alias of a seried calculated by an indicator. Just give as first parameter
+an alias of a series calculated by an indicator. Just give as first parameter
 the name of the value to use.
 
 This indicator is used when, during the calculation of an indicator,
@@ -39,49 +40,54 @@
 or an output value.
 
 For example,
-    $self->{'sma1'} = GT::Indicators::SMA->new([ $self->{'args'}->get_arg_names(1), $self->{'args'}->get_arg_names(2) ]);
-    $self->{'sma2'} = GT::Indicators::SMA->new([ $self->{'args'}->get_arg_names(1), "{I:Generic:ByName " . $self->{'sma1'}->get_name . "}" ]);
 
-The first line defines an intermediate series which smoothes the
-second parameter. The second line takes that series and applies 
+    $self->{'sma1'} = GT::Indicators::SMA->new([ 
+                      $self->{'args'}->get_arg_names(1),
+                      $self->{'args'}->get_arg_names(2) ]);
+    $self->{'sma2'} = GT::Indicators::SMA->new([ 
+                      $self->{'args'}->get_arg_names(1),
+                      "{I:Generic:ByName "
+                    . $self->{'sma1'}->get_name . "}" ]);
+
+The first statement defines an intermediate series which smoothes the
+second parameter. The second statement takes that series and applies 
 smoothing again. Similarly, the following applies smoothing to
 the first output value.
-    $self->{'sma3'} = GT::Indicators::SMA->new([ $self->{'args'}->get_arg_names(1), "{I:Generic:ByName " . $self->get_name(0) . "}" ]);
 
+    $self->{'sma3'} = GT::Indicators::SMA->new([
+                      $self->{'args'}->get_arg_names(1),
+                      "{I:Generic:ByName " . $self->get_name(0) . "}" ]);
+
 Care has to be taken that I:Generic:ByName is in fact given the
-name of an indicator, lest that series will not be found. The get_name
-method will always retrieve the name of a series. The parsable syntax
-does yield a name also.
+name of an indicator, lest that series will not be found.  Note
+that if the series is an indicator, the name of the series is the 
+name of the selected return value. The get_name method will always 
+retrieve the name of a series.
 
-***FIXME***
-The name as generated by the ArgsTree::parse_args is rather
-brittle and needs to be fixed up as indicated in the comments
-embedded in this modules code. Additional problems might exist.
+Remember that the parseable syntax does not yield a name.
 
-
 =cut
 
 sub new {
-    my ($type, $args, $key) = @_;
+    my ($type, $pieces, $key) = @_;
     my $class = ref($type) || $type;
     my $self = { };
     no strict "refs";
-    # Note: Do not add any cruft (e.g., whitespace) when joining the
-    # argument list, otherwise the constructed name will differ from
-    # the name of the referenced series.
-    #$self->{'args'}->[0] = join('', @{$args});
 
-    my $out =  '';
-    foreach (@{$args}) {
-      $out .= $_;
-      $out .= ' ' if ($_ =~ /[a-zA-Z0-9]$/o);
+    my @args = @{$pieces};
+###    map {print "ByName new:$_\n"} @args;
+    my $argstr = shift @args;
+    foreach (@args) {
+      if ($_ =~ /^\]/) {
+        $argstr .= $_;
+      } elsif ($_ =~ /^,$/) {
+        $argstr .= $_;
+      } else {
+        $argstr .= " $_";
+      }
     }
-    # Note: line 333 of ArgsTree.pm inserts extra \s before opening brace
-    # However, when CacheValues are set, these extra \s are not present in name
-    # Remove. 
-    $out =~ s/(\s)+/$1/go;
-    $self->{'args'}->[0] = $out;
-
+    $self->{'args'}->[0] = $argstr;
+###    print "ByName: $self->{'args'}->[0]\n";
     return manage_object(\
AT
{"$class\::NAMES"}, $self, $class, $self->{'args'}, $key);
 }
 
@@ -97,9 +103,8 @@
 
     my @pars = ();
     my $parname = $self->{'args'}->[0];
+###    print "ByName($i): $parname = " . (($indic->is_available($parname, $i))?$indic->get($parname, $i):'') . "\n";
 
-    #print "ByName($i): $parname = " . (($indic->is_available($parname, $i))?$indic->get($parname, $i):'') . "\n";
-
     $indic->set($name, $i, $indic->get($parname, $i))
      if ($indic->is_available($parname, $i));