OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
AAutomatic.h
Go to the documentation of this file.
1 #ifndef OPAL_AAutomatic_HH
2 #define OPAL_AAutomatic_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: AAutomatic.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.1.1.1.4.1 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Template class: AAutomatic<T>
13 //
14 // ------------------------------------------------------------------------
15 //
16 // $Date: 2004/11/18 22:52:40 $
17 // $Author: jsberg $
18 //
19 // ------------------------------------------------------------------------
20 
21 #include "Expressions/ADeferred.h"
24 
25 
26 namespace Expressions {
27 
28  // Template class AAutomatic
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,
33  // marked as known, and the new value is cached. Whenever a new
34  // definition is read, or an existing one is changed, the expressions
35  // are all marked as unknown. This forces a new evaluation when an
36  // exoression is used the next time.
37 
38  template <class T>
39  class AAutomatic: public ADeferred<T> {
40 
41  public:
42 
44  // From array of expressions.
45  explicit AAutomatic(PtrToArray<T> expr);
46 
48  // From array expression.
49  explicit AAutomatic(ArrayOfPtrs<T> expr);
50 
51  AAutomatic(const AAutomatic &);
52  virtual ~AAutomatic();
53 
55  virtual AAutomatic<T> *clone() const;
56 
58  // The resulting value is cached.
59  virtual std::vector<T> evaluate();
60 
62  // Mark as unknown to force re-evaluation of expression.
63  virtual void invalidate();
64 
65  private:
66 
67  // Not implemented.
68  AAutomatic();
69  void operator=(const AAutomatic &);
70 
71  // Is the expression known ?
72  mutable bool is_known;
73  };
74 
75 
76  // Implementation
77  // ----------------------------------------------------------------------
78 
79  template <class T>
81  ADeferred<T>(rhs),
82  is_known(false) {
84  }
85 
86 
87  template <class T>
89  ADeferred<T>(expr),
90  is_known(false) {
92  }
93 
94 
95  template <class T>
97  ADeferred<T>(expr),
98  is_known(false) {
100  }
101 
102 
103  template <class T>
105  // Unlink expression from expression list.
107  }
108 
109 
110  template <class T>
112  return new AAutomatic<T>(*this);
113  }
114 
115 
116  template <class T>
117  std::vector<T> AAutomatic<T>::evaluate() {
118  if(! is_known) {
120  is_known = true;
121  }
122 
123  return this->value;
124  }
125 
126 
127  template <class T>
129  is_known = false;
130  }
131 
132 }
133 
134 #endif // OPAL_AAutomatic_HH
135 
Definition: rbendmap.h:8
virtual AAutomatic< T > * clone() const
Make a clone.
Definition: AAutomatic.h:111
static OpalData * getInstance()
Definition: OpalData.cpp:209
virtual std::vector< T > evaluate()
Evaluate.
Definition: ADeferred.h:166
void operator=(const AAutomatic &)
Object attribute with a ``deferred&#39;&#39; array value.
Definition: ADeferred.h:40
void registerExpression(AttributeBase *)
Register expression.
Definition: OpalData.cpp:681
virtual void invalidate()
Invalidate.
Definition: AAutomatic.h:128
void unregisterExpression(AttributeBase *)
Unregister expression.
Definition: OpalData.cpp:686
virtual std::vector< T > evaluate()
Evaluate.
Definition: AAutomatic.h:117
An array of pointers to scalar expressions.
Definition: Expressions.h:134
A pointer to an array expression.
Definition: Expressions.h:186
Object attribute with an ``automatic&#39;&#39; array value.
Definition: AAutomatic.h:39