OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
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
24#include <string>
25#include <map>
26#include <set>
27
28class Attribute;
29class Statement;
30
31
32// Class AttributeHandler
33// ------------------------------------------------------------------------
35// An attribute parser defines the data type for an attribute. It is
36// used to parse the attribute, to read the attribute from the DOOM data
37// base, and to write it to that data base. It contains the name and
38// help text for the attribute. Optionally it may also contain a default
39// value for the attribute.
40// [p]
41// When ``is_readonly'' is true, the attribute cannot be redefined by
42// the user.
43// [p]
44// When ``is_deferred'' is true, the attribute must be re-evaluated
45// whenever it is used. This is the case for random error values.
46// When ``is_deferred'' is false, any expression for the attribute is
47// cached. It is re-evaluated only when any other definition has changed.
48
50
51public:
53 // Assigns the attribute name [b]name[/b] and the help text [b]help[/b],
54 // as well as a possible default value [b]def[/b]for the attribute.
55 AttributeHandler(const std::string& name, const std::string& help, AttributeBase* def);
56
57 virtual ~AttributeHandler();
58
60 // Attribute handlers are always shared, so this method should never
61 // be called. It exists only to fulfill the requirements of the class
62 // [b]Pointer[/b].
63 virtual AttributeHandler* clone() const;
64
66 // Return the default value stored in this parser.
67 virtual AttributeBase* getDefault() const;
68
70 virtual const std::string& getHelp() const;
71
73 virtual const std::string& getName() const;
74
76 // Return a string describing the attribute type
77 // ("logical", "real", etc.).
78 virtual const std::string& getType() const = 0;
79
81 // Parse value from the statement [b]s[/b] and assign it to the
82 // attribute [b]a[/b].
83 virtual void parse(Attribute& a, Statement& s, bool eval) const = 0;
84
86 // Parse value from the statement [b]s[/b] and assign it to the
87 // attribute [b]a[/b], indexed by [b]i[/b].
88 // The default version assumes that the value is scalar,
89 // and it throws [b]OpalException[/b].
90 virtual void parseComponent
91 (Attribute& a, Statement& s, bool eval, int i) const;
92
94 // True, if any expression evaluation is to be deferred.
95 // See [b]Expressions::ADeferred[/b] and [b]Expressions::SDeferred[/b]
96 // for details.
97 bool isDeferred() const;
98
100 // If the flag is set, expressions are evaluated only when the value
101 // is fetched.
102 void setDeferred(bool);
103
105 // If [b]parse[/b] is called with this flag set,
106 // then [b]OpalException[/b] is thrown.
107 bool isReadOnly() const;
108
110 // If [b]parse[/b] is called with the flag set,
111 // then [b]OpalException[/b] is thrown.
112 void setReadOnly(bool);
113
115 void setPredefinedValues(const std::set<std::string>&, const std::string&);
116
123
124 static std::multimap<OwnerType, std::string> getOwner(const std::string& att);
125 static void addAttributeOwner(const std::string& owner, const OwnerType& type, const std::string& name);
126
127 protected:
129 const std::string itsName;
130
132 const std::string itsHelp;
133
135 Pointer <AttributeBase> itsDefault;
136
139
142
143private:
144 // Not implemented.
148
149 static std::multimap<std::string, std::pair<OwnerType, std::string> > attributeOwnerDictionary_s;
150};
151
152#endif // OPAL_AttributeHandler_HH
std::complex< double > a
const std::string name
A representation of an Object attribute.
Definition Attribute.h:52
Abstract base class for attribute values of different types.
Abstract base class for attribute parsers.
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.
Pointer< AttributeBase > itsDefault
Default value.
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.
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.
Abstract base class for reference counted objects.
Definition RCObject.h:40
Interface for statements.
Definition Statement.h:38