OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
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 <set>
26 #include <iostream>
27 
28 extern Inform *gmsg;
29 
30 
31 // Class Attribute
32 // ------------------------------------------------------------------------
33 
35  base(nullptr),
36  handler(),
37  isDefault(true)
38 {}
39 
40 
42  base(rhs.base),
43  handler(rhs.handler),
44  isDefault(rhs.isDefault)
45 {}
46 
47 
49  base(b),
50  handler(h),
51  isDefault(true)
52 {}
53 
54 
56 {}
57 
58 
60  if(&rhs != this) {
61  base = rhs.base;
62  handler = rhs.handler;
63  }
64 
65  return *this;
66 }
67 
68 
70  return *base;
71 }
72 
74  return base != nullptr;
75 }
76 
78  return *handler;
79 }
80 
81 
82 const std::string &Attribute::getHelp() const {
83  return handler->getHelp();
84 }
85 
86 
87 std::string Attribute::getImage() const {
88  return base->getImage();
89 }
90 
91 
92 const std::string &Attribute::getName() const {
93  return handler->getName();
94 }
95 
96 
97 const std::string &Attribute::getType() const {
98  return handler->getType();
99 }
100 
101 
102 bool Attribute::isDeferred() const {
103  return handler->isDeferred();
104 }
105 
106 
107 void Attribute::setDeferred(bool flag) {
108  handler->setDeferred(flag);
109 }
110 
111 
113  return base->isExpression();
114 }
115 
116 
117 bool Attribute::isReadOnly() const {
118  return handler->isReadOnly();
119 }
120 
121 
122 void Attribute::setReadOnly(bool flag) {
123  handler->setReadOnly(flag);
124 }
125 
126 
127 void Attribute::parse(Statement &stat, bool eval) {
128  handler->parse(*this, stat, eval);
129  isDefault = false;
130 }
131 
132 
133 void Attribute::parseComponent(Statement &stat, bool eval, int index) {
134  handler->parseComponent(*this, stat, eval, index);
135  isDefault = false;
136 }
137 
138 
140  base = newBase;
141  isDefault = false;
142 }
143 
144 
146  base = handler->getDefault();
147  isDefault = true;
148 }
149 
150 
151 void Attribute::print(int &pos) const {
152  if(*this) {
153  std::string name = getName();
154  std::string image = getImage();
155  int step = name.length() + image.length() + 2;
156  pos += step;
157 
158  if(pos > 74) {
159  *gmsg << ',' << endl << " ";
160  pos = step + 2;
161  } else {
162  *gmsg << ',';
163  }
164  *gmsg << name << (isExpression() ? ":=" : "=") << image;
165  }
166 }
167 
168 
169 std::ostream &operator<<(std::ostream &os, const Attribute &attr) {
170  if(attr) {
171  attr.getBase().print(os);
172  } else {
173  os << "*undefined*";
174  }
175 
176  return os;
177 }
std::ostream & operator<<(std::ostream &os, const Attribute &attr)
Definition: Attribute.cpp:169
Inform * gmsg
Definition: Main.cpp:62
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
const std::string name
A representation of an Object attribute.
Definition: Attribute.h:52
void setDeferred(bool)
Set read-only flag.
Definition: Attribute.cpp:107
void print(int &len) const
Print attribute.
Definition: Attribute.cpp:151
AttributeBase & getBase() const
Return reference to polymorphic value.
Definition: Attribute.cpp:69
const std::string & getName() const
Return the attribute name.
Definition: Attribute.cpp:92
void setDefault()
Assign default value.
Definition: Attribute.cpp:145
void parse(Statement &stat, bool eval)
Parse attribute.
Definition: Attribute.cpp:127
bool isExpression() const
Test for expression.
Definition: Attribute.cpp:112
void set(AttributeBase *newBase)
Define new value.
Definition: Attribute.cpp:139
void parseComponent(Statement &stat, bool eval, int index)
Parse array component.
Definition: Attribute.cpp:133
const std::string & getHelp() const
Return the help string.
Definition: Attribute.cpp:82
bool isDeferred() const
Return [b]deferred[/b] flag.
Definition: Attribute.cpp:102
Attribute()
Default constructor.
Definition: Attribute.cpp:34
Pointer< AttributeHandler > handler
Definition: Attribute.h:160
const std::string & getType() const
Return the attribute type.
Definition: Attribute.cpp:97
bool isBaseAllocated() const
Definition: Attribute.cpp:73
std::string getImage() const
Return printable representation.
Definition: Attribute.cpp:87
bool isDefault
Definition: Attribute.h:162
AttributeHandler & getHandler() const
Return a reference to the parser.
Definition: Attribute.cpp:77
bool isReadOnly() const
Test for read only.
Definition: Attribute.cpp:117
void setReadOnly(bool)
Set read-only flag.
Definition: Attribute.cpp:122
Pointer< AttributeBase > base
Definition: Attribute.h:157
const Attribute & operator=(const Attribute &)
Definition: Attribute.cpp:59
Abstract base class for attribute values of different types.
Definition: AttributeBase.h:32
virtual bool isExpression() const
Test for expression.
std::string getImage() const
Convert to string.
virtual void print(std::ostream &) const =0
Print value.
Abstract base class for attribute parsers.
void setDeferred(bool)
Set or reset defer flag.
virtual AttributeBase * getDefault() const
Return default value.
bool isDeferred() const
Return defer flag.
void setReadOnly(bool)
Set or reset read-only flag.
virtual const std::string & getType() const =0
Return attribute type.
virtual const std::string & getName() const
Return attribute name.
virtual const std::string & getHelp() const
Return help string.
virtual void parseComponent(Attribute &a, Statement &s, bool eval, int i) const
Parse component value.
bool isReadOnly() const
Return read-only flag.
virtual void parse(Attribute &a, Statement &s, bool eval) const =0
Parse new value.
Interface for statements.
Definition: Statement.h:38
Definition: Inform.h:42