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