os/ossrv/ossrv_pub/boost_apis/boost/tuple/tuple_io.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/tuple/tuple_io.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,525 @@
     1.4 +// tuple_io.hpp --------------------------------------------------------------
     1.5 +
     1.6 +// Copyright (C) 2001 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
     1.7 +//               2001 Gary Powell (gary.powell@sierra.com)
     1.8 +//
     1.9 +// Distributed under the Boost Software License, Version 1.0. (See
    1.10 +// accompanying file LICENSE_1_0.txt or copy at
    1.11 +// http://www.boost.org/LICENSE_1_0.txt)
    1.12 +// For more information, see http://www.boost.org 
    1.13 +
    1.14 +// ----------------------------------------------------------------------------
    1.15 +
    1.16 +#ifndef BOOST_TUPLE_IO_HPP
    1.17 +#define BOOST_TUPLE_IO_HPP
    1.18 +
    1.19 +
    1.20 +// add to boost/config.hpp
    1.21 +// for now
    1.22 +# if defined __GNUC__
    1.23 +#   if (__GNUC__ == 2 && __GNUC_MINOR__ <= 97) 
    1.24 +#define BOOST_NO_TEMPLATED_STREAMS
    1.25 +#endif
    1.26 +#endif // __GNUC__
    1.27 +
    1.28 +#if defined BOOST_NO_TEMPLATED_STREAMS
    1.29 +#include <iostream>
    1.30 +#else 
    1.31 +#include <istream>
    1.32 +#include <ostream>
    1.33 +#endif  
    1.34 +
    1.35 +#include "boost/tuple/tuple.hpp"
    1.36 +
    1.37 +// This is ugly: one should be using twoargument isspace since whitspace can
    1.38 +// be locale dependent, in theory at least.
    1.39 +// not all libraries implement have the two-arg version, so we need to 
    1.40 +// use the one-arg one, which one should get with <cctype> but there seem
    1.41 +// to be exceptions to this.
    1.42 +
    1.43 +#if !defined (BOOST_NO_STD_LOCALE)
    1.44 +
    1.45 +#include <locale> // for two-arg isspace
    1.46 +
    1.47 +#else 
    1.48 +
    1.49 +#include <cctype> // for one-arg (old) isspace 
    1.50 +#include <ctype.h> // Metrowerks does not find one-arg isspace from cctype
    1.51 +
    1.52 +#endif
    1.53 +
    1.54 +namespace boost {
    1.55 +namespace tuples {
    1.56 +
    1.57 +namespace detail {
    1.58 +
    1.59 +class format_info {
    1.60 +public:   
    1.61 +
    1.62 +   enum manipulator_type { open, close, delimiter };
    1.63 +   BOOST_STATIC_CONSTANT(int, number_of_manipulators = delimiter + 1);
    1.64 +private:
    1.65 +   
    1.66 +   static int get_stream_index (int m)
    1.67 +   {
    1.68 +     static const int stream_index[number_of_manipulators]
    1.69 +        = { std::ios::xalloc(), std::ios::xalloc(), std::ios::xalloc() };
    1.70 +
    1.71 +     return stream_index[m];
    1.72 +   }
    1.73 +
    1.74 +   format_info(const format_info&);
    1.75 +   format_info();   
    1.76 +
    1.77 +
    1.78 +public:
    1.79 +
    1.80 +#if defined (BOOST_NO_TEMPLATED_STREAMS)
    1.81 +   static char get_manipulator(std::ios& i, manipulator_type m) {
    1.82 +     char c = static_cast<char>(i.iword(get_stream_index(m))); 
    1.83 +     
    1.84 +     // parentheses and space are the default manipulators
    1.85 +     if (!c) {
    1.86 +       switch(m) {
    1.87 +         case detail::format_info::open : c = '('; break;
    1.88 +         case detail::format_info::close : c = ')'; break;
    1.89 +         case detail::format_info::delimiter : c = ' '; break;
    1.90 +       }
    1.91 +     }
    1.92 +     return c;
    1.93 +   }
    1.94 +
    1.95 +   static void set_manipulator(std::ios& i, manipulator_type m, char c) {
    1.96 +      i.iword(get_stream_index(m)) = static_cast<long>(c);
    1.97 +   }
    1.98 +#else
    1.99 +   template<class CharType, class CharTrait>
   1.100 +   static CharType get_manipulator(std::basic_ios<CharType, CharTrait>& i, 
   1.101 +                                   manipulator_type m) {
   1.102 +     // The manipulators are stored as long.
   1.103 +     // A valid instanitation of basic_stream allows CharType to be any POD,
   1.104 +     // hence, the static_cast may fail (it fails if long is not convertible 
   1.105 +     // to CharType
   1.106 +     CharType c = static_cast<CharType>(i.iword(get_stream_index(m)) ); 
   1.107 +     // parentheses and space are the default manipulators
   1.108 +     if (!c) {
   1.109 +       switch(m) {
   1.110 +         case detail::format_info::open :  c = i.widen('('); break;
   1.111 +         case detail::format_info::close : c = i.widen(')'); break;
   1.112 +         case detail::format_info::delimiter : c = i.widen(' '); break;
   1.113 +       }
   1.114 +     }
   1.115 +     return c;
   1.116 +   }
   1.117 +
   1.118 +
   1.119 +   template<class CharType, class CharTrait>
   1.120 +   static void set_manipulator(std::basic_ios<CharType, CharTrait>& i, 
   1.121 +                               manipulator_type m, CharType c) {
   1.122 +     // The manipulators are stored as long.
   1.123 +     // A valid instanitation of basic_stream allows CharType to be any POD,
   1.124 +     // hence, the static_cast may fail (it fails if CharType is not 
   1.125 +     // convertible long.
   1.126 +      i.iword(get_stream_index(m)) = static_cast<long>(c);
   1.127 +   }
   1.128 +#endif // BOOST_NO_TEMPLATED_STREAMS
   1.129 +};
   1.130 +
   1.131 +} // end of namespace detail
   1.132 + 
   1.133 +template<class CharType>    
   1.134 +class tuple_manipulator {
   1.135 +  const detail::format_info::manipulator_type mt;
   1.136 +  CharType f_c;
   1.137 +public:
   1.138 +  explicit tuple_manipulator(detail::format_info::manipulator_type m, 
   1.139 +                             const char c = 0)
   1.140 +     : mt(m), f_c(c) {}
   1.141 +  
   1.142 +#if defined (BOOST_NO_TEMPLATED_STREAMS)
   1.143 +  void set(std::ios &io) const {
   1.144 +     detail::format_info::set_manipulator(io, mt, f_c);
   1.145 +  }
   1.146 +#else
   1.147 +#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
   1.148 +   template<class CharType2, class CharTrait>
   1.149 +  void set(std::basic_ios<CharType2, CharTrait> &io) const {
   1.150 +     detail::format_info::set_manipulator(io, mt, f_c);
   1.151 +  }
   1.152 +#else
   1.153 +   template<class CharTrait>
   1.154 +  void set(std::basic_ios<CharType, CharTrait> &io) const {
   1.155 +     detail::format_info::set_manipulator(io, mt, f_c);
   1.156 +  }
   1.157 +#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
   1.158 +#endif // BOOST_NO_TEMPLATED_STREAMS
   1.159 +};
   1.160 +
   1.161 +#if defined (BOOST_NO_TEMPLATED_STREAMS)
   1.162 +inline std::ostream&
   1.163 +operator<<(std::ostream& o, const tuple_manipulator<char>& m) {
   1.164 +  m.set(o);
   1.165 +  return o;
   1.166 +}
   1.167 +
   1.168 +inline std::istream&
   1.169 +operator>>(std::istream& i, const tuple_manipulator<char>& m) {
   1.170 +  m.set(i);
   1.171 +  return i;
   1.172 +}
   1.173 +
   1.174 +#else
   1.175 +
   1.176 +template<class CharType, class CharTrait>
   1.177 +inline std::basic_ostream<CharType, CharTrait>&
   1.178 +operator<<(std::basic_ostream<CharType, CharTrait>& o, const tuple_manipulator<CharType>& m) {
   1.179 +  m.set(o);
   1.180 +  return o;
   1.181 +}
   1.182 +
   1.183 +template<class CharType, class CharTrait>
   1.184 +inline std::basic_istream<CharType, CharTrait>&
   1.185 +operator>>(std::basic_istream<CharType, CharTrait>& i, const tuple_manipulator<CharType>& m) {
   1.186 +  m.set(i);
   1.187 +  return i;
   1.188 +}
   1.189 +
   1.190 +#endif   // BOOST_NO_TEMPLATED_STREAMS
   1.191 +   
   1.192 +template<class CharType>
   1.193 +inline tuple_manipulator<CharType> set_open(const CharType c) {
   1.194 +   return tuple_manipulator<CharType>(detail::format_info::open, c);
   1.195 +}
   1.196 +
   1.197 +template<class CharType>
   1.198 +inline tuple_manipulator<CharType> set_close(const CharType c) {
   1.199 +   return tuple_manipulator<CharType>(detail::format_info::close, c);
   1.200 +}
   1.201 +
   1.202 +template<class CharType>
   1.203 +inline tuple_manipulator<CharType> set_delimiter(const CharType c) {
   1.204 +   return tuple_manipulator<CharType>(detail::format_info::delimiter, c);
   1.205 +}
   1.206 +
   1.207 +
   1.208 +
   1.209 +   
   1.210 +   
   1.211 +// -------------------------------------------------------------
   1.212 +// printing tuples to ostream in format (a b c)
   1.213 +// parentheses and space are defaults, but can be overriden with manipulators
   1.214 +// set_open, set_close and set_delimiter
   1.215 +   
   1.216 +namespace detail {
   1.217 +
   1.218 +// Note: The order of the print functions is critical 
   1.219 +// to let a conforming compiler  find and select the correct one.
   1.220 +
   1.221 +#if defined (BOOST_NO_TEMPLATED_STREAMS)
   1.222 +
   1.223 +#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
   1.224 +template<class T1>
   1.225 +inline std::ostream& print(std::ostream& o, const cons<T1, null_type>& t) {
   1.226 +  return o << t.head;
   1.227 +}
   1.228 +#endif // BOOST_NO_TEMPLATED_STREAMS
   1.229 + 
   1.230 +inline std::ostream& print(std::ostream& o, const null_type&) { return o; }
   1.231 +
   1.232 +template<class T1, class T2>
   1.233 +inline std::ostream& 
   1.234 +print(std::ostream& o, const cons<T1, T2>& t) {
   1.235 +  
   1.236 +  const char d = format_info::get_manipulator(o, format_info::delimiter);
   1.237 +   
   1.238 +  o << t.head;
   1.239 +
   1.240 +#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
   1.241 +  if (tuples::length<T2>::value == 0)
   1.242 +    return o;
   1.243 +#endif  // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
   1.244 +  o << d;
   1.245 +  
   1.246 +  return print(o, t.tail );
   1.247 +
   1.248 +}
   1.249 +
   1.250 +
   1.251 +
   1.252 +#else
   1.253 +
   1.254 +#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
   1.255 +template<class CharType, class CharTrait, class T1>
   1.256 +inline std::basic_ostream<CharType, CharTrait>& 
   1.257 +print(std::basic_ostream<CharType, CharTrait>& o, const cons<T1, null_type>& t) {
   1.258 +  return o << t.head;
   1.259 +}
   1.260 +#endif  // !BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
   1.261 +
   1.262 + 
   1.263 +template<class CharType, class CharTrait>
   1.264 +inline std::basic_ostream<CharType, CharTrait>& 
   1.265 +print(std::basic_ostream<CharType, CharTrait>& o, const null_type&) { 
   1.266 +  return o; 
   1.267 +}
   1.268 +
   1.269 +template<class CharType, class CharTrait, class T1, class T2>
   1.270 +inline std::basic_ostream<CharType, CharTrait>& 
   1.271 +print(std::basic_ostream<CharType, CharTrait>& o, const cons<T1, T2>& t) {
   1.272 +  
   1.273 +  const CharType d = format_info::get_manipulator(o, format_info::delimiter);
   1.274 +   
   1.275 +  o << t.head;
   1.276 +
   1.277 +#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
   1.278 +  if (tuples::length<T2>::value == 0)
   1.279 +    return o;
   1.280 +#endif  // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
   1.281 +  o << d;
   1.282 +
   1.283 +  return print(o, t.tail);
   1.284 +}
   1.285 +
   1.286 +#endif  // BOOST_NO_TEMPLATED_STREAMS
   1.287 +
   1.288 +} // namespace detail
   1.289 +
   1.290 +#if defined (BOOST_NO_TEMPLATED_STREAMS)
   1.291 +template<class T1, class T2>
   1.292 +inline std::ostream& operator<<(std::ostream& o, const cons<T1, T2>& t) {
   1.293 +  if (!o.good() ) return o;
   1.294 + 
   1.295 +  const char l = 
   1.296 +    detail::format_info::get_manipulator(o, detail::format_info::open);
   1.297 +  const char r = 
   1.298 +    detail::format_info::get_manipulator(o, detail::format_info::close);
   1.299 +   
   1.300 +  o << l;
   1.301 +  
   1.302 +  detail::print(o, t);  
   1.303 +
   1.304 +  o << r;
   1.305 +
   1.306 +  return o;
   1.307 +}
   1.308 +
   1.309 +#else
   1.310 +
   1.311 +template<class CharType, class CharTrait, class T1, class T2>
   1.312 +inline std::basic_ostream<CharType, CharTrait>& 
   1.313 +operator<<(std::basic_ostream<CharType, CharTrait>& o, 
   1.314 +           const cons<T1, T2>& t) {
   1.315 +  if (!o.good() ) return o;
   1.316 + 
   1.317 +  const CharType l = 
   1.318 +    detail::format_info::get_manipulator(o, detail::format_info::open);
   1.319 +  const CharType r = 
   1.320 +    detail::format_info::get_manipulator(o, detail::format_info::close);
   1.321 +   
   1.322 +  o << l;   
   1.323 +
   1.324 +  detail::print(o, t);  
   1.325 +
   1.326 +  o << r;
   1.327 +
   1.328 +  return o;
   1.329 +}
   1.330 +#endif // BOOST_NO_TEMPLATED_STREAMS
   1.331 +
   1.332 +   
   1.333 +// -------------------------------------------------------------
   1.334 +// input stream operators
   1.335 +
   1.336 +namespace detail {
   1.337 +
   1.338 +#if defined (BOOST_NO_TEMPLATED_STREAMS)
   1.339 +
   1.340 +inline std::istream& 
   1.341 +extract_and_check_delimiter(
   1.342 +  std::istream& is, format_info::manipulator_type del)
   1.343 +{
   1.344 +  const char d = format_info::get_manipulator(is, del);
   1.345 +
   1.346 +#if defined (BOOST_NO_STD_LOCALE)
   1.347 +  const bool is_delimiter = !isspace(d);
   1.348 +#else
   1.349 +  const bool is_delimiter = (!std::isspace(d, is.getloc()) );            
   1.350 +#endif
   1.351 +
   1.352 +  char c;
   1.353 +  if (is_delimiter) { 
   1.354 +    is >> c; 
   1.355 +    if (is.good() && c!=d) {
   1.356 +      is.setstate(std::ios::failbit);
   1.357 +    } 
   1.358 +  }
   1.359 +  return is;
   1.360 +}
   1.361 +
   1.362 +
   1.363 +// Note: The order of the read functions is critical to let a 
   1.364 +// (conforming?) compiler find and select the correct one.
   1.365 +
   1.366 +#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
   1.367 +template<class T1>
   1.368 +inline  std::istream & 
   1.369 +read (std::istream &is, cons<T1, null_type>& t1) {
   1.370 +
   1.371 +  if (!is.good()) return is;   
   1.372 +   
   1.373 +  return is >> t1.head ;
   1.374 +}
   1.375 +#else
   1.376 +inline std::istream& read(std::istream& i, const null_type&) { return i; }
   1.377 +#endif // !BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
   1.378 +   
   1.379 +template<class T1, class T2>
   1.380 +inline std::istream& 
   1.381 +read(std::istream &is, cons<T1, T2>& t1) {
   1.382 +
   1.383 +  if (!is.good()) return is;
   1.384 +   
   1.385 +  is >> t1.head;
   1.386 +
   1.387 +#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
   1.388 +  if (tuples::length<T2>::value == 0)
   1.389 +    return is;
   1.390 +#endif  // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
   1.391 +
   1.392 +  extract_and_check_delimiter(is, format_info::delimiter);
   1.393 +
   1.394 +  return read(is, t1.tail);
   1.395 +}
   1.396 +
   1.397 +} // end namespace detail
   1.398 +
   1.399 +inline std::istream& 
   1.400 +operator>>(std::istream &is, null_type&) {
   1.401 +
   1.402 +  if (!is.good() ) return is;
   1.403 +
   1.404 +  detail::extract_and_check_delimiter(is, detail::format_info::open);
   1.405 +  detail::extract_and_check_delimiter(is, detail::format_info::close);
   1.406 +
   1.407 +  return is;
   1.408 +}
   1.409 +
   1.410 +
   1.411 +template<class T1, class T2>
   1.412 +inline std::istream& 
   1.413 +operator>>(std::istream& is, cons<T1, T2>& t1) {
   1.414 +
   1.415 +  if (!is.good() ) return is;
   1.416 +
   1.417 +  detail::extract_and_check_delimiter(is, detail::format_info::open);
   1.418 +                      
   1.419 +  detail::read(is, t1);
   1.420 +   
   1.421 +  detail::extract_and_check_delimiter(is, detail::format_info::close);
   1.422 +
   1.423 +  return is;
   1.424 +}
   1.425 +
   1.426 +
   1.427 +
   1.428 +#else
   1.429 +
   1.430 +template<class CharType, class CharTrait>
   1.431 +inline std::basic_istream<CharType, CharTrait>& 
   1.432 +extract_and_check_delimiter(
   1.433 +  std::basic_istream<CharType, CharTrait> &is, format_info::manipulator_type del)
   1.434 +{
   1.435 +  const CharType d = format_info::get_manipulator(is, del);
   1.436 +
   1.437 +#if defined (BOOST_NO_STD_LOCALE)
   1.438 +  const bool is_delimiter = !isspace(d);
   1.439 +#elif defined ( __BORLANDC__ )
   1.440 +  const bool is_delimiter = !std::use_facet< std::ctype< CharType > >
   1.441 +    (is.getloc() ).is( std::ctype_base::space, d);
   1.442 +#else
   1.443 +  const bool is_delimiter = (!std::isspace(d, is.getloc()) );            
   1.444 +#endif
   1.445 +
   1.446 +  CharType c;
   1.447 +  if (is_delimiter) { 
   1.448 +    is >> c;
   1.449 +    if (is.good() && c!=d) { 
   1.450 +      is.setstate(std::ios::failbit);
   1.451 +    }
   1.452 +  }
   1.453 +  return is;
   1.454 +}
   1.455 +
   1.456 +   
   1.457 +#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
   1.458 +template<class CharType, class CharTrait, class T1>
   1.459 +inline  std::basic_istream<CharType, CharTrait> & 
   1.460 +read (std::basic_istream<CharType, CharTrait> &is, cons<T1, null_type>& t1) {
   1.461 +
   1.462 +  if (!is.good()) return is;   
   1.463 +   
   1.464 +  return is >> t1.head; 
   1.465 +}
   1.466 +#else
   1.467 +template<class CharType, class CharTrait>
   1.468 +inline std::basic_istream<CharType, CharTrait>& 
   1.469 +read(std::basic_istream<CharType, CharTrait>& i, const null_type&) { return i; }
   1.470 +
   1.471 +#endif // !BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
   1.472 +
   1.473 +template<class CharType, class CharTrait, class T1, class T2>
   1.474 +inline std::basic_istream<CharType, CharTrait>& 
   1.475 +read(std::basic_istream<CharType, CharTrait> &is, cons<T1, T2>& t1) {
   1.476 +
   1.477 +  if (!is.good()) return is;
   1.478 +   
   1.479 +  is >> t1.head;
   1.480 +
   1.481 +#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
   1.482 +  if (tuples::length<T2>::value == 0)
   1.483 +    return is;
   1.484 +#endif  // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
   1.485 +
   1.486 +  extract_and_check_delimiter(is, format_info::delimiter);
   1.487 +
   1.488 +  return read(is, t1.tail);
   1.489 +}
   1.490 +
   1.491 +} // end namespace detail
   1.492 +
   1.493 +
   1.494 +template<class CharType, class CharTrait>
   1.495 +inline std::basic_istream<CharType, CharTrait>& 
   1.496 +operator>>(std::basic_istream<CharType, CharTrait> &is, null_type&) {
   1.497 +
   1.498 +  if (!is.good() ) return is;
   1.499 +
   1.500 +  detail::extract_and_check_delimiter(is, detail::format_info::open);
   1.501 +  detail::extract_and_check_delimiter(is, detail::format_info::close);
   1.502 +
   1.503 +  return is;
   1.504 +}
   1.505 +
   1.506 +template<class CharType, class CharTrait, class T1, class T2>
   1.507 +inline std::basic_istream<CharType, CharTrait>& 
   1.508 +operator>>(std::basic_istream<CharType, CharTrait>& is, cons<T1, T2>& t1) {
   1.509 +
   1.510 +  if (!is.good() ) return is;
   1.511 +
   1.512 +  detail::extract_and_check_delimiter(is, detail::format_info::open);
   1.513 +                      
   1.514 +  detail::read(is, t1);
   1.515 +   
   1.516 +  detail::extract_and_check_delimiter(is, detail::format_info::close);
   1.517 +
   1.518 +  return is;
   1.519 +}
   1.520 +
   1.521 +#endif // BOOST_NO_TEMPLATED_STREAMS
   1.522 +
   1.523 +} // end of namespace tuples
   1.524 +} // end of namespace boost
   1.525 +
   1.526 +#endif // BOOST_TUPLE_IO_HPP
   1.527 +
   1.528 +