OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
RealVector.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: RealVector.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: RealVector
10 // Implements a OPAL REAL_VECTOR definition.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:49 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
20 #include "Attributes/Attributes.h"
21 #include "Utilities/Options.h"
22 #include <iostream>
23 #include <vector>
24 
25 
26 // Class RealVector
27 // ------------------------------------------------------------------------
28 
30  ValueDefinition(1, "REAL_VECTOR",
31  "The \"REAL VECTOR\" statement defines a global "
32  "real vector.\n"
33  "\tREAL VECTOR<name>=<real-vector-expression>;\n") {
34  itsAttr[0] = Attributes::makeRealArray("VALUE", "The vector value");
35 
37 }
38 
39 
40 RealVector::RealVector(const std::string &name, RealVector *parent):
41  ValueDefinition(name, parent)
42 {}
43 
44 
46 {}
47 
48 
50  // Replace only by another vector.
51  return (dynamic_cast<RealVector *>(object) != 0);
52 }
53 
54 
55 RealVector *RealVector::clone(const std::string &name) {
56  return new RealVector(name, this);
57 }
58 
59 
60 void RealVector::print(std::ostream &os) const {
61  // WARNING: Cannot print in OPAL-8 format.
62  os << "REAL VECTOR " << getOpalName() << ":="
63  << itsAttr[0] << ';' << std::endl;
64 }
65 
66 void RealVector::printValue(std::ostream &os) const {
67  os << itsAttr[0];
68 }
69 
70 double RealVector::getRealComponent(int index) const {
71  std::vector<double> array = Attributes::getRealArray(itsAttr[0]);
72  return array[index-1];
73 }
The REAL VECTOR definition.
Definition: RealVector.h:27
virtual ~RealVector()
Definition: RealVector.cpp:45
RealVector()
Exemplar constructor.
Definition: RealVector.cpp:29
virtual bool canReplaceBy(Object *rhs)
Test for allowed replacement.
Definition: RealVector.cpp:49
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:284
virtual RealVector * clone(const std::string &name)
Make clone.
Definition: RealVector.cpp:55
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:194
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
Definition: Attributes.cpp:258
virtual void printValue(std::ostream &os) const
Print its value.
Definition: RealVector.cpp:66
virtual double getRealComponent(int) const
Return indexed value.
Definition: RealVector.cpp:70
The base class for all OPAL objects.
Definition: Object.h:48
The base class for all OPAL value definitions.
const std::string name
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
Definition: Attributes.cpp:253
virtual void print(std::ostream &) const
Print the vector.
Definition: RealVector.cpp:60
Inform & endl(Inform &inf)
Definition: Inform.cpp:42