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 // format_class.hpp : class interface
17 // ------------------------------------------------------------------------------
20 #ifndef BOOST_FORMAT_CLASS_HPP
21 #define BOOST_FORMAT_CLASS_HPP
28 #include "boost/format/format_fwd.hpp"
29 #include "boost/format/internals_fwd.hpp"
31 #include "boost/format/internals.hpp"
35 template<class Ch, class Tr>
38 typedef BOOST_IO_STD basic_ostream<Ch, Tr> stream_t;
39 typedef io::detail::stream_format_state<Ch, Tr> stream_format_state;
40 typedef io::detail::format_item<Ch, Tr> format_item_t;
42 typedef std::basic_string<Ch, Tr> string_t;
43 typedef BOOST_IO_STD basic_ostringstream<Ch, Tr> internal_stream_t;
46 basic_format(const Ch* str);
47 basic_format(const Ch* str, const std::locale & loc);
48 basic_format(const string_t& s);
49 basic_format(const string_t& s, const std::locale & loc);
50 basic_format(const basic_format& x);
51 basic_format& operator= (const basic_format& x);
53 basic_format& clear(); // empty the string buffers (except bound arguments, see clear_binds() )
55 // pass arguments through those operators :
56 template<class T> basic_format& operator%(const T& x)
58 return io::detail::feed<Ch, Tr, const T&>(*this,x);
61 #ifdef BOOST_OVERLOAD_FOR_NON_CONST
62 template<class T> basic_format& operator%(T& x)
64 return io::detail::feed<Ch, Tr, T&>(*this,x);
69 // system for binding arguments :
71 basic_format& bind_arg(int argN, const T& val)
73 return io::detail::bind_arg_body(*this, argN, val);
75 basic_format& clear_bind(int argN);
76 basic_format& clear_binds();
78 // modify the params of a directive, by applying a manipulator :
80 basic_format& modify_item(int itemN, const T& manipulator)
82 return io::detail::modify_item_body(*this, itemN, manipulator) ;
85 // Choosing which errors will throw exceptions :
86 unsigned char exceptions() const;
87 unsigned char exceptions(unsigned char newexcept);
91 friend BOOST_IO_STD basic_ostream<Ch, Tr>&
92 #if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
93 operator<< <Ch, Tr> ( BOOST_IO_STD basic_ostream<Ch, Tr>& , const basic_format& );
95 operator<< ( BOOST_IO_STD basic_ostream<Ch, Tr>& , const basic_format& );
99 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
100 template<class Ch2, class Tr2, class T> friend basic_format<Ch2, Tr2>&
101 io::detail::feed(basic_format<Ch2,Tr2>&, T);
103 template<class Ch2, class Tr2, class T> friend
104 void io::detail::distribute(basic_format<Ch2,Tr2>&, T);
106 template<class Ch2, class Tr2, class T> friend
107 basic_format<Ch2, Tr2>& io::detail::modify_item_body(basic_format<Ch2, Tr2>&, int, const T&);
109 template<class Ch2, class Tr2, class T> friend
110 basic_format<Ch2, Tr2>& io::detail::bind_arg_body(basic_format<Ch2, Tr2>&, int, const T&);
112 // make the members private only if the friend templates are supported
116 // flag bits, used for style_
117 enum style_values { ordered = 1, // set only if all directives are positional directives
120 // parse the format string :
121 void parse(const string_t&);
123 int style_; // style of format-string : positional or not, etc
124 int cur_arg_; // keep track of wich argument will come
125 int num_args_; // number of expected arguments
126 mutable bool dumped_; // true only after call to str() or <<
127 std::vector<format_item_t> items_; // vector of directives (aka items)
128 string_t prefix_; // piece of string to insert before first item
130 std::vector<bool> bound_; // stores which arguments were bound
131 // size = num_args OR zero
132 internal_stream_t oss_; // the internal stream.
133 stream_format_state state0_; // reference state for oss_
134 unsigned char exceptions_;
135 }; // class basic_format
141 #endif // BOOST_FORMAT_CLASS_HPP