OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
Value.cpp
Go to the documentation of this file.
1//
2// Class Value
3// The class for OPAL VALUE command.
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//
18#include "BasicActions/Value.h"
19
21#include "Parser/Statement.h"
22#include "Utility/Inform.h"
23
24#include <string>
25#include <vector>
26
27
28extern Inform* gmsg;
29
31 Action(1, "VALUE",
32 "The \"VALUE\" statement prints a list of expressions and "
33 "their values.") {
35 ("VALUE", "The values to be evaluated");
36
38}
39
40
41Value::Value(const std::string& name, Value* parent):
42 Action(name, parent)
43{}
44
45
47{}
48
49
50Value* Value::clone(const std::string& name) {
51 return new Value(name, this);
52}
53
54
56 *gmsg << "\nvalue: " << itsAttr[0] << " = {";
57 // std::streamsize old_prec = *gmsg.precision(12);
58 const std::vector<double> array = Attributes::getRealArray(itsAttr[0]);
59 std::vector<double>::const_iterator i = array.begin();
60
61 while (i != array.end()) {
62 *gmsg << *i++;
63 if (i == array.end()) break;
64 *gmsg << ", ";
65 }
66
67 *gmsg << "}\n" << endl;
68 // *gmsg.precision(old_prec);
69}
70
71void Value::parse(Statement& statement) {
72 // parse, but don't evaluate (for printing mainly)
73 parseShortcut(statement, false);
74}
Inform * gmsg
Definition: Main.cpp:61
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
const std::string name
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
Definition: Attributes.cpp:289
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
Definition: Attributes.cpp:294
The base class for all OPAL actions.
Definition: Action.h:30
virtual void parseShortcut(Statement &, bool eval=true)
Parser for single-attribute commands.
Definition: Object.cpp:129
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:191
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
Definition: Value.h:24
virtual ~Value()
Definition: Value.cpp:46
virtual void parse(Statement &)
Parse command (special for one-attribute command).
Definition: Value.cpp:71
virtual void execute()
Execute the command.
Definition: Value.cpp:55
Value()
Exemplar constructor.
Definition: Value.cpp:30
virtual Value * clone(const std::string &name)
Make clone.
Definition: Value.cpp:50
Interface for statements.
Definition: Statement.h:38
Definition: Inform.h:42