localvar.h

Go to the documentation of this file.
00001 
00002 
00003 
00015 
00016 // Copyright (C) 1997-2010 by Pawel Pilarczyk.
00017 //
00018 // This file is part of the Homology Library.  This library is free software;
00019 // you can redistribute it and/or modify it under the terms of the GNU
00020 // General Public License as published by the Free Software Foundation;
00021 // either version 2 of the License, or (at your option) any later version.
00022 //
00023 // This library is distributed in the hope that it will be useful,
00024 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00026 // GNU General Public License for more details.
00027 //
00028 // You should have received a copy of the GNU General Public License along
00029 // with this software; see the file "license.txt".  If not, write to the
00030 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00031 // MA 02111-1307, USA.
00032 
00033 // Started on June 12, 2008. Last revision: June 13, 2008.
00034 
00035 
00036 #ifndef _CHOMP_STRUCT_LOCALVAR_H_
00037 #define _CHOMP_STRUCT_LOCALVAR_H_
00038 
00039 
00040 namespace chomp {
00041 namespace homology {
00042 
00043 
00044 // --------------------------------------------------
00045 // -------------------- LOCALVAR --------------------
00046 // --------------------------------------------------
00047 
00053 template <class varType>
00054 class local_var
00055 {
00056 public:
00058         local_var (varType &_variable);
00059 
00062         local_var (varType &_variable, const varType &_newValue);
00063 
00065         ~local_var ();
00066 
00067 private:
00069         varType &var;
00070 
00073         const varType value;
00074 
00075 }; /* class local_var */
00076 
00077 // --------------------------------------------------
00078 
00079 template <class varType>
00080 inline local_var<varType>::local_var (varType &_variable):
00081         var (_variable), value (_variable)
00082 {
00083         return;
00084 } /* local_var */
00085 
00086 template <class varType>
00087 inline local_var<varType>::local_var (varType &_variable,
00088         const varType &_newValue): var (_variable), value (_variable)
00089 {
00090         _variable = _newValue;
00091         return;
00092 } /* local_var */
00093 
00094 template <class varType>
00095 inline local_var<varType>::~local_var ()
00096 {
00097         var = value;
00098         return;
00099 } /* ~local_var */
00100 
00101 
00102 } // namespace homology
00103 } // namespace chomp
00104 
00105 #endif // _CHOMP_STRUCT_LOCALVAR_H_
00106 
00108