OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
Bool.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: Bool.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class Attributes::Bool
10 // A class used to parse boolean attributes.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:36 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "Attributes/Bool.h"
21 #include "Expressions/SAutomatic.h"
22 #include "Expressions/SDeferred.h"
23 #include "Expressions/SValue.h"
24 #include "Parser/SimpleStatement.h"
25 #include "Parser/StringStream.h"
26 #include "Parser/Token.h"
28 #include "Utilities/ParseError.h"
29 
30 using namespace Expressions;
31 using std::cerr;
32 using std::endl;
33 
34 
35 // Class Attributes::Bool
36 // ------------------------------------------------------------------------
37 
38 namespace Attributes {
39 
40  Bool::Bool(const std::string &name, const std::string &help):
41  AttributeHandler(name, help, new SValue<bool>(true))
42  {}
43 
44 
46  {}
47 
48  const std::string &Bool::getType() const {
49  static const std::string type("logical");
50  return type;
51  }
52 
53  void Bool::parse(Attribute &attr, Statement &stat, bool eval) const {
54  PtrToScalar<bool> expr = parseBool(stat);
55 
56  if(eval || expr->isConstant()) {
57  attr.set(new SValue<bool>(expr->evaluate()));
58  } else if(is_deferred) {
59  attr.set(new SDeferred<bool>(expr));
60  } else {
61  attr.set(new SAutomatic<bool>(expr));
62  }
63  }
64 
65 };
void set(AttributeBase *newBase)
Define new value.
Definition: Attribute.cpp:137
virtual ~Bool()
Definition: Bool.cpp:45
virtual void parse(Attribute &, Statement &, bool) const
Parse the attribute.
Definition: Bool.cpp:53
A pointer to a scalar expression.
Definition: Expressions.h:116
bool is_deferred
Defer flag.
Object attribute with a ``deferred&#39;&#39; scalar value.
Definition: SDeferred.h:39
PtrToScalar< bool > parseBool(Statement &)
Parse boolean expression.
A representation of an Object attribute.
Definition: Attribute.h:55
virtual const std::string & getType() const
Return attribute type string ``logical&#39;&#39;.
Definition: Bool.cpp:48
Object attribute with an ``automatic&#39;&#39; scalar value.
Definition: SAutomatic.h:38
Interface for statements.
Definition: Statement.h:38
Abstract base class for attribute parsers.
Object attribute with a constant scalar value.
Definition: SValue.h:34
const std::string name
Inform & endl(Inform &inf)
Definition: Inform.cpp:42