OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
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 
28 class Attribute;
29 class 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 
49 class AttributeHandler: public RCObject {
50 
51 public:
52 
54  // Assigns the attribute name [b]name[/b] and the help text [b]help[/b],
55  // as well as a possible default value [b]def[/b]for the attribute.
56  AttributeHandler(const std::string &name, const std::string &help, AttributeBase *def);
57 
58  virtual ~AttributeHandler();
59 
61  // Attribute handlers are always shared, so this method should never
62  // be called. It exists only to fulfill the requirements of the class
63  // [b]Pointer[/b].
64  virtual AttributeHandler *clone() const;
65 
67  // Return the default value stored in this parser.
68  virtual AttributeBase *getDefault() const;
69 
71  virtual const std::string &getHelp() const;
72 
74  virtual const std::string &getName() const;
75 
77  // Return a string describing the attribute type
78  // ("logical", "real", etc.).
79  virtual const std::string &getType() const = 0;
80 
82  // Parse value from the statement [b]s[/b] and assign it to the
83  // attribute [b]a[/b].
84  virtual void parse(Attribute &a, Statement &s, bool eval) const = 0;
85 
87  // Parse value from the statement [b]s[/b] and assign it to the
88  // attribute [b]a[/b], indexed by [b]i[/b].
89  // The default version assumes that the value is scalar,
90  // and it throws [b]OpalException[/b].
91  virtual void parseComponent
92  (Attribute &a, Statement &s, bool eval, int i) const;
93 
95  // True, if any expression evaluation is to be deferred.
96  // See [b]Expressions::ADeferred[/b] and [b]Expressions::SDeferred[/b]
97  // for details.
98  bool isDeferred() const;
99 
101  // If the flag is set, expressions are evaluated only when the value
102  // is fetched.
103  void setDeferred(bool);
104 
106  // If [b]parse[/b] is called with this flag set,
107  // then [b]OpalException[/b] is thrown.
108  bool isReadOnly() const;
109 
111  // If [b]parse[/b] is called with the flag set,
112  // then [b]OpalException[/b] is thrown.
113  void setReadOnly(bool);
114 
116  void setPredefinedValues(const std::set<std::string>&, const std::string&);
117 
118  enum OwnerType {
124 
125  static std::multimap<OwnerType, std::string> getOwner(const std::string &att);
126  static void addAttributeOwner(const std::string &owner, const OwnerType &type, const std::string &name);
127 protected:
128 
130  const std::string itsName;
131 
133  const std::string itsHelp;
134 
137 
140 
143 
144 private:
145 
146  // Not implemented.
150 
151  static std::multimap<std::string, std::pair<OwnerType, std::string> > attributeOwnerDictionary_s;
152 };
153 
154 #endif // OPAL_AttributeHandler_HH
std::complex< double > a
const std::string name
boost::function< boost::tuple< double, bool >arguments_t)> type
Definition: function.hpp:21
A representation of an Object attribute.
Definition: Attribute.h:52
Abstract base class for attribute values of different types.
Definition: AttributeBase.h:32
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 & getType() const =0
Return attribute type.
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 void parseComponent(Attribute &a, Statement &s, bool eval, int i) const
Parse component value.
virtual ~AttributeHandler()
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