OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
Real.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: Real.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.2 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class Real:
10 // A class used to parse real attributes.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/12/15 10:08:28 $
15 // $Author: opal $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "Attributes/Real.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 Real
36 // ------------------------------------------------------------------------
37 
38 namespace Attributes {
39 
40  Real::Real(const std::string &name, const std::string &help):
41  AttributeHandler(name, help, 0)
42  {}
43 
44 
46  {}
47 
48 
49  const std::string &Real::getType() const {
50  static const std::string type("real");
51  return type;
52  }
53 
54 
55  void Real::parse(Attribute &attr, Statement &statement, bool eval) const {
56  PtrToScalar<double> expr = parseReal(statement);
57 
58  if(eval || expr->isConstant()) {
59  attr.set(new SValue<double>(expr->evaluate()));
60  } else if(isDeferred()) {
61  attr.set(new SDeferred<double>(expr));
62  } else {
63  attr.set(new SAutomatic<double>(expr));
64  }
65  }
66 
67 };
virtual const std::string & getType() const
Return attribute type string ``real&#39;&#39;.
Definition: Real.cpp:49
void set(AttributeBase *newBase)
Define new value.
Definition: Attribute.cpp:137
PtrToScalar< double > parseReal(Statement &)
Parse real expression.
Object attribute with a ``deferred&#39;&#39; scalar value.
Definition: SDeferred.h:39
virtual ~Real()
Definition: Real.cpp:45
A representation of an Object attribute.
Definition: Attribute.h:55
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.
bool isDeferred() const
Return defer flag.
Object attribute with a constant scalar value.
Definition: SValue.h:34
const std::string name
virtual void parse(Attribute &, Statement &, bool) const
Parse the attribute.
Definition: Real.cpp:55
Inform & endl(Inform &inf)
Definition: Inform.cpp:42