OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
RealVariable.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: RealVariable.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.3 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: RealVariable
10 // Implements a OPAL REAL_VARIABLE definition.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2001/08/13 15:26:42 $
15 // $Author: jowett $
16 //
17 // ------------------------------------------------------------------------
18 
21 #include "Attributes/Attributes.h"
22 #include <iostream>
23 
24 
25 // Class RealVariable
26 // ------------------------------------------------------------------------
27 
29  ValueDefinition(1, "REAL_VARIABLE",
30  "The \"REAL VARIABLE\" statement defines a global "
31  "real variable:\n"
32  "\tREAL VARIABLE <name>=<real-expression>;\n") {
33  itsAttr[0] = Attributes::makeReal("VALUE", "The variable value", 0.0);
34 
36 
37  // Construct the P0 variable.
38  RealVariable *p0 = new RealVariable("P0", this, 1.0);
40  p0->setDirty(true);
42 }
43 
44 
45 RealVariable::RealVariable(const std::string &name, RealVariable *parent,
46  double value):
47  ValueDefinition(name, parent) {
48  Attributes::setReal(itsAttr[0], value);
49 }
50 
51 
52 RealVariable::RealVariable(const std::string &name, RealVariable *parent):
53  ValueDefinition(name, parent)
54 {}
55 
56 
58 {}
59 
60 
62  // Replace only by another variable.
63  return (dynamic_cast<RealVariable *>(object) != 0);
64 }
65 
66 
67 RealVariable *RealVariable::clone(const std::string &name) {
68  return new RealVariable(name, this);
69 }
70 
71 
72 double RealVariable::getReal() const {
73  return Attributes::getReal(itsAttr[0]);
74 }
75 
76 
77 void RealVariable::print(std::ostream &os) const {
78  os << "REAL " << getOpalName()
79  << (itsAttr[0].isExpression() ? ":=" : "=") << itsAttr[0] << ';';
80  os << std::endl;
81 }
82 
83 void RealVariable::printValue(std::ostream &os) const {
84  os << itsAttr[0];
85 }
RealVariable()
Exemplar constructor.
void setReal(Attribute &attr, double val)
Set real value.
Definition: Attributes.cpp:236
virtual void printValue(std::ostream &os) const
Print its value.
void create(Object *newObject)
Create new object.
Definition: OpalData.cpp:524
virtual double getReal() const
Return value.
The REAL VARIABLE definition.
Definition: RealVariable.h:26
void setDirty(bool)
Set/reset the [b]modified[/b] flag.
Definition: Object.cpp:257
virtual bool canReplaceBy(Object *rhs)
Test for allowed replacement.
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
virtual ~RealVariable()
virtual void print(std::ostream &) const
Print the variable.
static OpalData * getInstance()
Definition: OpalData.cpp:209
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:284
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:194
virtual RealVariable * clone(const std::string &name)
Make clone.
The base class for all OPAL objects.
Definition: Object.h:48
The base class for all OPAL value definitions.
const std::string name
void setP0(ValueDefinition *p0)
Set the global momentum.
Definition: OpalData.cpp:691
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:205
Inform & endl(Inform &inf)
Definition: Inform.cpp:42