OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
Attribute.h
Go to the documentation of this file.
1#ifndef OPAL_Attribute_HH
2#define OPAL_Attribute_HH
3
4// ------------------------------------------------------------------------
5// $RCSfile: Attribute.h,v $
6// ------------------------------------------------------------------------
7// $Revision: 1.1.1.1 $
8// ------------------------------------------------------------------------
9// Copyright: see Copyright.readme
10// ------------------------------------------------------------------------
11//
12// Class Attribute:
13//
14// ------------------------------------------------------------------------
15//
16// $Date: 2000/03/27 09:33:34 $
17// $Author: Andreas Adelmann $
18//
19// ------------------------------------------------------------------------
20
21#include <cstring>
22#include <iosfwd>
23#include <memory>
26
27class Statement;
28
29// Class Attribute
30// ------------------------------------------------------------------------
32// Contains a pointer [b]base[/b] to the polymorphic attribute value,
33// derived from [b]AttributeBase[/b], and a pointer [b]handler[/b] to
34// the polymorphic attribute parser, derived from [b]AttributeHandler[/b].
35//
36// The type of the attribute is determined by the class of AttributeHandler
37// attached. The attribute handler must be set for all attributes by the
38// exemplar constructor for a command object. The clone constructor does
39// not copy the handlers, but it creates new references to the same handlers.
40//
41// The value is stored in the object pointed at by base. An object can be
42// created for the default value of an attribute by the exemplar constructor,
43// or it can be null, meaning an as yet undefined value. The validity of
44// the pointer can be tested by the method Attribute::isValid().
45//
46// Each OPAL command object (derived from class Object) has a
47// vector<Attribute> containing the command attributes read by the parser.
48// This attribute vector is first filled by the clone constructor of the
49// command class by copying the pointers in the model, and possibly by the
50// OPAL parser with the values given by the user.
51
52class Attribute {
53public:
55 // Leaves both pointers [b]nullptr[/b].
56 // An object constructed by the default constructor must be initialized
57 // using assignment before it can be used.
58 // Failing to do so may cause a program crash.
59 Attribute();
60
62 // Both value and parser are shared with [b]rhs[/b].
63 Attribute(const Attribute& rhs);
64
66 // The default value is ``undefined''.
68
69 ~Attribute();
70 const Attribute& operator=(const Attribute&);
71
73 // Returns true, when the value is defined (non-null pointer).
74 operator bool() const;
75
77 AttributeBase& getBase() const;
78
79 bool isBaseAllocated() const;
80
82 // This string duplicates the input expression defining the attribute.
83 std::string getImage() const;
84
87
89 // This string is stored in the parser object.
90 const std::string& getHelp() const;
91
93 // This string is stored in the parser object.
94 const std::string& getName() const;
95
97 // This string ("real", "logical", etc.) is stored in the parser object.
98 const std::string& getType() const;
99
101 // If this flag is set, any expression is re-evaluated each time the
102 // value is fetched. Normally attribute evaluation is not deferred,
103 // i. e. any expression is evaluated only the first time the value is
104 // fetched after a new definition has been read.
105 // See [b]Expressions::ADeferred[/b] and [b]Expressions::SDeferred[/b]
106 // for information.
107 bool isDeferred() const;
108
110 // If this flag is set, the attribute cannot be redefined by the user.
111 // See [b]Expressions::ADeferred[/b] and [b]Expressions::SDeferred[/b]
112 // for information.
113 void setDeferred(bool);
114
116 // Return true, if the attribute is defined as an expression.
117 bool isExpression() const;
118
120 // Return true, if the attribute cannot be redefined by the user.
121 bool isReadOnly() const;
122
124 // Set or reset the attribute's read-only flag.
125 void setReadOnly(bool);
126
128 // Use the contained parser to parse a new value for the attribute.
129 void parse(Statement& stat, bool eval);
130
132 // Use the contained parser to parse a new value for an existing
133 // vector component. If the attribute is a scalar value, or if the
134 // component does not exist, this method throws [b]OpalException[/b].
135 void parseComponent(Statement& stat, bool eval, int index);
136
138 // Assign a new value. The value must be compatible with the parser
139 // type, otherwise a [b]OpalException[/b] is thrown.
140 void set(AttributeBase* newBase);
141
143 // Set the attribute value to the default value stored in the parser.
144 // If no default value exists, set it to ``undefined''.
145 void setDefault();
146
148 // Print the attribute name, followed by an equals sign and its value.
149 void print(int& len) const;
150
151 bool defaultUsed() const;
152
153private:
154 // Pointer to the value. The value can be shared for several objects.
155 std::shared_ptr<AttributeBase> base;
156
157 // Pointer to the shared attribute parser.
158 std::shared_ptr<AttributeHandler> handler;
159
161};
162
163// Class Attribute
164// ------------------------------------------------------------------------
165
166inline Attribute::operator bool() const { return base != nullptr; }
167
168inline bool Attribute::defaultUsed() const { return isDefault; }
169
170extern std::ostream& operator<<(std::ostream& os, const Attribute& attr);
171
172#endif // OPAL_Attribute_HH
std::ostream & operator<<(std::ostream &os, const Attribute &attr)
Abstract base class for attribute values of different types.
Abstract base class for attribute parsers.
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
bool defaultUsed() const
Definition Attribute.h:168
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