OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
BoolArray.cpp
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2// $RCSfile: BoolArray.cpp,v $
3// ------------------------------------------------------------------------
4// $Revision: 1.1.1.1 $
5// ------------------------------------------------------------------------
6// Copyright: see Copyright.readme
7// ------------------------------------------------------------------------
8//
9// Class BoolArray:
10// A class used to parse boolean array attributes.
11//
12// ------------------------------------------------------------------------
13//
14// $Date: 2000/03/27 09:33:36 $
15// $Author: Andreas Adelmann $
16//
17// ------------------------------------------------------------------------
18
24#include "Expressions/AList.h"
27#include <vector>
28
29using namespace Expressions;
30
31
32// Class BoolArray
33// ------------------------------------------------------------------------
34
35namespace Attributes {
36
37 BoolArray::BoolArray(const std::string &name, const std::string &help):
38 AttributeHandler(name, help, 0)
39 {}
40
41
43 {}
44
45
46 const std::string &BoolArray::getType() const {
47 static std::string type = "logical array";
48 return type;
49 }
50
51
52 void BoolArray::parse(Attribute &attr, Statement &stat, bool eval) const {
54
55 if(eval) {
56 // Use ADeferred here, since a component may be overridden later
57 // by an expression.
58 attr.set(new ADeferred<bool>(expr->evaluate()));
59 } else if(is_deferred) {
60 attr.set(new ADeferred<bool>(expr));
61 } else {
62 attr.set(new AAutomatic<bool>(expr));
63 }
64 }
65
66
68 (Attribute &attr, Statement &stat, bool eval, int index) const {
69 ADeferred<bool> *array = 0;
70
71 if(AttributeBase *base = &(attr.getBase())) {
72 array = dynamic_cast<ADeferred<bool>*>(base);
73 } else {
74 attr.set(array = new ADeferred<bool>());
75 }
76
77 PtrToScalar<bool> expr = parseBool(stat);
78 if(eval) expr = new SConstant<bool>(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< bool > parseBool(Statement &)
Parse boolean expression.
PtrToArray< bool > parseBoolArray(Statement &)
Parse boolean 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 a scalar expression.
Definition: Expressions.h:109
A pointer to an array expression.
Definition: Expressions.h:180
virtual const std::string & getType() const
Return attribute type string `‘logical array’'.
Definition: BoolArray.cpp:46
virtual void parseComponent(Attribute &, Statement &, bool, int) const
Parse a component of the array.
Definition: BoolArray.cpp:68
virtual void parse(Attribute &, Statement &, bool) const
Parse the attribute.
Definition: BoolArray.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