OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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
27 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
42RealVariable::RealVariable(const std::string& name, RealVariable* parent, double value)
43 : ValueDefinition(name, parent) {
45}
46
47RealVariable::RealVariable(const std::string& name, RealVariable* parent)
48 : ValueDefinition(name, parent) {}
49
51
53 // Replace only by another variable.
54 return (dynamic_cast<RealVariable*>(object) != 0);
55}
56
57RealVariable* RealVariable::clone(const std::string& name) { return new RealVariable(name, this); }
58
60
61void RealVariable::print(std::ostream& os) const {
62 os << "REAL " << getOpalName() << (itsAttr[0].isExpression() ? ":=" : "=") << itsAttr[0] << ';';
63 os << std::endl;
64}
65
66void RealVariable::printValue(std::ostream& os) const { os << itsAttr[0]; }
The base class for all OPAL objects.
Definition Object.h:45
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition Object.cpp:169
const std::string & getOpalName() const
Return object name.
Definition Object.cpp:267
void setDirty(bool)
Set/reset the [b]modified[/b] flag.
Definition Object.cpp:249
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:210
void setP0(ValueDefinition *p0)
Set the global momentum.
Definition OpalData.cpp:557
void create(Object *newObject)
Create new object.
Definition OpalData.cpp:387
static OpalData * getInstance()
Definition OpalData.cpp:193
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.
The base class for all OPAL value definitions.
Attribute & value()
Return the attribute representing the value of the definition.
double getReal(const Attribute &attr)
Return real value.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
void setReal(Attribute &attr, double val)
Set real value.