123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- #ifndef BOOST_FORMAT_CLASS_HPP
- #define BOOST_FORMAT_CLASS_HPP
- #include <vector>
- #include <string>
- #include <boost/optional.hpp> // to store locale when needed
- #include <boost/format/format_fwd.hpp>
- #include <boost/format/internals_fwd.hpp>
- #include <boost/format/internals.hpp>
- #include <boost/format/alt_sstream.hpp>
- namespace boost {
- template<class Ch, class Tr, class Alloc>
- class basic_format
- {
- typedef typename io::CompatTraits<Tr>::compatible_type compat_traits;
- public:
- typedef Ch CharT;
- typedef std::basic_string<Ch, Tr, Alloc> string_type;
- typedef typename string_type::size_type size_type;
- typedef io::detail::format_item<Ch, Tr, Alloc> format_item_t;
- typedef io::basic_altstringbuf<Ch, Tr, Alloc> internal_streambuf_t;
-
- explicit basic_format(const Ch* str=NULL);
- explicit basic_format(const string_type& s);
- basic_format(const basic_format& x);
- basic_format& operator= (const basic_format& x);
- void swap(basic_format& x);
- #if !defined(BOOST_NO_STD_LOCALE)
- explicit basic_format(const Ch* str, const std::locale & loc);
- explicit basic_format(const string_type& s, const std::locale & loc);
- #endif
- io::detail::locale_t getloc() const;
- basic_format& clear();
- basic_format& clear_binds();
- basic_format& parse(const string_type&);
-
- size_type size() const;
- string_type str() const;
-
- template<class T>
- basic_format& operator%(const T& x)
- { return io::detail::feed<CharT, Tr, Alloc, const T&>(*this,x); }
- #ifndef BOOST_NO_OVERLOAD_FOR_NON_CONST
- template<class T> basic_format& operator%(T& x)
- { return io::detail::feed<CharT, Tr, Alloc, T&>(*this,x); }
- #endif
- template<class T>
- basic_format& operator%(volatile const T& x)
- { const T v(x);
- return io::detail::feed<CharT, Tr, Alloc, const T&>(*this, v); }
- #ifndef BOOST_NO_OVERLOAD_FOR_NON_CONST
- template<class T>
- basic_format& operator%(volatile T& x)
- { T v(x);
- return io::detail::feed<CharT, Tr, Alloc, T&>(*this, v); }
- #endif
- #if defined(__GNUC__)
-
-
- basic_format& operator%(const int& x)
- { return io::detail::feed<CharT, Tr, Alloc, const int&>(*this,x); }
- #ifndef BOOST_NO_OVERLOAD_FOR_NON_CONST
- basic_format& operator%(int& x)
- { return io::detail::feed<CharT, Tr, Alloc, int&>(*this,x); }
- #endif
- #endif
-
- int expected_args() const
- { return num_args_; }
-
- int bound_args() const;
-
- int fed_args() const;
-
- int cur_arg() const;
-
- int remaining_args() const;
-
- template<class T>
- basic_format& bind_arg(int argN, const T& val)
- { return io::detail::bind_arg_body(*this, argN, val); }
- basic_format& clear_bind(int argN);
- template<class T>
- basic_format& modify_item(int itemN, T manipulator)
- { return io::detail::modify_item_body<Ch,Tr, Alloc, T> (*this, itemN, manipulator);}
-
- unsigned char exceptions() const;
- unsigned char exceptions(unsigned char newexcept);
- #if !defined( BOOST_NO_MEMBER_TEMPLATE_FRIENDS ) \
- && !BOOST_WORKAROUND(BOOST_BORLANDC, <= 0x570) \
- && !BOOST_WORKAROUND( _CRAYC, != 0) \
- && !BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042))
-
- #ifndef BOOST_NO_TEMPLATE_STD_STREAM
- template<class Ch2, class Tr2, class Alloc2>
- friend std::basic_ostream<Ch2, Tr2> &
- operator<<( std::basic_ostream<Ch2, Tr2> & ,
- const basic_format<Ch2, Tr2, Alloc2>& );
- #else
- template<class Ch2, class Tr2, class Alloc2>
- friend std::ostream &
- operator<<( std::ostream & ,
- const basic_format<Ch2, Tr2, Alloc2>& );
- #endif
- template<class Ch2, class Tr2, class Alloc2, class T>
- friend basic_format<Ch2, Tr2, Alloc2>&
- io::detail::feed_impl (basic_format<Ch2, Tr2, Alloc2>&, T);
- template<class Ch2, class Tr2, class Alloc2, class T> friend
- void io::detail::distribute (basic_format<Ch2, Tr2, Alloc2>&, T);
-
- template<class Ch2, class Tr2, class Alloc2, class T> friend
- basic_format<Ch2, Tr2, Alloc2>&
- io::detail::modify_item_body (basic_format<Ch2, Tr2, Alloc2>&, int, T);
-
- template<class Ch2, class Tr2, class Alloc2, class T> friend
- basic_format<Ch2, Tr2, Alloc2>&
- io::detail::bind_arg_body (basic_format<Ch2, Tr2, Alloc2>&, int, const T&);
- private:
- #endif
- typedef io::detail::stream_format_state<Ch, Tr> stream_format_state;
-
- enum style_values { ordered = 1,
- special_needs = 4 };
- void make_or_reuse_data(std::size_t nbitems);
-
- std::vector<format_item_t> items_;
- std::vector<bool> bound_;
- int style_;
- int cur_arg_;
- int num_args_;
- mutable bool dumped_;
- string_type prefix_;
- unsigned char exceptions_;
- internal_streambuf_t buf_;
- boost::optional<io::detail::locale_t> loc_;
- };
- }
- #endif
|