OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
ATable.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: ATable.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.3 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: ATable
10 // Expression class. Generates a list of values from a TABLE() function.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2002/01/22 15:16:02 $
15 // $Author: jsberg $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "Expressions/ATable.h"
20 
21 #include <iostream>
22 
23 
24 // Class ATable
25 // ------------------------------------------------------------------------
26 
27 namespace Expressions {
28 
29  ATable::ATable(const ATable &rhs):
30  OArray<double>(rhs), itsExpr(rhs.itsExpr),
31  itsBegin(rhs.itsBegin), itsEnd(rhs.itsEnd), itsStep(rhs.itsEnd)
32  {}
33 
34 
35  ATable::ATable(int n1, int n2, int n3):
36  OArray<double>(), itsExpr(), itsBegin(n1), itsEnd(n2), itsStep(n3)
37  {}
38 
39 
41  {}
42 
43 
45  return new ATable(*this);
46  }
47 
48 
50  itsExpr = expr;
51  }
52 
53 
54  std::vector<double> ATable::evaluate() const {
55  std::vector<double> result(itsEnd, 0.0);
56 
57  for(itsHash = itsBegin; itsHash <= itsEnd; itsHash += itsStep) {
58  result[itsHash-1] = itsExpr->evaluate();
59  }
60 
61  return result;
62  }
63 
64 
65  double ATable::getHash() const {
66  return itsHash;
67  }
68 
69 
70  void ATable::print(std::ostream &os, int) const {
71  os << "TABLE(" << itsBegin << ':' << itsEnd << ':' << itsStep << ',';
72  itsExpr->print(os);
73  os << ')';
74  return;
75  }
76 
77 }
Representation objects and parsers for attribute expressions.
Definition: Expressions.h:64
An array expression.
Definition: Expressions.h:142
An array expression generated from a TABLE() function.
Definition: ATable.h:38
virtual OArray< double > * clone() const
Make clone.
Definition: ATable.cpp:44
void defineExpression(PtrToScalar< double >)
Store the generating expression.
Definition: ATable.cpp:49
virtual std::vector< double > evaluate() const
Evaluate.
Definition: ATable.cpp:54
virtual void print(std::ostream &os, int precedence=99) const
Print expression.
Definition: ATable.cpp:70
PtrToScalar< double > itsExpr
Definition: ATable.h:73
double getHash() const
Return the current value of '#'.
Definition: ATable.cpp:65