source: ThirdParty/mpqc_open/src/lib/util/misc/comptmpl.h@ bbc982

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since bbc982 was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 5.5 KB
Line 
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
28namespace 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. */
34template <class T>
35class 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. */
54template <class T>
55class 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. */
73template <class T>
74class 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. */
101template <class T>
102class 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. */
130template <class T>
131class 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:
Note: See TracBrowser for help on using the repository browser.