OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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
28 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
37RealVector::RealVector(const std::string& name, RealVector* parent)
38 : ValueDefinition(name, parent) {}
39
41
43 // Replace only by another vector.
44 return (dynamic_cast<RealVector*>(object) != 0);
45}
46
47RealVector* RealVector::clone(const std::string& name) { return new RealVector(name, this); }
48
49void RealVector::print(std::ostream& os) const {
50 // WARNING: Cannot print in OPAL-8 format.
51 os << "REAL VECTOR " << getOpalName() << ":=" << itsAttr[0] << ';' << std::endl;
52}
53
54void RealVector::printValue(std::ostream& os) const { os << itsAttr[0]; }
55
56double RealVector::getRealComponent(int index) const {
57 std::vector<double> array = Attributes::getRealArray(itsAttr[0]);
58 return array[index - 1];
59}
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
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:210
virtual bool canReplaceBy(Object *rhs)
Test for allowed replacement.
virtual double getRealComponent(int) const
Return indexed value.
virtual RealVector * clone(const std::string &name)
Make clone.
virtual ~RealVector()
virtual void print(std::ostream &) const
Print the vector.
RealVector()
Exemplar constructor.
virtual void printValue(std::ostream &os) const
Print its value.
The base class for all OPAL value definitions.
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
std::vector< double > getRealArray(const Attribute &attr)
Get array value.