OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
Object.h
Go to the documentation of this file.
1#ifndef OPAL_Object_HH
2#define OPAL_Object_HH
3
4// ------------------------------------------------------------------------
5// $RCSfile: Object.h,v $
6// ------------------------------------------------------------------------
7// $Revision: 1.2 $
8// ------------------------------------------------------------------------
9// Copyright: see Copyright.readme
10// ------------------------------------------------------------------------
11//
12// Class: Object
13//
14// ------------------------------------------------------------------------
15//
16// $Date: 2000/03/29 10:40:37 $
17// $Author: opal $
18//
19// ------------------------------------------------------------------------
20
21#include <iosfwd>
22#include <set>
23#include <string>
24#include <vector>
26
27class Invalidator;
28class Parser;
29class Statement;
30class TokenStream;
31
32// Class Object
33// ------------------------------------------------------------------------
35// Any OPAL command object which may be generated by parsing a command or
36// definition.
37// All known Objects use standard C++ memory management.
38//
39// Objects are linked by name to the OPAL directory, which resides in
40// the global object [b]OpalData[/b]. Each Object has a pointer pointing
41// to its parent object. This may be an exemplar object, or a previously
42// generated command or definition object. This mechanism allows to find
43// easily whether an Object belongs to a given class (see isTreeMember()).
44
45class Object {
46public:
47 virtual ~Object();
48
50 // By default redefinition of an existing Object is not allowed.
51 virtual bool canReplaceBy(Object* object);
52
54 // Call the [b]clone[/b] constructor to generate a copy of [b]this[/b]
55 // with a new name [b]name[/b].
56 virtual Object* clone(const std::string& name) = 0;
57
59 void copyAttributes(const Object&);
60
62 // For definitions check validity, for actions execute the action.
63 virtual void execute();
64
66 // Find the Object's attribute identified by [b]name[/b]
67 // (version for non-constant object).
68 virtual Attribute* findAttribute(const std::string& name);
69
71 // Find the Object's attribute identified by [b]name[/b]
72 // (version for constant object).
73 virtual const Attribute* findAttribute(const std::string& name) const;
74
76 // Is overridden by the (still abstract) sub-classes of Object.
77 virtual const std::string getCategory() const = 0;
78
80 // If true, the object's execute() function should be traced.
81 // For all commands for which OPAL should give tracing output this
82 // method must return true.
83 virtual bool shouldTrace() const = 0;
84
86 // If true, the data structure must be updated before calling execute().
87 // For all commands which require the OPAL data structure to be up to date
88 // for their execution this method must return true.
89 virtual bool shouldUpdate() const = 0;
90
92 // Construct an ``archetype'' object for a MACRO commands.
93 // The default version throws OpalException.
94 virtual Object* makeTemplate(const std::string&, TokenStream&, Statement&);
95
97 // Construct an instance object from an ``archetype'' object.
98 // The default version throws OpalException.
99 virtual Object* makeInstance(const std::string& name, Statement&, const Parser*);
100
102 // Parse the statement and fill in the Object's attributes.
103 virtual void parse(Statement&);
104
106 // This parser allows to use unnamed attributes for command which
107 // have only one attribute.
108 // If [b]eval[/b] is false, then the attribute is not evaluated immediately
109 // even if the delimiter is ``=''.
110 virtual void parseShortcut(Statement&, bool eval = true);
111
113 // Print a OPAL-readable image of [b]this[/b] on the given output stream.
114 virtual void print(std::ostream&) const;
115
116 virtual void printValue(std::ostream&) const;
117
119 // Print help information for [b]this[/b] on the default output stream (argument not used).
120 virtual void printHelp(std::ostream&) const;
121
123 // Called for all defined objects, when an object [b]oldObject[/b] is
124 // replaced by a new definition [b]newObject[/b].
125 // This default version does nothing.
126 // Some derived classes may react to the redefinition by invalidating
127 // themselves or by replacing reference inside their data.
128 virtual void replace(Object* oldObject, Object* newObject);
129
131 // Called for all defined objects, before an action command is executed.
132 // This default version does nothing.
133 // Derived classes may use this call to update their internal state.
134 // The beam line elements can update their OPALX counterpart.
135 virtual void update();
136
138 bool isBuiltin() const;
139
141 // If true, this object cannot be cloned to create new elements.
142 // If it is an element or a line, all references are to the same object.
143 virtual bool isShared() const;
144
146 // If true, this object cannot be cloned to create new elements.
147 // If it is an element or a line, all references are to the same object.
148 virtual void setShared(bool);
149
151 // Set the flag when an object is created and modified,
152 // reset it when the object is saved in the DOOM data base.
153 void setDirty(bool);
154
156 bool isDirty() const;
157
159 // flagged objects only.
160 void setFlag(bool);
161
163 bool isFlagged() const;
164
166 // Return the top-most ancestor of this object, i. e. the built-in
167 // object from which [b]this[/b] is ultimately derived.
168 const Object* getBaseObject() const;
169
171 const std::string& getOpalName() const;
172
174 Object* getParent() const;
175
177 // Return true, if [b]this[/b] has been directly or indirectly derived
178 // from [b]subTree[/b].
179 bool isTreeMember(const Object* subTree) const;
180
182 void setOpalName(const std::string& name);
183
185 // This method should normally be called only from Directory.
186 void setParent(Object*);
187
189 void clear();
190
192 int increment();
193
195 int occurrenceCount();
196
198 // Place [b]a[/b] in the list of references. Whenever [b]this[/b]
199 // is erased or modified, [b]a[/b] will be notified of the change.
201
203 // Remove [b]a[/b] from the list of references. The object [b]a[/b]
204 // will no longer be notified of any change to [b]this[/b].
206
207 void registerOwnership(const AttributeHandler::OwnerType& itsClass) const;
208
210 std::vector<Attribute> itsAttr;
211
212protected:
214 // The exemplar object will have the name [b]name[/b], and the help
215 // text [b]help[/b]; it initially reserves [b]size[/b] attributes.
216 Object(int size, const char* name, const char* help);
217
219 // The clone object will have the name [b]name[/b]; it inherits its
220 // attributes (shared) from the object [b]*parent[/b].
221 Object(const std::string& name, Object* parent);
222
224 // True, if the object is built-in to OPAL-9, i. e. if it is an exemplar
225 // or a predefined definition.
227
229 // True when [b]this[/b] is new or modified and should be saved in the
230 // DOOM data base.
232
234 // This flag can be freely set and reset during the execution of a command.
236
237private:
238 // Not implemented.
240 Object(const Object& object);
241 void operator=(const Object&);
242
243 // Pointer to the parent object.
245
246 // The object name.
247 std::string itsName;
248
249 // The help text.
250 std::string itsHelp;
251
252 // The occurrence counter.
254
255 // The DOOM data base time stamp.
256 double timeStamp;
257
258 // The set of all references to this object.
259 // This allows to invalidate the references when [b]this[/b] is deleted.
260 std::set<Invalidator*> references;
261
262 // If true, the object is shared.
264};
265
266// Implementation.
267// ------------------------------------------------------------------------
268extern std::ostream& operator<<(std::ostream& os, const Object& object);
269
270inline void Object::printValue(std::ostream& os) const { print(os); }
271
272#endif // OPAL_Object_HH
std::ostream & operator<<(std::ostream &os, const Object &object)
Definition Object.cpp:313
A representation of an Object attribute.
Definition Attribute.h:52
Abstract base class for references which must be invalidated when an.
Definition Invalidator.h:26
The base class for all OPAL objects.
Definition Object.h:45
void setParent(Object *)
Set parent object.
Definition Object.cpp:283
Object(const Object &object)
virtual bool shouldTrace() const =0
Trace flag.
virtual void parseShortcut(Statement &, bool eval=true)
Parser for single-attribute commands.
Definition Object.cpp:113
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition Object.cpp:169
virtual bool canReplaceBy(Object *object)
Test if replacement is allowed.
Definition Object.cpp:45
virtual Object * makeTemplate(const std::string &, TokenStream &, Statement &)
Macro handler function.
Definition Object.cpp:71
int occurrence
Definition Object.h:253
void operator=(const Object &)
virtual Object * clone(const std::string &name)=0
Return a clone.
bool isFlagged() const
True, if [b]this[/b] is flagged by setFlag(true).
Definition Object.cpp:258
Object * itsParent
Definition Object.h:244
bool isDirty() const
True, if the [b]modified[/b] flag is set.
Definition Object.cpp:254
std::string itsHelp
Definition Object.h:250
Object * getParent() const
Return parent pointer.
Definition Object.cpp:269
virtual void update()
Update this object.
Definition Object.cpp:239
std::string itsName
Definition Object.h:247
const Object * getBaseObject() const
Return the object's base type object.
Definition Object.cpp:260
bool sharedFlag
Definition Object.h:263
bool flagged
Object flag.
Definition Object.h:235
virtual Object * makeInstance(const std::string &name, Statement &, const Parser *)
Macro handler function.
Definition Object.cpp:76
const std::string & getOpalName() const
Return object name.
Definition Object.cpp:267
virtual void print(std::ostream &) const
Print the object.
Definition Object.cpp:146
std::set< Invalidator * > references
Definition Object.h:260
int occurrenceCount()
Return the occurrence counter.
Definition Object.cpp:289
void copyAttributes(const Object &)
Copy attributes from another object.
Definition Object.cpp:50
void setDirty(bool)
Set/reset the [b]modified[/b] flag.
Definition Object.cpp:249
int increment()
Increment and return the occurrence counter.
Definition Object.cpp:287
virtual void setShared(bool)
Set/reset shared flag.
Definition Object.cpp:247
virtual Attribute * findAttribute(const std::string &name)
Find an attribute by name.
Definition Object.cpp:56
void registerReference(Invalidator *a)
Register a reference to this object.
Definition Object.cpp:165
bool modified
Dirty flag.
Definition Object.h:231
virtual void execute()
Execute the command.
Definition Object.cpp:52
void clear()
Clear the occurrence counter.
Definition Object.cpp:285
void setOpalName(const std::string &name)
Set object name.
Definition Object.cpp:281
virtual void printHelp(std::ostream &) const
Print help.
Definition Object.cpp:179
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:210
virtual bool shouldUpdate() const =0
Update flag.
virtual const std::string getCategory() const =0
Return the object category as a string.
bool isTreeMember(const Object *subTree) const
Test for tree membership.
Definition Object.cpp:271
virtual void parse(Statement &)
Parse the object.
Definition Object.cpp:82
bool isBuiltin() const
True, if [b]this[/b] is a built-in object.
Definition Object.cpp:243
virtual ~Object()
Definition Object.cpp:38
virtual bool isShared() const
Shared flag.
Definition Object.cpp:245
void setFlag(bool)
Flag/unflag this object, e. g. to control output of objects for.
Definition Object.cpp:256
bool builtin
Built-in flag.
Definition Object.h:226
virtual void replace(Object *oldObject, Object *newObject)
Replace references.
Definition Object.cpp:235
void unregisterReference(Invalidator *a)
Unegister a reference to this object.
Definition Object.cpp:167
virtual void printValue(std::ostream &) const
Definition Object.h:270
double timeStamp
Definition Object.h:256
Interface for abstract language parser.
Definition Parser.h:30
Interface for statements.
Definition Statement.h:37
Abstract interface for a stream of input tokens.
Definition TokenStream.h:30