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