OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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
24
25namespace Expressions {
26
27 // Template class SAutomatic
28 // ----------------------------------------------------------------------
30 // An automatic expression is marked as unknown and registered in a list
31 // when it is created. When its value is required, it is evaluated, is
32 // marked as known, and the new value is cached. Whenever a new
33 // definition is read, or an existing one is changed, all expressions
34 // are again marked as unknown. This forces a new evaluation when an
35 // expression is used the next time.
36
37 template <class T>
38 class SAutomatic : public SDeferred<T> {
39 public:
41 // From scalar expression.
42 explicit SAutomatic(PtrToScalar<T> expr);
43
45 virtual ~SAutomatic();
46
48 virtual SAutomatic<T>* clone() const;
49
51 // The resulting value is cached.
52 virtual T evaluate();
53
55 // Mark as unknown to force re-evaluation of expression.
56 virtual void invalidate();
57
58 private:
59 // Not implemented.
62
63 // Is the expression known ?
64 mutable bool is_known;
65 };
66
67 // Implementation
68 // ------------------------------------------------------------------------
69
70 template <class T>
71 SAutomatic<T>::SAutomatic(const SAutomatic<T>& rhs) : SDeferred<T>(rhs), is_known(false) {
73 }
74
75 template <class T>
79
80 template <class T>
82 // Unlink expression from expression list.
84 }
85
86 template <class T>
88 return new SAutomatic<T>(*this);
89 }
90
91 template <class T>
93 if (!is_known) {
95 is_known = true;
96 }
97
98 return this->value;
99 }
100
101 template <class T>
103 is_known = false;
104 }
105
106} // namespace Expressions
107
108#endif // OPAL_SAutomatic_HH
double T
Definition OPALTypes.h:8
A pointer to a scalar expression.
Object attribute with an `‘automatic’' scalar value.
Definition SAutomatic.h:38
void operator=(const SAutomatic< T > &)
virtual T evaluate()
Evaluate.
Definition SAutomatic.h:92
virtual SAutomatic< T > * clone() const
Make clone.
Definition SAutomatic.h:87
virtual void invalidate()
Invalidate.
Definition SAutomatic.h:102
Object attribute with a `‘deferred’' scalar value.
Definition SDeferred.h:39
virtual T evaluate()
Evaluate.
Definition SDeferred.h:95
void registerExpression(AttributeBase *)
Register expression.
Definition OpalData.cpp:553
void unregisterExpression(AttributeBase *)
Unregister expression.
Definition OpalData.cpp:555
static OpalData * getInstance()
Definition OpalData.cpp:193
Representation objects and parsers for attribute expressions.