00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef __GNUC__
00029 #pragma interface
00030 #endif
00031
00032 #ifndef _util_misc_compute_h
00033 #define _util_misc_compute_h
00034
00035 #include <stdio.h>
00036 #include <util/container/avlset.h>
00037 #include <util/state/state.h>
00038 #include <util/state/stateio.h>
00039
00040 class ResultInfo;
00041 class StateIn;
00042 class StateOut;
00043
00044 typedef ResultInfo* ResultInfoP;
00045
00053 class Compute
00054 {
00055 friend class ResultInfo;
00056 friend class AccResultInfo;
00057 private:
00058 AVLSet<ResultInfoP> _results;
00059 void add(ResultInfo*);
00060
00061
00062 Compute(const Compute&) {};
00063
00064 protected:
00068 virtual void compute() = 0;
00069 public:
00070 Compute();
00071 virtual ~Compute();
00072
00075 virtual void obsolete();
00076 };
00077
00082 class ResultInfo
00083 {
00084 protected:
00085 int _compute;
00086 int _computed;
00087 Compute* _c;
00088
00089
00090 virtual void update();
00091 protected:
00092 ResultInfo(StateIn&,Compute*);
00093 ResultInfo(const ResultInfo&,Compute*);
00094 virtual void save_data_state(StateOut&);
00095 virtual void restore_state(StateIn&);
00096 ResultInfo& operator=(const ResultInfo&);
00097 public:
00098 ResultInfo(Compute*c);
00099 virtual ~ResultInfo();
00100 int& compute() { return _compute; }
00101 const int& compute() const { return _compute; }
00102 int compute(int c) { int r = _compute; _compute = c; return r; }
00103 int& computed() { return _computed; }
00104 const int& computed() const { return _computed; }
00105 virtual int needed() const;
00106 };
00107
00110 class AccResultInfo: public ResultInfo
00111 {
00112 private:
00113 double _actual_accuracy;
00114 double _desired_accuracy;
00115 protected:
00116 AccResultInfo(StateIn&,Compute*);
00117 AccResultInfo(const AccResultInfo&,Compute*);
00118 virtual void save_data_state(StateOut&);
00119 virtual void restore_state(StateIn&);
00120 AccResultInfo& operator=(const AccResultInfo&);
00121 void update();
00122 public:
00123 AccResultInfo(Compute*c);
00124 ~AccResultInfo();
00125 double actual_accuracy() const;
00126 double desired_accuracy() const;
00127 void set_desired_accuracy(double);
00128 void set_actual_accuracy(double);
00129 int computed_to_desired_accuracy() const
00130 { return computed() && _actual_accuracy <= _desired_accuracy; }
00131 int needed() const;
00132 };
00133
00134 #include <util/misc/comptmpl.h>
00135
00136 typedef NCResult<int> Resultint;
00137 typedef NCResult<double> Resultdouble;
00138 typedef NCAccResult<double> AccResultdouble;
00139
00140 #endif
00141
00142
00143
00144
00145