OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
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 };
const std::string name
Representation objects and parsers for attribute expressions.
Definition: Expressions.h:64
PtrToScalar< double > parseReal(Statement &)
Parse real expression.
PtrToArray< double > parseRealArray(Statement &)
Parse real array expression.
A collection of routines to construct object Attributes and retrieve.
Definition: Attributes.cpp:85
boost::function< boost::tuple< double, bool >arguments_t)> type
Definition: function.hpp:21
A representation of an Object attribute.
Definition: Attribute.h:52
AttributeBase & getBase() const
Return reference to polymorphic value.
Definition: Attribute.cpp:69
void set(AttributeBase *newBase)
Define new value.
Definition: Attribute.cpp:139
Abstract base class for attribute values of different types.
Definition: AttributeBase.h:32
Abstract base class for attribute parsers.
bool is_deferred
Defer flag.
A pointer to an array expression.
Definition: Expressions.h:180
virtual const std::string & getType() const
Return attribute type string `‘real array’'.
Definition: RealArray.cpp:46
virtual void parseComponent(Attribute &, Statement &, bool, int) const
Parse a component of the array.
Definition: RealArray.cpp:68
virtual void parse(Attribute &, Statement &, bool) const
Parse the attribute.
Definition: RealArray.cpp:52
Interface for statements.
Definition: Statement.h:38
Object attribute with an `‘automatic’' array value.
Definition: AAutomatic.h:39
Object attribute with a `‘deferred’' array value.
Definition: ADeferred.h:40
void setComponent(int i, const PtrToScalar< T > expr)
Set a component of the value.
Definition: ADeferred.h:243
A scalar constant expression.
Definition: SConstant.h:35