1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/io/ios_state.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,417 @@
1.4 +// Boost io/ios_state.hpp header file --------------------------------------//
1.5 +
1.6 +// Copyright 2002, 2005 Daryle Walker. Use, modification, and distribution
1.7 +// are subject to the Boost Software License, Version 1.0. (See accompanying
1.8 +// file LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
1.9 +
1.10 +// See <http://www.boost.org/libs/io/> for the library's home page.
1.11 +
1.12 +#ifndef BOOST_IO_IOS_STATE_HPP
1.13 +#define BOOST_IO_IOS_STATE_HPP
1.14 +
1.15 +#include <boost/io_fwd.hpp> // self include
1.16 +#include <boost/detail/workaround.hpp>
1.17 +
1.18 +#include <ios> // for std::ios_base, std::basic_ios, etc.
1.19 +#ifndef BOOST_NO_STD_LOCALE
1.20 +#include <locale> // for std::locale
1.21 +#endif
1.22 +#include <ostream> // for std::basic_ostream
1.23 +#include <streambuf> // for std::basic_streambuf
1.24 +#include <string> // for std::char_traits
1.25 +
1.26 +namespace boost
1.27 +{
1.28 +namespace io
1.29 +{
1.30 +
1.31 +
1.32 +// Basic stream state saver class declarations -----------------------------//
1.33 +
1.34 +class ios_flags_saver
1.35 +{
1.36 +public:
1.37 + typedef ::std::ios_base state_type;
1.38 + typedef ::std::ios_base::fmtflags aspect_type;
1.39 +
1.40 + explicit ios_flags_saver( state_type &s )
1.41 + : s_save_( s ), a_save_( s.flags() )
1.42 + {}
1.43 + ios_flags_saver( state_type &s, aspect_type const &a )
1.44 + : s_save_( s ), a_save_( s.flags(a) )
1.45 + {}
1.46 + ~ios_flags_saver()
1.47 + { this->restore(); }
1.48 +
1.49 + void restore()
1.50 + { s_save_.flags( a_save_ ); }
1.51 +
1.52 +private:
1.53 + state_type & s_save_;
1.54 + aspect_type const a_save_;
1.55 +};
1.56 +
1.57 +class ios_precision_saver
1.58 +{
1.59 +public:
1.60 + typedef ::std::ios_base state_type;
1.61 + typedef ::std::streamsize aspect_type;
1.62 +
1.63 + explicit ios_precision_saver( state_type &s )
1.64 + : s_save_( s ), a_save_( s.precision() )
1.65 + {}
1.66 + ios_precision_saver( state_type &s, aspect_type const &a )
1.67 + : s_save_( s ), a_save_( s.precision(a) )
1.68 + {}
1.69 + ~ios_precision_saver()
1.70 + { this->restore(); }
1.71 +
1.72 + void restore()
1.73 + { s_save_.precision( a_save_ ); }
1.74 +
1.75 +private:
1.76 + state_type & s_save_;
1.77 + aspect_type const a_save_;
1.78 +};
1.79 +
1.80 +class ios_width_saver
1.81 +{
1.82 +public:
1.83 + typedef ::std::ios_base state_type;
1.84 + typedef ::std::streamsize aspect_type;
1.85 +
1.86 + explicit ios_width_saver( state_type &s )
1.87 + : s_save_( s ), a_save_( s.width() )
1.88 + {}
1.89 + ios_width_saver( state_type &s, aspect_type const &a )
1.90 + : s_save_( s ), a_save_( s.width(a) )
1.91 + {}
1.92 + ~ios_width_saver()
1.93 + { this->restore(); }
1.94 +
1.95 + void restore()
1.96 + { s_save_.width( a_save_ ); }
1.97 +
1.98 +private:
1.99 + state_type & s_save_;
1.100 + aspect_type const a_save_;
1.101 +};
1.102 +
1.103 +
1.104 +// Advanced stream state saver class template declarations -----------------//
1.105 +
1.106 +template < typename Ch, class Tr >
1.107 +class basic_ios_iostate_saver
1.108 +{
1.109 +public:
1.110 + typedef ::std::basic_ios<Ch, Tr> state_type;
1.111 + typedef ::std::ios_base::iostate aspect_type;
1.112 +
1.113 + explicit basic_ios_iostate_saver( state_type &s )
1.114 + : s_save_( s ), a_save_( s.rdstate() )
1.115 + {}
1.116 + basic_ios_iostate_saver( state_type &s, aspect_type const &a )
1.117 + : s_save_( s ), a_save_( s.rdstate() )
1.118 + { s.clear(a); }
1.119 + ~basic_ios_iostate_saver()
1.120 + { this->restore(); }
1.121 +
1.122 + void restore()
1.123 + { s_save_.clear( a_save_ ); }
1.124 +
1.125 +private:
1.126 + state_type & s_save_;
1.127 + aspect_type const a_save_;
1.128 +};
1.129 +
1.130 +template < typename Ch, class Tr >
1.131 +class basic_ios_exception_saver
1.132 +{
1.133 +public:
1.134 + typedef ::std::basic_ios<Ch, Tr> state_type;
1.135 + typedef ::std::ios_base::iostate aspect_type;
1.136 +
1.137 + explicit basic_ios_exception_saver( state_type &s )
1.138 + : s_save_( s ), a_save_( s.exceptions() )
1.139 + {}
1.140 +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
1.141 + basic_ios_exception_saver( state_type &s, aspect_type a )
1.142 +#else
1.143 + basic_ios_exception_saver( state_type &s, aspect_type const &a )
1.144 +#endif
1.145 + : s_save_( s ), a_save_( s.exceptions() )
1.146 + { s.exceptions(a); }
1.147 + ~basic_ios_exception_saver()
1.148 + { this->restore(); }
1.149 +
1.150 + void restore()
1.151 + { s_save_.exceptions( a_save_ ); }
1.152 +
1.153 +private:
1.154 + state_type & s_save_;
1.155 + aspect_type const a_save_;
1.156 +};
1.157 +
1.158 +template < typename Ch, class Tr >
1.159 +class basic_ios_tie_saver
1.160 +{
1.161 +public:
1.162 + typedef ::std::basic_ios<Ch, Tr> state_type;
1.163 + typedef ::std::basic_ostream<Ch, Tr> * aspect_type;
1.164 +
1.165 + explicit basic_ios_tie_saver( state_type &s )
1.166 + : s_save_( s ), a_save_( s.tie() )
1.167 + {}
1.168 + basic_ios_tie_saver( state_type &s, aspect_type const &a )
1.169 + : s_save_( s ), a_save_( s.tie(a) )
1.170 + {}
1.171 + ~basic_ios_tie_saver()
1.172 + { this->restore(); }
1.173 +
1.174 + void restore()
1.175 + { s_save_.tie( a_save_ ); }
1.176 +
1.177 +private:
1.178 + state_type & s_save_;
1.179 + aspect_type const a_save_;
1.180 +};
1.181 +
1.182 +template < typename Ch, class Tr >
1.183 +class basic_ios_rdbuf_saver
1.184 +{
1.185 +public:
1.186 + typedef ::std::basic_ios<Ch, Tr> state_type;
1.187 + typedef ::std::basic_streambuf<Ch, Tr> * aspect_type;
1.188 +
1.189 + explicit basic_ios_rdbuf_saver( state_type &s )
1.190 + : s_save_( s ), a_save_( s.rdbuf() )
1.191 + {}
1.192 + basic_ios_rdbuf_saver( state_type &s, aspect_type const &a )
1.193 + : s_save_( s ), a_save_( s.rdbuf(a) )
1.194 + {}
1.195 + ~basic_ios_rdbuf_saver()
1.196 + { this->restore(); }
1.197 +
1.198 + void restore()
1.199 + { s_save_.rdbuf( a_save_ ); }
1.200 +
1.201 +private:
1.202 + state_type & s_save_;
1.203 + aspect_type const a_save_;
1.204 +};
1.205 +
1.206 +template < typename Ch, class Tr >
1.207 +class basic_ios_fill_saver
1.208 +{
1.209 +public:
1.210 + typedef ::std::basic_ios<Ch, Tr> state_type;
1.211 + typedef typename state_type::char_type aspect_type;
1.212 +
1.213 + explicit basic_ios_fill_saver( state_type &s )
1.214 + : s_save_( s ), a_save_( s.fill() )
1.215 + {}
1.216 + basic_ios_fill_saver( state_type &s, aspect_type const &a )
1.217 + : s_save_( s ), a_save_( s.fill(a) )
1.218 + {}
1.219 + ~basic_ios_fill_saver()
1.220 + { this->restore(); }
1.221 +
1.222 + void restore()
1.223 + { s_save_.fill( a_save_ ); }
1.224 +
1.225 +private:
1.226 + state_type & s_save_;
1.227 + aspect_type const a_save_;
1.228 +};
1.229 +
1.230 +#ifndef BOOST_NO_STD_LOCALE
1.231 +template < typename Ch, class Tr >
1.232 +class basic_ios_locale_saver
1.233 +{
1.234 +public:
1.235 + typedef ::std::basic_ios<Ch, Tr> state_type;
1.236 + typedef ::std::locale aspect_type;
1.237 +
1.238 + explicit basic_ios_locale_saver( state_type &s )
1.239 + : s_save_( s ), a_save_( s.getloc() )
1.240 + {}
1.241 + basic_ios_locale_saver( state_type &s, aspect_type const &a )
1.242 + : s_save_( s ), a_save_( s.imbue(a) )
1.243 + {}
1.244 + ~basic_ios_locale_saver()
1.245 + { this->restore(); }
1.246 +
1.247 + void restore()
1.248 + { s_save_.imbue( a_save_ ); }
1.249 +
1.250 +private:
1.251 + state_type & s_save_;
1.252 + aspect_type const a_save_;
1.253 +};
1.254 +#endif
1.255 +
1.256 +
1.257 +// User-defined stream state saver class declarations ----------------------//
1.258 +
1.259 +class ios_iword_saver
1.260 +{
1.261 +public:
1.262 + typedef ::std::ios_base state_type;
1.263 + typedef int index_type;
1.264 + typedef long aspect_type;
1.265 +
1.266 + explicit ios_iword_saver( state_type &s, index_type i )
1.267 + : s_save_( s ), a_save_( s.iword(i) ), i_save_( i )
1.268 + {}
1.269 + ios_iword_saver( state_type &s, index_type i, aspect_type const &a )
1.270 + : s_save_( s ), a_save_( s.iword(i) ), i_save_( i )
1.271 + { s.iword(i) = a; }
1.272 + ~ios_iword_saver()
1.273 + { this->restore(); }
1.274 +
1.275 + void restore()
1.276 + { s_save_.iword( i_save_ ) = a_save_; }
1.277 +
1.278 +private:
1.279 + state_type & s_save_;
1.280 + aspect_type const a_save_;
1.281 + index_type const i_save_;
1.282 +};
1.283 +
1.284 +class ios_pword_saver
1.285 +{
1.286 +public:
1.287 + typedef ::std::ios_base state_type;
1.288 + typedef int index_type;
1.289 + typedef void * aspect_type;
1.290 +
1.291 + explicit ios_pword_saver( state_type &s, index_type i )
1.292 + : s_save_( s ), a_save_( s.pword(i) ), i_save_( i )
1.293 + {}
1.294 + ios_pword_saver( state_type &s, index_type i, aspect_type const &a )
1.295 + : s_save_( s ), a_save_( s.pword(i) ), i_save_( i )
1.296 + { s.pword(i) = a; }
1.297 + ~ios_pword_saver()
1.298 + { this->restore(); }
1.299 +
1.300 + void restore()
1.301 + { s_save_.pword( i_save_ ) = a_save_; }
1.302 +
1.303 +private:
1.304 + state_type & s_save_;
1.305 + aspect_type const a_save_;
1.306 + index_type const i_save_;
1.307 +};
1.308 +
1.309 +
1.310 +// Combined stream state saver class (template) declarations ---------------//
1.311 +
1.312 +class ios_base_all_saver
1.313 +{
1.314 +public:
1.315 + typedef ::std::ios_base state_type;
1.316 +
1.317 + explicit ios_base_all_saver( state_type &s )
1.318 + : s_save_( s ), a1_save_( s.flags() ), a2_save_( s.precision() )
1.319 + , a3_save_( s.width() )
1.320 + {}
1.321 +
1.322 + ~ios_base_all_saver()
1.323 + { this->restore(); }
1.324 +
1.325 + void restore()
1.326 + {
1.327 + s_save_.width( a3_save_ );
1.328 + s_save_.precision( a2_save_ );
1.329 + s_save_.flags( a1_save_ );
1.330 + }
1.331 +
1.332 +private:
1.333 + state_type & s_save_;
1.334 + state_type::fmtflags const a1_save_;
1.335 + ::std::streamsize const a2_save_;
1.336 + ::std::streamsize const a3_save_;
1.337 +};
1.338 +
1.339 +template < typename Ch, class Tr >
1.340 +class basic_ios_all_saver
1.341 +{
1.342 +public:
1.343 + typedef ::std::basic_ios<Ch, Tr> state_type;
1.344 +
1.345 + explicit basic_ios_all_saver( state_type &s )
1.346 + : s_save_( s ), a1_save_( s.flags() ), a2_save_( s.precision() )
1.347 + , a3_save_( s.width() ), a4_save_( s.rdstate() )
1.348 + , a5_save_( s.exceptions() ), a6_save_( s.tie() )
1.349 + , a7_save_( s.rdbuf() ), a8_save_( s.fill() )
1.350 + #ifndef BOOST_NO_STD_LOCALE
1.351 + , a9_save_( s.getloc() )
1.352 + #endif
1.353 + {}
1.354 +
1.355 + ~basic_ios_all_saver()
1.356 + { this->restore(); }
1.357 +
1.358 + void restore()
1.359 + {
1.360 + #ifndef BOOST_NO_STD_LOCALE
1.361 + s_save_.imbue( a9_save_ );
1.362 + #endif
1.363 + s_save_.fill( a8_save_ );
1.364 + s_save_.rdbuf( a7_save_ );
1.365 + s_save_.tie( a6_save_ );
1.366 + s_save_.exceptions( a5_save_ );
1.367 + s_save_.clear( a4_save_ );
1.368 + s_save_.width( a3_save_ );
1.369 + s_save_.precision( a2_save_ );
1.370 + s_save_.flags( a1_save_ );
1.371 + }
1.372 +
1.373 +private:
1.374 + state_type & s_save_;
1.375 + typename state_type::fmtflags const a1_save_;
1.376 + ::std::streamsize const a2_save_;
1.377 + ::std::streamsize const a3_save_;
1.378 + typename state_type::iostate const a4_save_;
1.379 + typename state_type::iostate const a5_save_;
1.380 + ::std::basic_ostream<Ch, Tr> * const a6_save_;
1.381 + ::std::basic_streambuf<Ch, Tr> * const a7_save_;
1.382 + typename state_type::char_type const a8_save_;
1.383 + #ifndef BOOST_NO_STD_LOCALE
1.384 + ::std::locale const a9_save_;
1.385 + #endif
1.386 +};
1.387 +
1.388 +class ios_all_word_saver
1.389 +{
1.390 +public:
1.391 + typedef ::std::ios_base state_type;
1.392 + typedef int index_type;
1.393 +
1.394 + ios_all_word_saver( state_type &s, index_type i )
1.395 + : s_save_( s ), i_save_( i ), a1_save_( s.iword(i) )
1.396 + , a2_save_( s.pword(i) )
1.397 + {}
1.398 +
1.399 + ~ios_all_word_saver()
1.400 + { this->restore(); }
1.401 +
1.402 + void restore()
1.403 + {
1.404 + s_save_.pword( i_save_ ) = a2_save_;
1.405 + s_save_.iword( i_save_ ) = a1_save_;
1.406 + }
1.407 +
1.408 +private:
1.409 + state_type & s_save_;
1.410 + index_type const i_save_;
1.411 + long const a1_save_;
1.412 + void * const a2_save_;
1.413 +};
1.414 +
1.415 +
1.416 +} // namespace io
1.417 +} // namespace boost
1.418 +
1.419 +
1.420 +#endif // BOOST_IO_IOS_STATE_HPP