]> git.lyx.org Git - lyx.git/blobdiff - boost/boost/format/internals.hpp
Don't allow newline characters in document settings.
[lyx.git] / boost / boost / format / internals.hpp
index 6c0647b8afe0b62820fb8b00a654a890c0383c68..b0d874a1fb4a26020a6a3026e444c65391029c6a 100644 (file)
@@ -1,39 +1,33 @@
-// -*- C++ -*-
-//  Boost general library 'format'   ---------------------------
-//  See http://www.boost.org for updates, documentation, and revision history.
+// ----------------------------------------------------------------------------
+// internals.hpp :  internal structs : stream_format_state, format_item. 
+//                  included by format.hpp
+// ----------------------------------------------------------------------------
 
-//  (C) Samuel Krempp 2001
-//                  krempp@crans.ens-cachan.fr
-//  Permission to copy, use, modify, sell and
-//  distribute this software is granted provided this copyright notice appears
-//  in all copies. This software is provided "as is" without express or implied
-//  warranty, and with no claim as to its suitability for any purpose.
+//  Copyright Samuel Krempp 2003. Use, modification, and distribution are
+//  subject to 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)
 
-// ideas taken from Rüdiger Loos's format class
-// and Karl Nelson's ofstream
+//  See http://www.boost.org/libs/format for library home page
 
 // ----------------------------------------------------------------------------
-// internals.hpp :  internal structs. included by format.hpp
-//                              stream_format_state, and format_item
-// ----------------------------------------------------------------------------
-
 
 #ifndef BOOST_FORMAT_INTERNALS_HPP
 #define BOOST_FORMAT_INTERNALS_HPP
 
 
 #include <string>
-
 #include <boost/assert.hpp>
-#include <boost/format/outsstream.hpp>
+#include <boost/optional.hpp>
 #include <boost/limits.hpp>
