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 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     // Prohibit copy
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     // This make sure that the datum is up to date.  If it is not then
00089     // Compute::compute() will be called.
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 // Local Variables:
00143 // mode: c++
00144 // c-file-style: "CLJ"
00145 // End:

Generated at Thu Oct 4 18:08:42 2001 for MPQC 2.0.0 using the documentation package Doxygen 1.2.5.