File indexing completed on 2025-01-30 09:35:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef BOOST_FORMAT_CLASS_HPP
0014 #define BOOST_FORMAT_CLASS_HPP
0015
0016
0017 #include <vector>
0018 #include <string>
0019
0020 #include <boost/optional.hpp> // to store locale when needed
0021
0022 #include <boost/format/format_fwd.hpp>
0023 #include <boost/format/internals_fwd.hpp>
0024 #include <boost/format/internals.hpp>
0025 #include <boost/format/alt_sstream.hpp>
0026
0027 namespace boost {
0028
0029 template<class Ch, class Tr, class Alloc>
0030 class basic_format
0031 {
0032 typedef typename io::CompatTraits<Tr>::compatible_type compat_traits;
0033 public:
0034 typedef Ch CharT;
0035 typedef std::basic_string<Ch, Tr, Alloc> string_type;
0036 typedef typename string_type::size_type size_type;
0037 typedef io::detail::format_item<Ch, Tr, Alloc> format_item_t;
0038 typedef io::basic_altstringbuf<Ch, Tr, Alloc> internal_streambuf_t;
0039
0040
0041 explicit basic_format(const Ch* str=NULL);
0042 explicit basic_format(const string_type& s);
0043 basic_format(const basic_format& x);
0044 basic_format& operator= (const basic_format& x);
0045 void swap(basic_format& x);
0046
0047 #if !defined(BOOST_NO_STD_LOCALE)
0048 explicit basic_format(const Ch* str, const std::locale & loc);
0049 explicit basic_format(const string_type& s, const std::locale & loc);
0050 #endif
0051 io::detail::locale_t getloc() const;
0052
0053 basic_format& clear();
0054 basic_format& clear_binds();
0055 basic_format& parse(const string_type&);
0056
0057
0058 size_type size() const;
0059 string_type str() const;
0060
0061
0062 template<class T>
0063 basic_format& operator%(const T& x)
0064 { return io::detail::feed<CharT, Tr, Alloc, const T&>(*this,x); }
0065
0066 #ifndef BOOST_NO_OVERLOAD_FOR_NON_CONST
0067 template<class T> basic_format& operator%(T& x)
0068 { return io::detail::feed<CharT, Tr, Alloc, T&>(*this,x); }
0069 #endif
0070
0071 template<class T>
0072 basic_format& operator%(volatile const T& x)
0073 { const T v(x);
0074 return io::detail::feed<CharT, Tr, Alloc, const T&>(*this, v); }
0075
0076 #ifndef BOOST_NO_OVERLOAD_FOR_NON_CONST
0077 template<class T>
0078 basic_format& operator%(volatile T& x)
0079 { T v(x);
0080 return io::detail::feed<CharT, Tr, Alloc, T&>(*this, v); }
0081 #endif
0082
0083 #if defined(__GNUC__)
0084
0085
0086 basic_format& operator%(const int& x)
0087 { return io::detail::feed<CharT, Tr, Alloc, const int&>(*this,x); }
0088
0089 #ifndef BOOST_NO_OVERLOAD_FOR_NON_CONST
0090 basic_format& operator%(int& x)
0091 { return io::detail::feed<CharT, Tr, Alloc, int&>(*this,x); }
0092 #endif
0093 #endif
0094
0095
0096 int expected_args() const
0097 { return num_args_; }
0098
0099 int bound_args() const;
0100
0101 int fed_args() const;
0102
0103 int cur_arg() const;
0104
0105 int remaining_args() const;
0106
0107
0108
0109 template<class T>
0110 basic_format& bind_arg(int argN, const T& val)
0111 { return io::detail::bind_arg_body(*this, argN, val); }
0112 basic_format& clear_bind(int argN);
0113 template<class T>
0114 basic_format& modify_item(int itemN, T manipulator)
0115 { return io::detail::modify_item_body<Ch,Tr, Alloc, T> (*this, itemN, manipulator);}
0116
0117
0118 unsigned char exceptions() const;
0119 unsigned char exceptions(unsigned char newexcept);
0120
0121 #if !defined( BOOST_NO_MEMBER_TEMPLATE_FRIENDS ) \
0122 && !BOOST_WORKAROUND(BOOST_BORLANDC, <= 0x570) \
0123 && !BOOST_WORKAROUND( _CRAYC, != 0) \
0124 && !BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042))
0125
0126
0127 #ifndef BOOST_NO_TEMPLATE_STD_STREAM
0128 template<class Ch2, class Tr2, class Alloc2>
0129 friend std::basic_ostream<Ch2, Tr2> &
0130 operator<<( std::basic_ostream<Ch2, Tr2> & ,
0131 const basic_format<Ch2, Tr2, Alloc2>& );
0132 #else
0133 template<class Ch2, class Tr2, class Alloc2>
0134 friend std::ostream &
0135 operator<<( std::ostream & ,
0136 const basic_format<Ch2, Tr2, Alloc2>& );
0137 #endif
0138
0139 template<class Ch2, class Tr2, class Alloc2, class T>
0140 friend basic_format<Ch2, Tr2, Alloc2>&
0141 io::detail::feed_impl (basic_format<Ch2, Tr2, Alloc2>&, T);
0142
0143 template<class Ch2, class Tr2, class Alloc2, class T> friend
0144 void io::detail::distribute (basic_format<Ch2, Tr2, Alloc2>&, T);
0145
0146 template<class Ch2, class Tr2, class Alloc2, class T> friend
0147 basic_format<Ch2, Tr2, Alloc2>&
0148 io::detail::modify_item_body (basic_format<Ch2, Tr2, Alloc2>&, int, T);
0149
0150 template<class Ch2, class Tr2, class Alloc2, class T> friend
0151 basic_format<Ch2, Tr2, Alloc2>&
0152 io::detail::bind_arg_body (basic_format<Ch2, Tr2, Alloc2>&, int, const T&);
0153
0154 private:
0155 #endif
0156 typedef io::detail::stream_format_state<Ch, Tr> stream_format_state;
0157
0158 enum style_values { ordered = 1,
0159 special_needs = 4 };
0160
0161 void make_or_reuse_data(std::size_t nbitems);
0162
0163
0164 std::vector<format_item_t> items_;
0165 std::vector<bool> bound_;
0166
0167 int style_;
0168 int cur_arg_;
0169 int num_args_;
0170 mutable bool dumped_;
0171 string_type prefix_;
0172 unsigned char exceptions_;
0173 internal_streambuf_t buf_;
0174 boost::optional<io::detail::locale_t> loc_;
0175 };
0176
0177 }
0178
0179
0180 #endif