1 // ----------------------------------------------------------------------------
2 // free_funcs.hpp : implementation of the free functions of boost::format
3 // ----------------------------------------------------------------------------
5 // Copyright Samuel Krempp 2003. Use, modification, and distribution are
6 // subject to the Boost Software License, Version 1.0. (See accompanying
7 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 // See http://www.boost.org/libs/format for library home page
11 // ----------------------------------------------------------------------------
13 #ifndef BOOST_FORMAT_FUNCS_HPP
14 #define BOOST_FORMAT_FUNCS_HPP
16 #include <boost/format/format_class.hpp>
17 #include <boost/throw_exception.hpp>
21 template<class Ch, class Tr, class Alloc> inline
22 std::basic_string<Ch, Tr, Alloc> str(const basic_format<Ch, Tr, Alloc>& f) {
23 // adds up all pieces of strings and converted items, and return the formatted string
27 using ::boost::str; // keep compatibility with when it was defined in this N.S.
30 #ifndef BOOST_NO_TEMPLATE_STD_STREAM
31 template<class Ch, class Tr, class Alloc>
32 std::basic_ostream<Ch, Tr> &
33 operator<<( std::basic_ostream<Ch, Tr> & os,
34 const basic_format<Ch, Tr, Alloc>& f)
36 template<class Ch, class Tr, class Alloc>
38 operator<<( std::ostream & os,
39 const basic_format<Ch, Tr, Alloc>& f)
41 // effect: "return os << str(f);" but we can do it faster
43 typedef boost::basic_format<Ch, Tr, Alloc> format_t;
44 if(f.items_.size()==0)
47 if(f.cur_arg_ < f.num_args_)
48 if( f.exceptions() & io::too_few_args_bit )
49 // not enough variables supplied
50 boost::throw_exception(io::too_few_args(f.cur_arg_, f.num_args_));
51 if(f.style_ & format_t::special_needs)
54 // else we dont have to count chars output, so we dump directly to os :
56 for(unsigned long i=0; i<f.items_.size(); ++i) {
57 const typename format_t::format_item_t& item = f.items_[i];
70 #endif // BOOST_FORMAT_FUNCS_HPP