vul_ios_state.h
Go to the documentation of this file.
1 // This is core/vul/vul_ios_state.h
2 #ifndef vul_ios_state_h_
3 #define vul_ios_state_h_
4 //:
5 // \file
6 // \brief saves and restores stream state
7 // \author Ian Scott, Imorphics.
8 // \date 03 April 2007
9 //
10 // Modifications are subject to the VXL license.
11 //
12 // Copied from http://www.boost.org/boost/io/ios_state.hpp
13 //
14 // Original:
15 // Copyright 2002, 2005 Daryle Walker. Use, modification, and distribution
16 // are subject to the Boost Software License, Version 1.0. (See accompanying
17 // file LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
18 //
19 // Boost Software License - Version 1.0 - August 17th, 2003
20 //
21 // Permission is hereby granted, free of charge, to any person or organization
22 // obtaining a copy of the software and accompanying documentation covered by
23 // this license (the "Software") to use, reproduce, display, distribute,
24 // execute, and transmit the Software, and to prepare derivative works of the
25 // Software, and to permit third-parties to whom the Software is furnished to
26 // do so, all subject to the following:
27 //
28 // The copyright notices in the Software and this entire statement, including
29 // the above license grant, this restriction and the following disclaimer,
30 // must be included in all copies of the Software, in whole or in part, and
31 // all derivative works of the Software, unless such copies or derivative
32 // works are solely in the form of machine-executable object code generated by
33 // a source language processor.
34 //
35 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37 // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
38 // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
39 // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
40 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
41 // DEALINGS IN THE SOFTWARE.
42 
43 #include <ios>
44 #ifdef _MSC_VER
45 # include <vcl_msvc_warnings.h>
46 #endif
47 
48 //: Use RAII to save and restore precision and other state on an iostream
50 {
51  public:
52  explicit vul_ios_state_saver( std::ios_base &s )
53  : stream_( s ),
54  flags_( s.flags() ),
55  precision_( s.precision() ),
56  width_( s.width() )
57  {}
59  { this->restore(); }
60 
61  void restore()
62  {
63  stream_.width(width_);
64  stream_.precision(precision_);
65  stream_.flags(flags_);
66  }
67 
68  private:
69  std::ios_base & stream_;
70  const std::ios::fmtflags flags_;
71  const std::streamsize precision_;
72  const std::streamsize width_;
73 };
74 
75 #endif
const std::ios::fmtflags flags_
Definition: vul_ios_state.h:70
vul_ios_state_saver(std::ios_base &s)
Definition: vul_ios_state.h:52
Use RAII to save and restore precision and other state on an iostream.
Definition: vul_ios_state.h:49
std::ios_base & stream_
Definition: vul_ios_state.h:69
const std::streamsize width_
Definition: vul_ios_state.h:72
const std::streamsize precision_
Definition: vul_ios_state.h:71