OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
SAutomatic.h
Go to the documentation of this file.
1 #ifndef OPAL_SAutomatic_HH
2 #define OPAL_SAutomatic_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: SAutomatic.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.1.1.1.4.1 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Template class: SAutomatic<T>
13 //
14 // ------------------------------------------------------------------------
15 //
16 // $Date: 2004/11/18 22:52:40 $
17 // $Author: jsberg $
18 //
19 // ------------------------------------------------------------------------
20 
21 #include "Expressions/SDeferred.h"
24 
25 
26 namespace Expressions {
27 
28  // Template class SAutomatic
29  // ----------------------------------------------------------------------
31  // An automatic expression is marked as unknown and registered in a list
32  // when it is created. When its value is required, it is evaluated, is
33  // marked as known, and the new value is cached. Whenever a new
34  // definition is read, or an existing one is changed, all expressions
35  // are again marked as unknown. This forces a new evaluation when an
36  // expression is used the next time.
37 
38  template <class T> class SAutomatic: public SDeferred<T> {
39 
40  public:
41 
43  // From scalar expression.
44  explicit SAutomatic(PtrToScalar<T> expr);
45 
46  SAutomatic(const SAutomatic<T> &);
47  virtual ~SAutomatic();
48 
50  virtual SAutomatic<T> *clone() const;
51 
53  // The resulting value is cached.
54  virtual T evaluate();
55 
57  // Mark as unknown to force re-evaluation of expression.
58  virtual void invalidate();
59 
60  private:
61 
62  // Not implemented.
63  SAutomatic();
64  void operator=(const SAutomatic<T> &);
65 
66  // Is the expression known ?
67  mutable bool is_known;
68  };
69 
70 
71  // Implementation
72  // ------------------------------------------------------------------------
73 
74  template <class T>
76  SDeferred<T>(rhs), is_known(false) {
78  }
79 
80 
81  template <class T>
83  SDeferred<T>(expr), is_known(false) {
85  }
86 
87 
88  template <class T>
90  // Unlink expression from expression list.
92  }
93 
94 
95  template <class T>
97  return new SAutomatic<T>(*this);
98  }
99 
100 
101  template <class T>
103  if(! is_known) {
105  is_known = true;
106  }
107 
108  return this->value;
109  }
110 
111 
112  template <class T>
114  is_known = false;
115  }
116 
117 }
118 
119 #endif // OPAL_SAutomatic_HH
Definition: rbendmap.h:8
A pointer to a scalar expression.
Definition: Expressions.h:116
virtual T evaluate()
Evaluate.
Definition: SAutomatic.h:102
void operator=(const SAutomatic< T > &)
Object attribute with a ``deferred&#39;&#39; scalar value.
Definition: SDeferred.h:39
virtual T evaluate()
Evaluate.
Definition: SDeferred.h:107
static OpalData * getInstance()
Definition: OpalData.cpp:209
Object attribute with an ``automatic&#39;&#39; scalar value.
Definition: SAutomatic.h:38
virtual void invalidate()
Invalidate.
Definition: SAutomatic.h:113
void registerExpression(AttributeBase *)
Register expression.
Definition: OpalData.cpp:681
void unregisterExpression(AttributeBase *)
Unregister expression.
Definition: OpalData.cpp:686
virtual SAutomatic< T > * clone() const
Make clone.
Definition: SAutomatic.h:96