OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
AttributeHandler.h
Go to the documentation of this file.
1#ifndef OPAL_AttributeHandler_HH
2#define OPAL_AttributeHandler_HH
3
4// ------------------------------------------------------------------------
5// $RCSfile: AttributeHandler.h,v $
6// ------------------------------------------------------------------------
7// $Revision: 1.1.1.1 $
8// ------------------------------------------------------------------------
9// Copyright: see Copyright.readme
10// ------------------------------------------------------------------------
11//
12// Class: AttributeHandler
13//
14// ------------------------------------------------------------------------
15//
16// $Date: 2000/03/27 09:33:34 $
17// $Author: Andreas Adelmann $
18//
19// ------------------------------------------------------------------------
20
23#include <memory.h>
24#include <cstring>
25#include <map>
26#include <set>
27#include <memory>
28#include <string>
29
30class Attribute;
31class Statement;
32
33
34// Class AttributeHandler
35// ------------------------------------------------------------------------
37// An attribute parser defines the data type for an attribute. It is
38// used to parse the attribute, to read the attribute from the DOOM data
39// base, and to write it to that data base. It contains the name and
40// help text for the attribute. Optionally it may also contain a default
41// value for the attribute.
42// [p]
43// When ``is_readonly'' is true, the attribute cannot be redefined by
44// the user.
45// [p]
46// When ``is_deferred'' is true, the attribute must be re-evaluated
47// whenever it is used. This is the case for random error values.
48// When ``is_deferred'' is false, any expression for the attribute is
49// cached. It is re-evaluated only when any other definition has changed.
50
52
53public:
54
56 // Assigns the attribute name [b]name[/b] and the help text [b]help[/b],
57 // as well as a possible default value [b]def[/b]for the attribute.
58 AttributeHandler(const std::string &name, const std::string &help, AttributeBase *def);
59
60 virtual ~AttributeHandler();
61
63 // Attribute handlers are always shared, so this method should never
64 // be called. It exists only to fulfill the requirements of the class
65 // [b]Pointer[/b].
66 virtual AttributeHandler *clone() const;
67
69 // Return the default value stored in this parser.
70 virtual AttributeBase *getDefault() const;
71
73 virtual const std::string &getHelp() const;
74
76 virtual const std::string &getName() const;
77
79 // Return a string describing the attribute type
80 // ("logical", "real", etc.).
81 virtual const std::string &getType() const = 0;
82
84 // Parse value from the statement [b]s[/b] and assign it to the
85 // attribute [b]a[/b].
86 virtual void parse(Attribute &a, Statement &s, bool eval) const = 0;
87
89 // Parse value from the statement [b]s[/b] and assign it to the
90 // attribute [b]a[/b], indexed by [b]i[/b].
91 // The default version assumes that the value is scalar,
92 // and it throws [b]OpalException[/b].
93 virtual void parseComponent
94 (Attribute &a, Statement &s, bool eval, int i) const;
95
97 // True, if any expression evaluation is to be deferred.
98 // See [b]Expressions::ADeferred[/b] and [b]Expressions::SDeferred[/b]
99 // for details.
100 bool isDeferred() const;
101
103 // If the flag is set, expressions are evaluated only when the value
104 // is fetched.
105 void setDeferred(bool);
106
108 // If [b]parse[/b] is called with this flag set,
109 // then [b]OpalException[/b] is thrown.
110 bool isReadOnly() const;
111
113 // If [b]parse[/b] is called with the flag set,
114 // then [b]OpalException[/b] is thrown.
115 void setReadOnly(bool);
116
118 void setPredefinedValues(const std::set<std::string>&, const std::string&);
119
126
127 static std::multimap<OwnerType, std::string> getOwner(const std::string &att);
128 static void addAttributeOwner(const std::string &owner, const OwnerType &type, const std::string &name);
129protected:
130
132 const std::string itsName;
133
135 const std::string itsHelp;
136
138 std::shared_ptr<AttributeBase> itsDefault;
139
142
145
146private:
147
148 // Not implemented.
152
153 static std::multimap<std::string, std::pair<OwnerType, std::string> > attributeOwnerDictionary_s;
154};
155
156#endif // OPAL_AttributeHandler_HH
A representation of an Object attribute.
Definition Attribute.h:52
Abstract base class for attribute values of different types.
AttributeHandler(const AttributeHandler &)
void setDeferred(bool)
Set or reset defer flag.
const std::string itsHelp
Help text.
virtual AttributeBase * getDefault() const
Return default value.
bool isDeferred() const
Return defer flag.
static void addAttributeOwner(const std::string &owner, const OwnerType &type, const std::string &name)
bool is_deferred
Defer flag.
void setReadOnly(bool)
Set or reset read-only flag.
static std::multimap< std::string, std::pair< OwnerType, std::string > > attributeOwnerDictionary_s
virtual const std::string & getName() const
Return attribute name.
const std::string itsName
Attribute name.
virtual const std::string & getHelp() const
Return help string.
virtual const std::string & getType() const =0
Return attribute type.
virtual void parseComponent(Attribute &a, Statement &s, bool eval, int i) const
Parse component value.
AttributeHandler(const std::string &name, const std::string &help, AttributeBase *def)
Constructor.
bool isReadOnly() const
Return read-only flag.
virtual void parse(Attribute &a, Statement &s, bool eval) const =0
Parse new value.
void operator=(const AttributeHandler &)
static std::multimap< OwnerType, std::string > getOwner(const std::string &att)
virtual AttributeHandler * clone() const
Make clone.
bool is_readonly
Read-only flag.
void setPredefinedValues(const std::set< std::string > &, const std::string &)
Add predefined strings values to the help.
std::shared_ptr< AttributeBase > itsDefault
Default value.
RCObject()
Default constructor.
Definition RCObject.h:98
Interface for statements.
Definition Statement.h:38