00001 // This is core/vul/vul_ios_state.h 00002 #ifndef vul_ios_state_h_ 00003 #define vul_ios_state_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \brief saves and restores stream state 00010 // \author Ian Scott, Imorphics. 00011 // \date 03 April 2007 00012 // 00013 // Modifications are subject to the VXL license. 00014 // 00015 // Copied from http://www.boost.org/boost/io/ios_state.hpp 00016 // 00017 // Original: 00018 // Copyright 2002, 2005 Daryle Walker. Use, modification, and distribution 00019 // are subject to the Boost Software License, Version 1.0. (See accompanying 00020 // file LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.) 00021 // 00022 // Boost Software License - Version 1.0 - August 17th, 2003 00023 // 00024 // Permission is hereby granted, free of charge, to any person or organization 00025 // obtaining a copy of the software and accompanying documentation covered by 00026 // this license (the "Software") to use, reproduce, display, distribute, 00027 // execute, and transmit the Software, and to prepare derivative works of the 00028 // Software, and to permit third-parties to whom the Software is furnished to 00029 // do so, all subject to the following: 00030 // 00031 // The copyright notices in the Software and this entire statement, including 00032 // the above license grant, this restriction and the following disclaimer, 00033 // must be included in all copies of the Software, in whole or in part, and 00034 // all derivative works of the Software, unless such copies or derivative 00035 // works are solely in the form of machine-executable object code generated by 00036 // a source language processor. 00037 // 00038 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00039 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00040 // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 00041 // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 00042 // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 00043 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00044 // DEALINGS IN THE SOFTWARE. 00045 00046 #include <vcl_ios.h> 00047 00048 //: Use RAII to save and restore precision and other state on an iostream 00049 class vul_ios_state_saver 00050 { 00051 public: 00052 explicit vul_ios_state_saver( vcl_ios_base &s ) 00053 : stream_( s ), 00054 flags_( s.flags() ), 00055 precision_( s.precision() ), 00056 width_( s.width() ) 00057 {} 00058 ~vul_ios_state_saver() 00059 { this->restore(); } 00060 00061 void restore() 00062 { 00063 stream_.width(width_); 00064 stream_.precision(precision_); 00065 stream_.flags(flags_); 00066 } 00067 00068 private: 00069 vcl_ios_base & stream_; 00070 const vcl_ios_fmtflags flags_; 00071 const vcl_streamsize precision_; 00072 const vcl_streamsize width_; 00073 }; 00074 00075 #endif