2 // Boost general library 'format' ---------------------------
3 // See http://www.boost.org for updates, documentation, and revision history.
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.
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)
15 // ------------------------------------------------------------------------------
16 // free_funcs.hpp : implementation of the free functions declared in namespace format
17 // ------------------------------------------------------------------------------
19 #ifndef BOOST_FORMAT_FUNCS_HPP
20 #define BOOST_FORMAT_FUNCS_HPP
22 #include "boost/format/format_class.hpp"
23 #include "boost/throw_exception.hpp"
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
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
42 typedef boost::basic_format<Ch, Tr> format_t;
43 if(f.items_.size()==0)
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)
52 // else we dont have to count chars output, so we dump directly to os :
54 for(unsigned long i=0; i<f.items_.size(); ++i)
56 const typename format_t::format_item_t& item = f.items_[i];
72 #endif // BOOST_FORMAT_FUNCS_HPP