Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:54

0001 // ----------------------------------------------------------------------------
0002 // free_funcs.hpp :  implementation of the free functions of boost::format
0003 // ----------------------------------------------------------------------------
0004 
0005 //  Copyright Samuel Krempp 2003. Use, modification, and distribution are
0006 //  subject to the Boost Software License, Version 1.0. (See accompanying
0007 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 //  See http://www.boost.org/libs/format for library home page
0010 
0011 // ----------------------------------------------------------------------------
0012 
0013 #ifndef BOOST_FORMAT_FUNCS_HPP
0014 #define BOOST_FORMAT_FUNCS_HPP
0015 
0016 #include <boost/format/format_class.hpp>
0017 #include <boost/throw_exception.hpp>
0018 
0019 namespace boost {
0020 
0021     template<class Ch, class Tr, class Alloc> inline 
0022     std::basic_string<Ch, Tr, Alloc> str(const basic_format<Ch, Tr, Alloc>& f) {
0023         // adds up all pieces of strings and converted items, and return the formatted string
0024         return f.str();
0025     }
0026     namespace io {
0027          using ::boost::str; // keep compatibility with when it was defined in this N.S.
0028     }   // - namespace io
0029 
0030 #ifndef  BOOST_NO_TEMPLATE_STD_STREAM
0031         template<class Ch, class Tr, class Alloc>
0032         std::basic_ostream<Ch, Tr> & 
0033         operator<<( std::basic_ostream<Ch, Tr> & os,
0034                     const basic_format<Ch, Tr, Alloc>& f)
0035 #else
0036         template<class Ch, class Tr, class Alloc>
0037         std::ostream & 
0038         operator<<( std::ostream & os,
0039                     const basic_format<Ch, Tr, Alloc>& f)
0040 #endif
0041         // effect: "return os << str(f);" but we can do it faster
0042     {
0043         typedef boost::basic_format<Ch, Tr, Alloc>   format_t;
0044         if(f.items_.size()==0) 
0045             os << f.prefix_;
0046         else {
0047             if(f.cur_arg_ < f.num_args_)
0048                 if( f.exceptions() & io::too_few_args_bit )
0049                     // not enough variables supplied
0050                     boost::throw_exception(io::too_few_args(f.cur_arg_, f.num_args_)); 
0051             if(f.style_ & format_t::special_needs) 
0052                 os << f.str();
0053             else {
0054                 // else we dont have to count chars output, so we dump directly to os :
0055                 os << f.prefix_;
0056                 for(unsigned long i=0; i<f.items_.size(); ++i) {
0057                     const typename format_t::format_item_t& item = f.items_[i];
0058                     os << item.res_;
0059                     os << item.appendix_;
0060                 }
0061             }
0062         }
0063         f.dumped_=true;
0064         return os;
0065     }
0066 
0067 } // namespace boost
0068 
0069 
0070 #endif // BOOST_FORMAT_FUNCS_HPP