+#include <boost/format/detail/compat_workarounds.hpp>
+#include <boost/format/alt_sstream.hpp> // used as a dummy stream
 
 namespace boost {
 namespace io {
 namespace detail {
 
 
-//----- stream_format_state --------------------------------------------------//
+//---- stream_format_state --------------------------------------------------//
 
 //   set of params that define the format state of a stream
     template<class Ch, class Tr> 
@@ -42,11 +36,12 @@ namespace detail {
         typedef BOOST_IO_STD basic_ios<Ch, Tr>   basic_ios;
 
         stream_format_state(Ch fill)                 { reset(fill); }
-        stream_format_state(const basic_ios& os)     { set_by_stream(os); }
+//        stream_format_state(const basic_ios& os)     { set_by_stream(os); }
 
         void reset(Ch fill);                     //- sets to default state.
         void set_by_stream(const basic_ios& os); //- sets to os's state.
-        void apply_on(basic_ios & os) const;     //- applies format_state to the stream
+        void apply_on(basic_ios & os,            //- applies format_state to the stream
+                      boost::io::detail::locale_t * loc_default = 0) const;
         template<class T> 
         void apply_manip(T manipulator)          //- modifies state by applying manipulator
             { apply_manip_body<Ch, Tr, T>( *this, manipulator) ; }
@@ -58,13 +53,14 @@ namespace detail {
         std::ios_base::fmtflags flags_;
         std::ios_base::iostate  rdstate_;
         std::ios_base::iostate  exceptions_;
+        boost::optional<boost::io::detail::locale_t>  loc_;
     };  
 
 
-//----- format_item  ---------------------------------------------------------//
+//---- format_item  ---------------------------------------------------------//
 
 //   stores all parameters that can be specified in format strings
-    template<class Ch, class Tr>  
+    template<class Ch, class Tr, class Alloc>  
     struct format_item 
     {     
         enum pad_values { zeropad = 1, spacepad =2, centered=4, tabulation = 8 };
@@ -75,9 +71,9 @@ namespace detail {
                           argN_tabulation = -2, // tabulation directive. (no argument read) 
                           argN_ignored    = -3  // ignored directive. (no argument read)
         };
-        typedef BOOST_IO_STD basic_ios<Ch, Tr>              basic_ios;
-        typedef detail::stream_format_state<Ch, Tr>         stream_format_state;
-        typedef std::basic_string<Ch, Tr>                   string_t;
+        typedef BOOST_IO_STD basic_ios<Ch, Tr>                    basic_ios;
+        typedef detail::stream_format_state<Ch, Tr>               stream_format_state;
+        typedef ::std::basic_string<Ch, Tr, Alloc>                string_type;
 
         format_item(Ch fill) :argN_(argN_no_posit), fmtstate_(fill), 
                               truncate_(max_streamsize()), pad_scheme_(0)  {}
@@ -85,28 +81,29 @@ namespace detail {
         void compute_states(); // sets states  according to truncate and pad_scheme.
 
         static std::streamsize max_streamsize() { 
-            return std::numeric_limits<std::streamsize>::max();
+            return (std::numeric_limits<std::streamsize>::max)();
         }
 
         // --- data ---
         int         argN_;  //- argument number (starts at 0,  eg : %1 => argN=0)
                             //  negative values for items that don't process an argument
-        string_t    res_;      //- result of the formatting of this item
-        string_t    appendix_; //- piece of string between this item and the next
+        string_type  res_;      //- result of the formatting of this item
+        string_type  appendix_; //- piece of string between this item and the next
 
         stream_format_state fmtstate_;// set by parsing, is only affected by modify_item
 
-        signed int truncate_;    //- is set for directives like %.5s that ask truncation
+        std::streamsize truncate_;//- is set for directives like %.5s that ask truncation
         unsigned int pad_scheme_;//- several possible padding schemes can mix. see pad_values
     }; 
 
 
 
-//---- Definitions  ------------------------------------------------------------
+//--- Definitions  ------------------------------------------------------------
 
-// ---   stream_format_state:: -------------------------------------------------
+// -   stream_format_state:: -------------------------------------------------
     template<class Ch, class Tr>
-    void stream_format_state<Ch,Tr>:: apply_on(basic_ios & os) const {
+    void stream_format_state<Ch,Tr>:: apply_on (basic_ios & os,
+                      boost::io::detail::locale_t * loc_default) const {
         // set the state of this stream according to our params
         if(width_ != -1)
             os.width(width_);
@@ -117,6 +114,14 @@ namespace detail {
         os.flags(flags_);
         os.clear(rdstate_);
         os.exceptions(exceptions_);
+#if !defined(BOOST_NO_STD_LOCALE)
+        if(loc_)
+            os.imbue(loc_.get());
+        else if(loc_default)
+            os.imbue(*loc_default);
+#else
+        (void) loc_default; // keep compiler quiet if we don't support locales
+#endif        
     }
 
     template<class Ch, class Tr>
@@ -135,7 +140,7 @@ namespace detail {
     void apply_manip_body( stream_format_state<Ch, Tr>& self,
                            T manipulator) {
         // modify our params according to the manipulator
-        basic_outsstream<Ch, Tr>  ss;
+        basic_oaltstringstream<Ch, Tr>  ss;
         self.apply_on( ss );
         ss << manipulator;
         self.set_by_stream( ss );
@@ -143,7 +148,7 @@ namespace detail {
 
     template<class Ch, class Tr> inline
     void stream_format_state<Ch,Tr>:: reset(Ch fill) {
-        // set our params to standard's default state.   cf § 27.4.4.1 of the C++ norm
+        // set our params to standard's default state.   cf 27.4.4.1 of the C++ norm
         width_=0; precision_=6; 
         fill_=fill; // default is widen(' '), but we cant compute it without the locale
         flags_ = std::ios_base::dec | std::ios_base::skipws; 
@@ -155,16 +160,17 @@ namespace detail {
 
 // ---   format_item:: --------------------------------------------------------
 
-    template<class Ch, class Tr> 
-    void format_item<Ch, Tr>:: 
-    reset(Ch fill) { 
+    template<class Ch, class Tr, class Alloc
+    void format_item<Ch, Tr, Alloc>:: 
+    reset (Ch fill) { 
         argN_=argN_no_posit; truncate_ = max_streamsize(); pad_scheme_ =0; 
         res_.resize(0); appendix_.resize(0);
         fmtstate_.reset(fill);
     }
 
-    template<class Ch, class Tr> 
-    void format_item<Ch, Tr>:: compute_states() {
+    template<class Ch, class Tr, class Alloc> 
+    void format_item<Ch, Tr, Alloc>:: 
+    compute_states() {
         // reflect pad_scheme_   on  fmt_state_
         //   because some pad_schemes has complex consequences on several state params.
         if(pad_scheme_ & zeropad) {