MPQC  2.3.1
compute.h
1 //
2 // compute.h
3 //
4 // Copyright (C) 1996 Limit Point Systems, Inc.
5 //
6 // Author: Curtis Janssen <cljanss@limitpt.com>
7 // Maintainer: LPS
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 #ifdef __GNUC__
29 #pragma interface
30 #endif
31 
32 #ifndef _util_misc_compute_h
33 #define _util_misc_compute_h
34 
35 #include <set>
36 
37 #include <util/state/state.h>
38 #include <util/state/stateio.h>
39 
40 namespace sc {
41 
42 class ResultInfo;
43 class StateIn;
44 class StateOut;
45 
46 typedef ResultInfo* ResultInfoP;
47 
55 class Compute
56 {
57  friend class ResultInfo;
58  friend class AccResultInfo;
59  private:
60  std::set<ResultInfoP> _results;
61  void add(ResultInfo*);
62 
63  // Prohibit copy
64  Compute(const Compute&) {};
65 
66  protected:
70  virtual void compute() = 0;
71  public:
72  Compute();
73  virtual ~Compute();
74 
77  virtual void obsolete();
78 };
79 
85 {
86  protected:
87  int _compute;
88  int _computed;
89  Compute* _c;
90  // This make sure that the datum is up to date. If it is not then
91  // Compute::compute() will be called.
92  virtual void update();
93  protected:
95  ResultInfo(const ResultInfo&,Compute*);
96  virtual void save_data_state(StateOut&);
97  virtual void restore_state(StateIn&);
98  ResultInfo& operator=(const ResultInfo&);
99  public:
100  ResultInfo(Compute*c);
101  virtual ~ResultInfo();
102  int& compute() { return _compute; }
103  const int& compute() const { return _compute; }
104  int compute(int c) { int r = _compute; _compute = c; return r; }
105  int& computed() { return _computed; }
106  const int& computed() const { return _computed; }
107  virtual int needed() const;
108 };
109 
113 {
114  private:
115  double _actual_accuracy;
116  double _desired_accuracy;
117  protected:
120  virtual void save_data_state(StateOut&);
121  virtual void restore_state(StateIn&);
122  AccResultInfo& operator=(const AccResultInfo&);
123  void update();
124  public:
126  ~AccResultInfo();
127  double actual_accuracy() const;
128  double desired_accuracy() const;
129  void set_desired_accuracy(double);
130  void set_actual_accuracy(double);
131  int computed_to_desired_accuracy() const
132  { return computed() && _actual_accuracy <= _desired_accuracy; }
133  int needed() const;
134 };
135 
136 }
137 
138 #include <util/misc/comptmpl.h>
139 
140 namespace sc {
141 
142 typedef NCResult<int> Resultint;
143 typedef NCResult<double> Resultdouble;
144 typedef NCAccResult<double> AccResultdouble;
145 
146 }
147 
148 #endif
149 
150 // Local Variables:
151 // mode: c++
152 // c-file-style: "CLJ"
153 // End:
sc::AccResultInfo
This is like ResultInfo but the accuracy with which a result was computed as well as the desired accu...
Definition: compute.h:112
sc::StateIn
Restores objects that derive from SavableState.
Definition: statein.h:70
sc::ResultInfo
This is a base class for all of Compute's result types.
Definition: compute.h:84
sc::Compute::obsolete
virtual void obsolete()
Marks all results as being out of date.
sc::StateOut
Serializes objects that derive from SavableState.
Definition: stateout.h:61
sc::Compute
The Compute class provides a means of keeping results up to date.
Definition: compute.h:55
sc::Compute::compute
virtual void compute()=0
Recompute at least the results that have compute true and are not already computed.

Generated at Sun Jan 26 2020 23:33:03 for MPQC 2.3.1 using the documentation package Doxygen 1.8.16.