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