OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
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 };
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
const std::string name
Representation objects and parsers for attribute expressions.
Definition: Expressions.h:64
PtrToScalar< bool > parseBool(Statement &)
Parse boolean 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
void set(AttributeBase *newBase)
Define new value.
Definition: Attribute.cpp:139
Abstract base class for attribute parsers.
bool is_deferred
Defer flag.
A pointer to a scalar expression.
Definition: Expressions.h:109
virtual const std::string & getType() const
Return attribute type string `‘logical’'.
Definition: Bool.cpp:48
virtual ~Bool()
Definition: Bool.cpp:45
virtual void parse(Attribute &, Statement &, bool) const
Parse the attribute.
Definition: Bool.cpp:53
Interface for statements.
Definition: Statement.h:38
Object attribute with an `‘automatic’' scalar value.
Definition: SAutomatic.h:38
Object attribute with a `‘deferred’' scalar value.
Definition: SDeferred.h:39
Object attribute with a constant scalar value.
Definition: SValue.h:34