OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
RealArray.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: RealArray.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class RealArray:
10 // A class used to parse real array attributes.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:36 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "Attributes/RealArray.h"
20 #include "Attributes/Attributes.h"
22 #include "Expressions/AAutomatic.h"
23 #include "Expressions/ADeferred.h"
24 #include "Expressions/AList.h"
25 #include "Expressions/SConstant.h"
27 #include <vector>
28 
29 using namespace Expressions;
30 
31 
32 // Class RealArray
33 // ------------------------------------------------------------------------
34 
35 namespace Attributes {
36 
37  RealArray::RealArray(const std::string &name, const std::string &help):
38  AttributeHandler(name, help, 0)
39  {}
40 
41 
43  {}
44 
45 
46  const std::string &RealArray::getType() const {
47  static std::string type = "real array";
48  return type;
49  }
50 
51 
52  void RealArray::parse(Attribute &attr, Statement &statement, bool eval) const {
53  PtrToArray<double> expr = parseRealArray(statement);
54 
55  if(eval) {
56  // Use ADeferred here, since a component may be overridden later
57  // by an expression.
58  attr.set(new ADeferred<double>(expr->evaluate()));
59  } else if(is_deferred) {
60  attr.set(new ADeferred<double>(expr));
61  } else {
62  attr.set(new AAutomatic<double>(expr));
63  }
64  }
65 
66 
68  (Attribute &attr, Statement &stat, bool eval, int index) const {
69  ADeferred<double> *array = 0;
70 
71  if(AttributeBase *base = &(attr.getBase())) {
72  array = dynamic_cast<ADeferred<double>*>(base);
73  } else {
74  attr.set(array = new ADeferred<double>());
75  }
76 
77  PtrToScalar<double> expr = parseReal(stat);
78  if(eval) expr = new SConstant<double>(expr->evaluate());
79  array->setComponent(index, expr);
80  }
81 
82 };
void set(AttributeBase *newBase)
Define new value.
Definition: Attribute.cpp:137
Abstract base class for attribute values of different types.
Definition: AttributeBase.h:32
A scalar constant expression.
Definition: SConstant.h:35
PtrToScalar< double > parseReal(Statement &)
Parse real expression.
bool is_deferred
Defer flag.
void setComponent(int i, const PtrToScalar< T > expr)
Set a component of the value.
Definition: ADeferred.h:243
virtual void parse(Attribute &, Statement &, bool) const
Parse the attribute.
Definition: RealArray.cpp:52
A representation of an Object attribute.
Definition: Attribute.h:55
virtual const std::string & getType() const
Return attribute type string ``real array&#39;&#39;.
Definition: RealArray.cpp:46
Interface for statements.
Definition: Statement.h:38
Abstract base class for attribute parsers.
Object attribute with a ``deferred&#39;&#39; array value.
Definition: ADeferred.h:40
PtrToArray< double > parseRealArray(Statement &)
Parse real array expression.
const std::string name
virtual std::vector< T > evaluate() const =0
Evaluate.
virtual void parseComponent(Attribute &, Statement &, bool, int) const
Parse a component of the array.
Definition: RealArray.cpp:68
A pointer to an array expression.
Definition: Expressions.h:186
AttributeBase & getBase() const
Return reference to polymorphic value.
Definition: Attribute.cpp:67
Object attribute with an ``automatic&#39;&#39; array value.
Definition: AAutomatic.h:39