Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

compute.h

00001 //
00002 // compute.h
00003 //
00004 // Copyright (C) 1996 Limit Point Systems, Inc.
00005 //
00006 // Author: Curtis Janssen <cljanss@limitpt.com>
00007 // Maintainer: LPS
00008 //
00009 // This file is part of the SC Toolkit.
00010 //
00011 // The SC Toolkit is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Library General Public License as published by
00013 // the Free Software Foundation; either version 2, or (at your option)
00014 // any later version.
00015 //
00016 // The SC Toolkit is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU Library General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Library General Public License
00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00024 //
00025 // The U.S. Government is granted a limited license as per AL 91-7.
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 namespace sc {
00041 
00042 class ResultInfo;
00043 class StateIn;
00044 class StateOut;
00045 
00046 typedef ResultInfo* ResultInfoP;
00047 
00055 class Compute
00056 {
00057    friend class ResultInfo;
00058    friend class AccResultInfo;
00059   private:
00060     AVLSet<ResultInfoP> _results;
00061     void add(ResultInfo*);
00062 
00063     // Prohibit copy
00064     Compute(const Compute&) {};
00065 
00066   protected:
00070     virtual void compute() = 0;
00071   public:
00072     Compute();
00073     virtual ~Compute();
00074 
00077     virtual void obsolete();
00078 };
00079 
00084 class ResultInfo
00085 {
00086   protected:
00087     int _compute;
00088     int _computed;
00089     Compute* _c;
00090     // This make sure that the datum is up to date.  If it is not then
00091     // Compute::compute() will be called.
00092     virtual void update();
00093   protected:
00094     ResultInfo(StateIn&,Compute*);
00095     ResultInfo(const ResultInfo&,Compute*);
00096     virtual void save_data_state(StateOut&);
00097     virtual void restore_state(StateIn&);
00098     ResultInfo& operator=(const ResultInfo&);
00099   public:
00100     ResultInfo(Compute*c);
00101     virtual ~ResultInfo();
00102     int& compute() { return _compute; }
00103     const int& compute() const { return _compute; }
00104     int compute(int c) { int r = _compute; _compute = c; return r; }
00105     int& computed() { return _computed; }
00106     const int& computed() const { return _computed; }
00107     virtual int needed() const;
00108 };
00109 
00112 class AccResultInfo: public ResultInfo
00113 {
00114   private:
00115     double _actual_accuracy;
00116     double _desired_accuracy;
00117   protected:
00118     AccResultInfo(StateIn&,Compute*);
00119     AccResultInfo(const AccResultInfo&,Compute*);
00120     virtual void save_data_state(StateOut&);
00121     virtual void restore_state(StateIn&);
00122     AccResultInfo& operator=(const AccResultInfo&);
00123     void update();
00124   public:
00125     AccResultInfo(Compute*c);
00126     ~AccResultInfo();
00127     double actual_accuracy() const;
00128     double desired_accuracy() const;
00129     void set_desired_accuracy(double);
00130     void set_actual_accuracy(double);
00131     int computed_to_desired_accuracy() const
00132         { return computed() && _actual_accuracy <= _desired_accuracy; }
00133     int needed() const;
00134 };
00135 
00136 }
00137 
00138 #include <util/misc/comptmpl.h>
00139 
00140 namespace sc {
00141 
00142 typedef NCResult<int> Resultint;
00143 typedef NCResult<double> Resultdouble;
00144 typedef NCAccResult<double> AccResultdouble;
00145 
00146 }
00147 
00148 #endif
00149 
00150 // Local Variables:
00151 // mode: c++
00152 // c-file-style: "CLJ"
00153 // End:

Generated at Fri Jan 10 08:14:08 2003 for MPQC 2.1.3 using the documentation package Doxygen 1.2.14.