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