contrib/oxl/mvl/mvl_modify_handle.h
Go to the documentation of this file.
00001 // This is oxl/mvl/mvl_modify_handle.h
00002 #ifndef mvl_modify_handle_h_
00003 #define mvl_modify_handle_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Temporarily modify a value, restoring on end-of-block
00010 //
00011 //    Take a pointer to some type, and when the mvl_modify_handle goes out
00012 //    of scope, restore the old value.
00013 //
00014 // \author
00015 //     Andrew W. Fitzgibbon, Oxford RRG, 03 Aug 96
00016 //
00017 //-----------------------------------------------------------------------------
00018 
00019 template <class T>
00020 class mvl_modify_handle
00021 {
00022   T  oldvalue_;
00023   T* place_;
00024  public:
00025   mvl_modify_handle(T* place) { place_ = place; oldvalue_ = *place; }
00026   ~mvl_modify_handle() { *place_ = oldvalue_; }
00027   operator T* () { return place_; }
00028   T& operator*() { return *place_; }
00029 };
00030 
00031 #endif // mvl_modify_handle_h_