OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
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 
27 class Attribute;
28 class Statement;
29 
30 
31 // Class AttributeHandler
32 // ------------------------------------------------------------------------
34 // An attribute parser defines the data type for an attribute. It is
35 // used to parse the attribute, to read the attribute from the DOOM data
36 // base, and to write it to that data base. It contains the name and
37 // help text for the attribute. Optionally it may also contain a default
38 // value for the attribute.
39 // [p]
40 // When ``is_readonly'' is true, the attribute cannot be redefined by
41 // the user.
42 // [p]
43 // When ``is_deferred'' is true, the attribute must be re-evaluated
44 // whenever it is used. This is the case for random error values.
45 // When ``is_deferred'' is false, any expression for the attribute is
46 // cached. It is re-evaluated only when any other definition has changed.
47 
48 class AttributeHandler: public RCObject {
49 
50 public:
51 
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 
114  enum OwnerType {
120 
121  static std::multimap<OwnerType, std::string> getOwner(const std::string &att);
122  static void addAttributeOwner(const std::string &owner, const OwnerType &type, const std::string &name);
123 protected:
124 
126  const std::string itsName;
127 
129  const std::string itsHelp;
130 
133 
136 
139 
140 private:
141 
142  // Not implemented.
145  void operator=(const AttributeHandler &);
146 
147  static std::multimap<std::string, std::pair<OwnerType, std::string> > attributeOwnerDictionary_s;
148 };
149 
150 #endif // OPAL_AttributeHandler_HH
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.
Pointer< AttributeBase > itsDefault
Default value.
bool is_deferred
Defer flag.
const std::string itsName
Attribute name.
virtual const std::string & getType() const =0
Return attribute type.
const std::string itsHelp
Help text.
void setReadOnly(bool)
Set or reset read-only flag.
void setDeferred(bool)
Set or reset defer flag.
static void addAttributeOwner(const std::string &owner, const OwnerType &type, const std::string &name)
virtual ~AttributeHandler()
virtual AttributeBase * getDefault() const
Return default value.
virtual const std::string & getHelp() const
Return help string.
void operator=(const AttributeHandler &)
A representation of an Object attribute.
Definition: Attribute.h:55
virtual const std::string & getName() const
Return attribute name.
Interface for statements.
Definition: Statement.h:38
virtual AttributeHandler * clone() const
Make clone.
Abstract base class for attribute parsers.
bool isDeferred() const
Return defer flag.
Abstract base class for reference counted objects.
Definition: RCObject.h:42
static std::multimap< OwnerType, std::string > getOwner(const std::string &att)
const std::string name
virtual void parse(Attribute &a, Statement &s, bool eval) const =0
Parse new value.
static std::multimap< std::string, std::pair< OwnerType, std::string > > attributeOwnerDictionary_s
bool is_readonly
Read-only flag.
bool isReadOnly() const
Return read-only flag.