OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
Attribute.cpp
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2// $RCSfile: Attribute.cpp,v $
3// ------------------------------------------------------------------------
4// $Revision: 1.3.4.1 $
5// ------------------------------------------------------------------------
6// Copyright: see Copyright.readme
7// ------------------------------------------------------------------------
8//
9// Class Attribute:
10// Interface a polymorphic attribute, including its parser.
11//
12// ------------------------------------------------------------------------
13//
14// $Date: 2002/12/09 15:06:07 $
15// $Author: jsberg $
16//
17// ------------------------------------------------------------------------
18
21#include "Utilities/Options.h"
22
23#include "Utility/Inform.h"
24
25#include <iostream>
26#include <set>
27
28extern Inform* gmsg;
29
30// Class Attribute
31// ------------------------------------------------------------------------
32
33Attribute::Attribute() : base(nullptr), handler(), isDefault(true) {}
34
36 : base(rhs.base), handler(rhs.handler), isDefault(rhs.isDefault) {}
37
39 : base(b), handler(h), isDefault(true) {}
40
42
44 if (&rhs != this) {
45 base = std::shared_ptr<AttributeBase>(rhs.base);
46 handler = std::shared_ptr<AttributeHandler>(rhs.handler);
47 }
48
49 return *this;
50}
51
53
54bool Attribute::isBaseAllocated() const { return base != nullptr; }
55
57
58const std::string& Attribute::getHelp() const { return handler->getHelp(); }
59
60std::string Attribute::getImage() const { return base->getImage(); }
61
62const std::string& Attribute::getName() const { return handler->getName(); }
63
64const std::string& Attribute::getType() const { return handler->getType(); }
65
66bool Attribute::isDeferred() const { return handler->isDeferred(); }
67
68void Attribute::setDeferred(bool flag) { handler->setDeferred(flag); }
69
70bool Attribute::isExpression() const { return base->isExpression(); }
71
72bool Attribute::isReadOnly() const { return handler->isReadOnly(); }
73
74void Attribute::setReadOnly(bool flag) { handler->setReadOnly(flag); }
75
76void Attribute::parse(Statement& stat, bool eval) {
77 handler->parse(*this, stat, eval);
78 isDefault = false;
79}
80
81void Attribute::parseComponent(Statement& stat, bool eval, int index) {
82 handler->parseComponent(*this, stat, eval, index);
83 isDefault = false;
84}
85
87 base = std::shared_ptr<AttributeBase>(newBase);
88 isDefault = false;
89}
90
92 base = std::shared_ptr<AttributeBase>(handler->getDefault());
93 isDefault = true;
94}
95
96void Attribute::print(int& pos) const {
97 if (*this) {
98 std::string name = getName();
99 std::string image = getImage();
100 int step = name.length() + image.length() + 2;
101 pos += step;
102
103 if (pos > 74) {
104 *gmsg << ',' << endl << " ";
105 pos = step + 2;
106 } else {
107 *gmsg << ',';
108 }
109 *gmsg << name << (isExpression() ? ":=" : "=") << image;
110 }
111}
112
113std::ostream& operator<<(std::ostream& os, const Attribute& attr) {
114 if (attr) {
115 attr.getBase().print(os);
116 } else {
117 os << "*undefined*";
118 }
119
120 return os;
121}
std::ostream & operator<<(std::ostream &os, const Attribute &attr)
Inform * gmsg
Definition changes.cpp:7
Inform * gmsg
Definition changes.cpp:7
Abstract base class for attribute values of different types.
virtual void print(std::ostream &) const =0
Print value.
Abstract base class for attribute parsers.
virtual const std::string & getHelp() const
Return help string.
A representation of an Object attribute.
Definition Attribute.h:52
void setDeferred(bool)
Set read-only flag.
Definition Attribute.cpp:68
std::shared_ptr< AttributeBase > base
Definition Attribute.h:155
void print(int &len) const
Print attribute.
Definition Attribute.cpp:96
AttributeBase & getBase() const
Return reference to polymorphic value.
Definition Attribute.cpp:52
const std::string & getName() const
Return the attribute name.
Definition Attribute.cpp:62
void setDefault()
Assign default value.
Definition Attribute.cpp:91
void parse(Statement &stat, bool eval)
Parse attribute.
Definition Attribute.cpp:76
bool isExpression() const
Test for expression.
Definition Attribute.cpp:70
void set(AttributeBase *newBase)
Define new value.
Definition Attribute.cpp:86
void parseComponent(Statement &stat, bool eval, int index)
Parse array component.
Definition Attribute.cpp:81
const std::string & getHelp() const
Return the help string.
Definition Attribute.cpp:58
bool isDeferred() const
Return [b]deferred[/b] flag.
Definition Attribute.cpp:66
Attribute()
Default constructor.
Definition Attribute.cpp:33
std::shared_ptr< AttributeHandler > handler
Definition Attribute.h:158
const std::string & getType() const
Return the attribute type.
Definition Attribute.cpp:64
bool isBaseAllocated() const
Definition Attribute.cpp:54
std::string getImage() const
Return printable representation.
Definition Attribute.cpp:60
bool isDefault
Definition Attribute.h:160
AttributeHandler & getHandler() const
Return a reference to the parser.
Definition Attribute.cpp:56
bool isReadOnly() const
Test for read only.
Definition Attribute.cpp:72
void setReadOnly(bool)
Set read-only flag.
Definition Attribute.cpp:74
const Attribute & operator=(const Attribute &)
Definition Attribute.cpp:43
Interface for statements.
Definition Statement.h:37