[0b990d] | 1 | //
|
---|
| 2 | // comptmpl.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 | namespace sc {
|
---|
| 29 |
|
---|
| 30 | /** Result are members of Compute specializations that keep track of
|
---|
| 31 | whether or not a particular result should be computed or if it has
|
---|
| 32 | already been computed. For non-class template parameters, use
|
---|
| 33 | NCResult. */
|
---|
| 34 | template <class T>
|
---|
| 35 | class Result: public ResultInfo {
|
---|
| 36 | private:
|
---|
| 37 | T _result;
|
---|
| 38 | public:
|
---|
| 39 | Result(Compute*c):ResultInfo(c) {};
|
---|
| 40 | Result(const Result<T> &r, Compute*c):ResultInfo(c)
|
---|
| 41 | { _result=r._result; }
|
---|
| 42 | operator T&() { update(); return _result; };
|
---|
| 43 | T* operator ->() { update(); return &_result; };
|
---|
| 44 | T& result() { update(); return _result; };
|
---|
| 45 | T& result_noupdate() { return _result; };
|
---|
| 46 | const T& result_noupdate() const { return _result; };
|
---|
| 47 | void operator=(const T& a) { _result = a; }
|
---|
| 48 | void operator=(const Result<T> &r)
|
---|
| 49 | { ResultInfo::operator=(r); _result = r._result; };
|
---|
| 50 | };
|
---|
| 51 |
|
---|
| 52 | /** This is similar to Result, but can be used with
|
---|
| 53 | non-class types. */
|
---|
| 54 | template <class T>
|
---|
| 55 | class NCResult: public ResultInfo {
|
---|
| 56 | private:
|
---|
| 57 | T _result;
|
---|
| 58 | public:
|
---|
| 59 | NCResult(Compute*c):ResultInfo(c) {};
|
---|
| 60 | NCResult(const NCResult<T> &r, Compute*c):ResultInfo(c)
|
---|
| 61 | { _result=r._result; }
|
---|
| 62 | operator T&() { update(); return _result; };
|
---|
| 63 | T& result() { update(); return _result; };
|
---|
| 64 | T& result_noupdate() { return _result; };
|
---|
| 65 | const T& result_noupdate() const { return _result; };
|
---|
| 66 | void operator=(const T& a) { _result = a; }
|
---|
| 67 | void operator=(const NCResult<T> &r)
|
---|
| 68 | { ResultInfo::operator=(r); _result = r._result; };
|
---|
| 69 | };
|
---|
| 70 |
|
---|
| 71 | /** This associates a result datum with an accuracy. If the result datum
|
---|
| 72 | is to be saved or restored use SSAccResult. */
|
---|
| 73 | template <class T>
|
---|
| 74 | class AccResult: public AccResultInfo {
|
---|
| 75 | private:
|
---|
| 76 | T _result;
|
---|
| 77 | public:
|
---|
| 78 | AccResult(Compute*c):AccResultInfo(c) {};
|
---|
| 79 | AccResult(const AccResult<T> &r, Compute*c):AccResultInfo(c)
|
---|
| 80 | { _result=r._result; }
|
---|
| 81 | operator T&() { update(); return _result; };
|
---|
| 82 | T* operator ->() { update(); return &_result; };
|
---|
| 83 | T& result() { update(); return _result; };
|
---|
| 84 | T& result_noupdate() { return _result; };
|
---|
| 85 | const T& result_noupdate() const { return _result; };
|
---|
| 86 | void operator=(const T& a) { _result = a; }
|
---|
| 87 | void operator=(const AccResult<T> &r)
|
---|
| 88 | { AccResultInfo::operator=(r); _result = r._result; };
|
---|
| 89 | void restore_state(StateIn&s) {
|
---|
| 90 | AccResultInfo::restore_state(s);
|
---|
| 91 | }
|
---|
| 92 | void save_data_state(StateOut&s)
|
---|
| 93 | {
|
---|
| 94 | AccResultInfo::save_data_state(s);
|
---|
| 95 | }
|
---|
| 96 | AccResult(StateIn&s,Compute*c): AccResultInfo(s,c) {}
|
---|
| 97 | };
|
---|
| 98 |
|
---|
| 99 | /** This associates a result datum with an accuracy. The
|
---|
| 100 | datum must be a SavableState and will be saved and restored. */
|
---|
| 101 | template <class T>
|
---|
| 102 | class SSAccResult: public AccResultInfo {
|
---|
| 103 | private:
|
---|
| 104 | T _result;
|
---|
| 105 | public:
|
---|
| 106 | SSAccResult(Compute*c):AccResultInfo(c) {};
|
---|
| 107 | SSAccResult(const SSAccResult<T> &r, Compute*c):AccResultInfo(c)
|
---|
| 108 | { _result=r._result; }
|
---|
| 109 | operator T&() { update(); return _result; };
|
---|
| 110 | T* operator ->() { update(); return &_result; };
|
---|
| 111 | T& result() { update(); return _result; };
|
---|
| 112 | T& result_noupdate() { return _result; };
|
---|
| 113 | const T& result_noupdate() const { return _result; };
|
---|
| 114 | void operator=(const T& a) { _result = a; }
|
---|
| 115 | void operator=(const SSAccResult<T> &r)
|
---|
| 116 | { AccResultInfo::operator=(r); _result = r._result; };
|
---|
| 117 | void restore_state(StateIn&s) {
|
---|
| 118 | AccResultInfo::restore_state(s);
|
---|
| 119 | _result.restore_state(s);
|
---|
| 120 | }
|
---|
| 121 | void save_data_state(StateOut&s)
|
---|
| 122 | {
|
---|
| 123 | AccResultInfo::save_data_state(s);
|
---|
| 124 | _result.save_data_state(s);
|
---|
| 125 | }
|
---|
| 126 | SSAccResult(StateIn&s,Compute*c): AccResultInfo(s,c), _result(s) {}
|
---|
| 127 | };
|
---|
| 128 |
|
---|
| 129 | /** This associates a result non-class datum with an accuracy. */
|
---|
| 130 | template <class T>
|
---|
| 131 | class NCAccResult: public AccResultInfo {
|
---|
| 132 | private:
|
---|
| 133 | T _result;
|
---|
| 134 | public:
|
---|
| 135 | NCAccResult(Compute*c):AccResultInfo(c) {};
|
---|
| 136 | NCAccResult(const NCAccResult<T> &r, Compute*c):AccResultInfo(c)
|
---|
| 137 | { _result=r._result; }
|
---|
| 138 | operator T&() { update(); return _result; };
|
---|
| 139 | T& result() { update(); return _result; };
|
---|
| 140 | T& result_noupdate() { return _result; };
|
---|
| 141 | const T& result_noupdate() const { return _result; };
|
---|
| 142 | void operator=(const T& a) { _result = a; }
|
---|
| 143 | void operator=(const NCAccResult<T> &r)
|
---|
| 144 | { AccResultInfo::operator=(r); _result = r._result; };
|
---|
| 145 | void restore_state(StateIn&s) {
|
---|
| 146 | AccResultInfo::restore_state(s);
|
---|
| 147 | s.get(_result);
|
---|
| 148 | }
|
---|
| 149 | void save_data_state(StateOut&s)
|
---|
| 150 | {
|
---|
| 151 | AccResultInfo::save_data_state(s);
|
---|
| 152 | s.put(_result);
|
---|
| 153 | }
|
---|
| 154 | NCAccResult(StateIn&s,Compute*c): AccResultInfo(s,c) {s.get(_result);}
|
---|
| 155 | };
|
---|
| 156 |
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | // ///////////////////////////////////////////////////////////////////////////
|
---|
| 160 |
|
---|
| 161 | // Local Variables:
|
---|
| 162 | // mode: c++
|
---|
| 163 | // c-file-style: "CLJ"
|
---|
| 164 | // End:
|
---|