]> git.lyx.org Git - lyx.git/blobdiff - boost/boost/tuple/tuple_io.hpp
boost: update to 1.47.0
[lyx.git] / boost / boost / tuple / tuple_io.hpp
index 5ca9e8e5fa8d5bf7528a47db8ce3e8007e0998e2..c549716ebd17af7150fb8c6683736a6a5f2b287f 100644 (file)
@@ -1,16 +1,11 @@
 // tuple_io.hpp --------------------------------------------------------------
 
-// Copyright (C) 2001 Jaakko Jรคrvi (jaakko.jarvi@cs.utu.fi)
+// Copyright (C) 2001 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
 //               2001 Gary Powell (gary.powell@sierra.com)
 //
-// Permission to copy, use, sell and distribute this software is granted
-// provided this copyright notice appears in all copies. 
-// Permission to modify the code and to distribute modified code is granted
-// provided this copyright notice appears in all copies, and a notice 
-// that the code was modified is included with the copyright notice.
-//
-// This software is provided "as is" without express or implied warranty, 
-// and with no claim as to its suitability for any purpose.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
 // For more information, see http://www.boost.org 
 
 // ----------------------------------------------------------------------------
@@ -34,6 +29,8 @@
 #include <ostream>
 #endif  
 
+#include <sstream>
+
 #include "boost/tuple/tuple.hpp"
 
 // This is ugly: one should be using twoargument isspace since whitspace can
@@ -86,9 +83,9 @@ public:
      // parentheses and space are the default manipulators
      if (!c) {
        switch(m) {
-         case open : c = '('; break;
-         case close : c = ')'; break;
-         case delimiter : c = ' '; break;
+         case detail::format_info::open : c = '('; break;
+         case detail::format_info::close : c = ')'; break;
+         case detail::format_info::delimiter : c = ' '; break;
        }
      }
      return c;
@@ -109,9 +106,9 @@ public:
      // parentheses and space are the default manipulators
      if (!c) {
        switch(m) {
-         case open :  c = i.widen('('); break;
-         case close : c = i.widen(')'); break;
-         case delimiter : c = i.widen(' '); break;
+         case detail::format_info::open :  c = i.widen('('); break;
+         case detail::format_info::close : c = i.widen(')'); break;
+         case detail::format_info::delimiter : c = i.widen(' '); break;
        }
      }
      return c;
@@ -249,6 +246,22 @@ print(std::ostream& o, const cons<T1, T2>& t) {
 
 }
 
+template<class T>
+inline bool handle_width(std::ostream& o, const T& t) {
+    std::streamsize width = o.width();
+    if(width == 0) return false;
+
+    std::ostringstream ss;
+
+    ss.copyfmt(o);
+    ss.tie(0);
+    ss.width(0);
+
+    ss << t;
+    o << ss.str();
+
+    return true;
+}
 
 
 #else
@@ -285,14 +298,48 @@ print(std::basic_ostream<CharType, CharTrait>& o, const cons<T1, T2>& t) {
   return print(o, t.tail);
 }
 
+template<class CharT, class Traits, class T>
+inline bool handle_width(std::basic_ostream<CharT, Traits>& o, const T& t) {
+    std::streamsize width = o.width();
+    if(width == 0) return false;
+
+    std::basic_ostringstream<CharT, Traits> ss;
+
+    ss.copyfmt(o);
+    ss.tie(0);
+    ss.width(0);
+
+    ss << t;
+    o << ss.str();
+
+    return true;
+}
+
 #endif  // BOOST_NO_TEMPLATED_STREAMS
 
 } // namespace detail
 
 #if defined (BOOST_NO_TEMPLATED_STREAMS)
+
+inline std::ostream& operator<<(std::ostream& o, const null_type& t) {
+  if (!o.good() ) return o;
+  if (detail::handle_width(o, t)) return o;
+  const char l = 
+    detail::format_info::get_manipulator(o, detail::format_info::open);
+  const char r = 
+    detail::format_info::get_manipulator(o, detail::format_info::close);
+   
+  o << l;
+  o << r;
+
+  return o;
+}
+
 template<class T1, class T2>
 inline std::ostream& operator<<(std::ostream& o, const cons<T1, T2>& t) {
   if (!o.good() ) return o;
+  if (detail::handle_width(o, t)) return o;
  
   const char l = 
     detail::format_info::get_manipulator(o, detail::format_info::open);
@@ -310,11 +357,30 @@ inline std::ostream& operator<<(std::ostream& o, const cons<T1, T2>& t) {
 
 #else
 
+template<class CharType, class CharTrait>
+inline std::basic_ostream<CharType, CharTrait>& 
+operator<<(std::basic_ostream<CharType, CharTrait>& o, 
+           const null_type& t) {
+  if (!o.good() ) return o;
+  if (detail::handle_width(o, t)) return o;
+  const CharType l = 
+    detail::format_info::get_manipulator(o, detail::format_info::open);
+  const CharType r = 
+    detail::format_info::get_manipulator(o, detail::format_info::close);
+   
+  o << l;
+  o << r;
+
+  return o;
+}
+
 template<class CharType, class CharTrait, class T1, class T2>
 inline std::basic_ostream<CharType, CharTrait>& 
 operator<<(std::basic_ostream<CharType, CharTrait>& o, 
            const cons<T1, T2>& t) {
   if (!o.good() ) return o;
+  if (detail::handle_width(o, t)) return o;
  
   const CharType l = 
     detail::format_info::get_manipulator(o, detail::format_info::open);
@@ -354,9 +420,11 @@ extract_and_check_delimiter(
   char c;
   if (is_delimiter) { 
     is >> c; 
-    if (c!=d) {
+    if (is.good() && c!=d) {
       is.setstate(std::ios::failbit);
     } 
+  } else {
+    is >> std::ws;
   }
   return is;
 }
@@ -438,6 +506,9 @@ extract_and_check_delimiter(
 
 #if defined (BOOST_NO_STD_LOCALE)
   const bool is_delimiter = !isspace(d);
+#elif defined ( __BORLANDC__ )
+  const bool is_delimiter = !std::use_facet< std::ctype< CharType > >
+    (is.getloc() ).is( std::ctype_base::space, d);
 #else
   const bool is_delimiter = (!std::isspace(d, is.getloc()) );            
 #endif
@@ -445,9 +516,11 @@ extract_and_check_delimiter(
   CharType c;
   if (is_delimiter) { 
     is >> c;
-    if (c!=d) { 
+    if (is.good() && c!=d) { 
       is.setstate(std::ios::failbit);
     }
+  } else {
+    is >> std::ws;
   }
   return is;
 }