MPQC  3.0.0-alpha
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 #include <util/misc/compute.h>
29 
30 namespace sc {
31 
36 template <class T>
37 class Result: public ResultInfo {
38  private:
39  T _result;
40  public:
41  Result(Compute*c):ResultInfo(c) {};
42  Result(const Result<T> &r, Compute*c):ResultInfo(c)
43  { _result=r._result; }
44  operator T&() { update(); return _result; };
45  T* operator ->() { update(); return &_result; };
46  T& result() { update(); return _result; };
47  T& result_noupdate() { return _result; };
48  const T& result_noupdate() const { return _result; };
49  void operator=(const T& a) { _result = a; }
50  void operator=(const Result<T> &r)
51  { ResultInfo::operator=(r); _result = r._result; };
52 
53  // C++11-specific features
54 #if __cplusplus > 199711L
55  template <typename In>
56  auto operator()(In i) const -> decltype(_result(i)) {
57  return _result(i);
58  }
59  template <typename In>
60  auto operator()(In i) -> decltype(_result(i)) {
61  return _result(i);
62  }
63 #endif // C++11
64 };
65 
68 template <class T>
69 class NCResult: public ResultInfo {
70  private:
71  T _result;
72  public:
73  NCResult(Compute*c):ResultInfo(c) {};
74  NCResult(const NCResult<T> &r, Compute*c):ResultInfo(c)
75  { _result=r._result; }
76  operator T&() { update(); return _result; };
77  T& result() { update(); return _result; };
78  T& result_noupdate() { return _result; };
79  const T& result_noupdate() const { return _result; };
80  void operator=(const T& a) { _result = a; }
81  void operator=(const NCResult<T> &r)
82  { ResultInfo::operator=(r); _result = r._result; };
83 };
84 
87 template <class T>
88 class AccResult: public AccResultInfo {
89  private:
90  T _result;
91  public:
94  { _result=r._result; }
95  operator T&() { update(); return _result; };
96  T* operator ->() { update(); return &_result; };
97  T& result() { update(); return _result; };
98  T& result_noupdate() { return _result; };
99  const T& result_noupdate() const { return _result; };
100  void operator=(const T& a) { _result = a; }
101  void operator=(const AccResult<T> &r)
102  { AccResultInfo::operator=(r); _result = r._result; };
103  void restore_state(StateIn&s) {
104  AccResultInfo::restore_state(s);
105  }
106  void save_data_state(StateOut&s)
107  {
108  AccResultInfo::save_data_state(s);
109  }
110  AccResult(StateIn&s,Compute*c): AccResultInfo(s,c) {}
111 
112  // C++11-specific features
113 #if __cplusplus > 199711L
114  template <typename In>
115  auto operator()(In i) const -> decltype(_result(i)) {
116  return _result(i);
117  }
118  template <typename In>
119  auto operator()(In i) -> decltype(_result(i)) {
120  return _result(i);
121  }
122 #endif // C++11
123 };
124 
127 template <class T>
128 class SSAccResult: public AccResultInfo {
129  private:
130  T _result;
131  public:
134  { _result=r._result; }
135  operator T&() { update(); return _result; };
136  T* operator ->() { update(); return &_result; };
137  T& result() { update(); return _result; };
138  T& result_noupdate() { return _result; };
139  const T& result_noupdate() const { return _result; };
140  void operator=(const T& a) { _result = a; }
141  void operator=(const SSAccResult<T> &r)
142  { AccResultInfo::operator=(r); _result = r._result; };
143  void restore_state(StateIn&s) {
144  AccResultInfo::restore_state(s);
145  _result.restore_state(s);
146  }
147  void save_data_state(StateOut&s)
148  {
149  AccResultInfo::save_data_state(s);
150  _result.save_data_state(s);
151  }
152  SSAccResult(StateIn&s,Compute*c): AccResultInfo(s,c), _result(s) {}
153 };
154 
156 template <class T>
157 class NCAccResult: public AccResultInfo {
158  private:
159  T _result;
160  public:
163  { _result=r._result; }
164  operator T&() { update(); return _result; };
165  T& result() { update(); return _result; };
166  T& result_noupdate() { return _result; };
167  const T& result_noupdate() const { return _result; };
168  void operator=(const T& a) { _result = a; }
169  void operator=(const NCAccResult<T> &r)
170  { AccResultInfo::operator=(r); _result = r._result; };
171  void restore_state(StateIn&s) {
172  AccResultInfo::restore_state(s);
173  s.get(_result);
174  }
175  void save_data_state(StateOut&s)
176  {
177  AccResultInfo::save_data_state(s);
178  s.put(_result);
179  }
180  NCAccResult(StateIn&s,Compute*c): AccResultInfo(s,c) {s.get(_result);}
181 };
182 
183 }
184 
185 // ///////////////////////////////////////////////////////////////////////////
186 
187 // Local Variables:
188 // mode: c++
189 // c-file-style: "CLJ"
190 // 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:110
sc::AccResult
This associates a result datum with an accuracy.
Definition: comptmpl.h:88
sc::StateIn
Definition: statein.h:79
sc::ResultInfo
This is a base class for all of Compute's result types.
Definition: compute.h:82
sc::SSAccResult
This associates a result datum with an accuracy.
Definition: comptmpl.h:128
sc::StateOut
Definition: stateout.h:71
sc::Compute
The Compute class provides a means of keeping results up to date.
Definition: compute.h:51
sc::NCAccResult
This associates a result non-class datum with an accuracy.
Definition: comptmpl.h:157
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:37
sc::NCResult
This is similar to Result, but can be used with non-class types.
Definition: comptmpl.h:69
sc::StateIn::get
virtual int get(const ClassDesc **)
This restores ClassDesc's.
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14

Generated at Sun Jan 26 2020 23:24:01 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.