The Original CHomP Software
localvar.h
Go to the documentation of this file.
1
3
15
16// Copyright (C) 1997-2020 by Pawel Pilarczyk.
17//
18// This file is part of my research software package. This is free software:
19// you can redistribute it and/or modify it under the terms of the GNU
20// General Public License as published by the Free Software Foundation,
21// either version 3 of the License, or (at your option) any later version.
22//
23// This software is distributed in the hope that it will be useful,
24// but WITHOUT ANY WARRANTY; without even the implied warranty of
25// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26// GNU General Public License for more details.
27//
28// You should have received a copy of the GNU General Public License
29// along with this software; see the file "license.txt". If not,
30// please, see <https://www.gnu.org/licenses/>.
31
32// Started on June 12, 2008. Last revision: June 13, 2008.
33
34
35#ifndef _CHOMP_STRUCT_LOCALVAR_H_
36#define _CHOMP_STRUCT_LOCALVAR_H_
37
38
39namespace chomp {
40namespace homology {
41
42
43// --------------------------------------------------
44// -------------------- LOCALVAR --------------------
45// --------------------------------------------------
46
52template <class varType>
54{
55public:
57 local_var (varType &_variable);
58
61 local_var (varType &_variable, const varType &_newValue);
62
64 ~local_var ();
65
66private:
68 varType &var;
69
72 const varType value;
73
74}; /* class local_var */
75
76// --------------------------------------------------
77
78template <class varType>
79inline local_var<varType>::local_var (varType &_variable):
80 var (_variable), value (_variable)
81{
82 return;
83} /* local_var */
84
85template <class varType>
86inline local_var<varType>::local_var (varType &_variable,
87 const varType &_newValue): var (_variable), value (_variable)
88{
89 _variable = _newValue;
90 return;
91} /* local_var */
92
93template <class varType>
95{
96 var = value;
97 return;
98} /* ~local_var */
99
100
101} // namespace homology
102} // namespace chomp
103
104#endif // _CHOMP_STRUCT_LOCALVAR_H_
105
107
Local variable guardian.
Definition: localvar.h:54
const varType value
The original value of the variable which is going to be restored upon destruction of the guardian obj...
Definition: localvar.h:72
varType & var
Reference to the global variable.
Definition: localvar.h:68
local_var(varType &_variable)
The constructor of a local variable guardian.
Definition: localvar.h:79
~local_var()
The destructor of a local variable guardian.
Definition: localvar.h:94
This namespace contains the entire CHomP library interface.
Definition: bitmaps.h:51