OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
RealVector.cpp
Go to the documentation of this file.
1//
2// Class RealVector
3// The REAL VECTOR 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
21#include "Utilities/Options.h"
22
23#include <iostream>
24#include <vector>
25
26
28 ValueDefinition(1, "REAL_VECTOR",
29 "The \"REAL VECTOR\" statement defines a global "
30 "real vector.\n"
31 "\tREAL VECTOR<name>=<real-vector-expression>;\n") {
32 itsAttr[0] = Attributes::makeRealArray("VALUE", "The vector value");
33
35}
36
37
38RealVector::RealVector(const std::string &name, RealVector *parent):
39 ValueDefinition(name, parent)
40{}
41
42
44{}
45
46
48 // Replace only by another vector.
49 return (dynamic_cast<RealVector *>(object) != 0);
50}
51
52
53RealVector *RealVector::clone(const std::string &name) {
54 return new RealVector(name, this);
55}
56
57
58void RealVector::print(std::ostream &os) const {
59 // WARNING: Cannot print in OPAL-8 format.
60 os << "REAL VECTOR " << getOpalName() << ":="
61 << itsAttr[0] << ';' << std::endl;
62}
63
64void RealVector::printValue(std::ostream &os) const {
65 os << itsAttr[0];
66}
67
68double RealVector::getRealComponent(int index) const {
69 std::vector<double> array = Attributes::getRealArray(itsAttr[0]);
70 return array[index-1];
71}
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 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
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
The base class for all OPAL value definitions.
virtual bool canReplaceBy(Object *rhs)
Test for allowed replacement.
Definition: RealVector.cpp:47
virtual double getRealComponent(int) const
Return indexed value.
Definition: RealVector.cpp:68
virtual RealVector * clone(const std::string &name)
Make clone.
Definition: RealVector.cpp:53
virtual ~RealVector()
Definition: RealVector.cpp:43
virtual void print(std::ostream &) const
Print the vector.
Definition: RealVector.cpp:58
RealVector()
Exemplar constructor.
Definition: RealVector.cpp:27
virtual void printValue(std::ostream &os) const
Print its value.
Definition: RealVector.cpp:64