MPQC  2.3.1
comptmpl.h
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 
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 
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 
73 template <class T>
74 class AccResult: public AccResultInfo {
75  private:
76  T _result;
77  public:
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  }
97 };
98 
101 template <class T>
102 class SSAccResult: public AccResultInfo {
103  private:
104  T _result;
105  public:
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 
130 template <class T>
131 class NCAccResult: public AccResultInfo {
132  private:
133  T _result;
134  public:
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:
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::AccResult
This associates a result datum with an accuracy.
Definition: comptmpl.h:74
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::SSAccResult
This associates a result datum with an accuracy.
Definition: comptmpl.h:102
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::NCAccResult
This associates a result non-class datum with an accuracy.
Definition: comptmpl.h:131
sc::StateOut::put
virtual int put(const ClassDesc *)
Write out information about the given ClassDesc.
sc::Result
Result are members of Compute specializations that keep track of whether or not a particular result s...
Definition: comptmpl.h:35
sc::NCResult
This is similar to Result, but can be used with non-class types.
Definition: comptmpl.h:55
sc::StateIn::get
virtual int get(const ClassDesc **)
This restores ClassDesc's.

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