OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
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.
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 
Representation objects and parsers for attribute expressions.
Definition: Expressions.h:64
An array of pointers to scalar expressions.
Definition: Expressions.h:127
A pointer to an array expression.
Definition: Expressions.h:180
void registerExpression(AttributeBase *)
Register expression.
Definition: OpalData.cpp:622
void unregisterExpression(AttributeBase *)
Unregister expression.
Definition: OpalData.cpp:626
static OpalData * getInstance()
Definition: OpalData.cpp:195
Object attribute with an `‘automatic’' array value.
Definition: AAutomatic.h:39
virtual std::vector< T > evaluate()
Evaluate.
Definition: AAutomatic.h:117
virtual void invalidate()
Invalidate.
Definition: AAutomatic.h:128
virtual AAutomatic< T > * clone() const
Make a clone.
Definition: AAutomatic.h:111
void operator=(const AAutomatic &)
Object attribute with a `‘deferred’' array value.
Definition: ADeferred.h:40
virtual std::vector< T > evaluate()
Evaluate.
Definition: ADeferred.h:166