]> git.lyx.org Git - lyx.git/blob - boost/boost/format/free_funcs.hpp
64-bit fix to boost::format.
[lyx.git] / boost / boost / format / free_funcs.hpp
1 // -*- C++ -*-
2 //  Boost general library 'format'   ---------------------------
3 //  See http://www.boost.org for updates, documentation, and revision history.
4
5 //  (C) Samuel Krempp 2001
6 //  Permission to copy, use, modify, sell and
7 //  distribute this software is granted provided this copyright notice appears
8 //  in all copies. This software is provided "as is" without express or implied
9 //  warranty, and with no claim as to its suitability for any purpose.
10
11 // ideas taken from RĂ¼diger Loos's format class
12 // and Karl Nelson's ofstream (also took its parsing code as basis for printf parsing)
13
14 // ------------------------------------------------------------------------------
15 // free_funcs.hpp :  implementation of the free functions declared in namespace format
16 // ------------------------------------------------------------------------------
17
18 #ifndef BOOST_FORMAT_FUNCS_HPP
19 #define BOOST_FORMAT_FUNCS_HPP
20
21 #include <boost/format/format_class.hpp>
22 #include <boost/throw_exception.hpp>
23
24 namespace boost {
25
26     template<class Ch, class Tr> inline 
27     std::basic_string<Ch, Tr> str(const basic_format<Ch, Tr>& f) {
28         // adds up all pieces of strings and converted items, and return the formatted string
29         return f.str();
30     }
31
32
33     template< class Ch, class Tr>
34     BOOST_IO_STD basic_ostream<Ch, Tr>& 
35     operator<<( BOOST_IO_STD basic_ostream<Ch, Tr>& os, 
36                 const boost::basic_format<Ch, Tr>& f) 
37         // effect: "return os << str(f);" but we can try to do it faster
38     {
39         typedef boost::basic_format<Ch, Tr>   format_t;
40         if(f.items_.size()==0) 
41             os << f.prefix_;
42         else {
43             if(f.cur_arg_ < f.num_args_)
44                 if( f.exceptions() & io::too_few_args_bit )
45                     boost::throw_exception(io::too_few_args()); // not enough variables supplied
46             if(f.style_ & format_t::special_needs) 
47                 os << f.str();
48             else {
49                 // else we dont have to count chars output, so we dump directly to os :
50                 os << f.prefix_;
51                 for(unsigned long i=0; i<f.items_.size(); ++i) {
52                     const typename format_t::format_item_t& item = f.items_[i];
53                     os << item.res_;
54                     os << item.appendix_;
55                 }
56             }
57         }
58         f.dumped_=true;
59         return os;
60     }
61
62 } // namespace boost
63
64
65 #endif // BOOST_FORMAT_FUNCS_HPP