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