OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
RealVariable.cpp
Go to the documentation of this file.
1//
2// Class RealVariable
3// The REAL VARIABLE definition.
4//
5// Copyright (c) 2000 - 2021, Paul Scherrer Institut, Villigen PSI, Switzerland
6// All rights reserved
7//
8// This file is part of OPAL.
9//
10// OPAL is free software: you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// You should have received a copy of the GNU General Public License
16// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17//
19
22
23#include <iostream>
24
25
27 ValueDefinition(1, "REAL_VARIABLE",
28 "The \"REAL VARIABLE\" statement defines a global "
29 "real variable:\n"
30 "\tREAL VARIABLE <name>=<real-expression>;\n") {
31 itsAttr[0] = Attributes::makeReal("VALUE", "The variable value", 0.0);
32
34
35 // Construct the P0 variable.
36 RealVariable *p0 = new RealVariable("P0", this, 1.0);
38 p0->setDirty(true);
40}
41
42
43RealVariable::RealVariable(const std::string &name, RealVariable *parent,
44 double value):
45 ValueDefinition(name, parent) {
47}
48
49
50RealVariable::RealVariable(const std::string &name, RealVariable *parent):
51 ValueDefinition(name, parent)
52{}
53
54
56{}
57
58
60 // Replace only by another variable.
61 return (dynamic_cast<RealVariable *>(object) != 0);
62}
63
64
66 return new RealVariable(name, this);
67}
68
69
70double RealVariable::getReal() const {
72}
73
74
75void RealVariable::print(std::ostream &os) const {
76 os << "REAL " << getOpalName()
77 << (itsAttr[0].isExpression() ? ":=" : "=") << itsAttr[0] << ';';
78 os << std::endl;
79}
80
81void RealVariable::printValue(std::ostream &os) const {
82 os << itsAttr[0];
83}
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
const std::string name
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
void setReal(Attribute &attr, double val)
Set real value.
Definition: Attributes.cpp:271
The base class for all OPAL objects.
Definition: Object.h:48
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:191
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:310
void setDirty(bool)
Set/reset the [b]modified[/b] flag.
Definition: Object.cpp:283
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
void setP0(ValueDefinition *p0)
Set the global momentum.
Definition: OpalData.cpp:641
void create(Object *newObject)
Create new object.
Definition: OpalData.cpp:476
static OpalData * getInstance()
Definition: OpalData.cpp:196
The base class for all OPAL value definitions.
Attribute & value()
Return the attribute representing the value of the definition.
virtual RealVariable * clone(const std::string &name)
Make clone.
virtual void print(std::ostream &) const
Print the variable.
virtual void printValue(std::ostream &os) const
Print its value.
RealVariable()
Exemplar constructor.
virtual ~RealVariable()
virtual double getReal() const
Return value.
virtual bool canReplaceBy(Object *rhs)
Test for allowed replacement.