123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- #ifndef BOOST_LOG_UTILITY_MANIPULATORS_RANGE_HPP_INCLUDED_
- #define BOOST_LOG_UTILITY_MANIPULATORS_RANGE_HPP_INCLUDED_
- #include <cstddef>
- #include <boost/range/begin.hpp>
- #include <boost/range/end.hpp>
- #include <boost/range/const_iterator.hpp>
- #include <boost/core/enable_if.hpp>
- #include <boost/type_traits/is_scalar.hpp>
- #include <boost/type_traits/conditional.hpp>
- #include <boost/log/detail/config.hpp>
- #include <boost/log/detail/is_ostream.hpp>
- #include <boost/log/detail/header.hpp>
- #ifdef BOOST_HAS_PRAGMA_ONCE
- #pragma once
- #endif
- namespace boost {
- BOOST_LOG_OPEN_NAMESPACE
- template< typename RangeT, typename DelimiterT >
- class range_manipulator
- {
- private:
- typedef typename conditional<
- is_scalar< DelimiterT >::value,
- DelimiterT,
- DelimiterT const&
- >::type stored_delimiter_type;
- private:
- RangeT const& m_range;
- stored_delimiter_type m_delimiter;
- public:
-
- range_manipulator(RangeT const& range, stored_delimiter_type delimiter) BOOST_NOEXCEPT :
- m_range(range),
- m_delimiter(delimiter)
- {
- }
-
- template< typename StreamT >
- void output(StreamT& stream) const
- {
- typedef typename boost::range_const_iterator< RangeT >::type const_iterator;
- const_iterator it = boost::begin(m_range);
- const const_iterator end = boost::end(m_range);
- if (BOOST_LIKELY(it != end))
- {
- stream << *it;
- for (++it; it != end; ++it)
- {
- stream << m_delimiter;
- stream << *it;
- }
- }
- }
- };
- template< typename RangeT >
- class range_manipulator< RangeT, void >
- {
- private:
- RangeT const& m_range;
- public:
-
- explicit range_manipulator(RangeT const& range) BOOST_NOEXCEPT :
- m_range(range)
- {
- }
-
- template< typename StreamT >
- void output(StreamT& stream) const
- {
- typedef typename boost::range_const_iterator< RangeT >::type const_iterator;
- const_iterator it = boost::begin(m_range);
- const const_iterator end = boost::end(m_range);
- for (; it != end; ++it)
- {
- stream << *it;
- }
- }
- };
- template< typename StreamT, typename RangeT, typename DelimiterT >
- inline typename boost::enable_if_c< log::aux::is_ostream< StreamT >::value, StreamT& >::type operator<< (StreamT& strm, range_manipulator< RangeT, DelimiterT > const& manip)
- {
- if (BOOST_LIKELY(strm.good()))
- manip.output(strm);
- return strm;
- }
- template< typename RangeT, typename DelimiterT >
- inline typename boost::enable_if_c<
- is_scalar< DelimiterT >::value,
- range_manipulator< RangeT, DelimiterT >
- >::type range_manip(RangeT const& range, DelimiterT delimiter) BOOST_NOEXCEPT
- {
- return range_manipulator< RangeT, DelimiterT >(range, delimiter);
- }
- template< typename RangeT, typename DelimiterT >
- inline typename boost::disable_if_c<
- is_scalar< DelimiterT >::value,
- range_manipulator< RangeT, DelimiterT >
- >::type range_manip(RangeT const& range, DelimiterT const& delimiter) BOOST_NOEXCEPT
- {
- return range_manipulator< RangeT, DelimiterT >(range, delimiter);
- }
- template< typename RangeT, typename DelimiterElementT, std::size_t N >
- inline range_manipulator< RangeT, DelimiterElementT* > range_manip(RangeT const& range, DelimiterElementT (&delimiter)[N]) BOOST_NOEXCEPT
- {
- return range_manipulator< RangeT, DelimiterElementT* >(range, delimiter);
- }
- template< typename RangeT >
- inline range_manipulator< RangeT, void > range_manip(RangeT const& range) BOOST_NOEXCEPT
- {
- return range_manipulator< RangeT, void >(range);
- }
- BOOST_LOG_CLOSE_NAMESPACE
- }
- #include <boost/log/detail/footer.hpp>
- #endif
|