File indexing completed on 2025-01-18 09:52:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_TEST_UTILS_LAZY_OSTREAM_HPP
0012 #define BOOST_TEST_UTILS_LAZY_OSTREAM_HPP
0013
0014
0015 #include <boost/test/detail/config.hpp>
0016 #include <boost/test/tools/detail/print_helper.hpp>
0017
0018
0019 #include <iosfwd>
0020
0021 #include <boost/test/detail/suppress_warnings.hpp>
0022
0023
0024
0025
0026
0027
0028
0029 namespace boost {
0030 namespace unit_test {
0031
0032 class BOOST_TEST_DECL lazy_ostream {
0033 public:
0034 virtual ~lazy_ostream() {}
0035
0036 static lazy_ostream& instance() { return inst; }
0037
0038 #if !defined(BOOST_EMBTC)
0039
0040 friend std::ostream& operator<<( std::ostream& ostr, lazy_ostream const& o ) { return o( ostr ); }
0041
0042 #else
0043
0044 friend std::ostream& operator<<( std::ostream& ostr, lazy_ostream const& o );
0045
0046 #endif
0047
0048
0049 bool empty() const { return m_empty; }
0050
0051
0052 virtual std::ostream& operator()( std::ostream& ostr ) const { return ostr; }
0053 protected:
0054 explicit lazy_ostream( bool p_empty = true ) : m_empty( p_empty ) {}
0055
0056 private:
0057
0058 bool m_empty;
0059 static lazy_ostream inst;
0060 };
0061
0062 #if defined(BOOST_EMBTC)
0063
0064 inline std::ostream& operator<<( std::ostream& ostr, lazy_ostream const& o ) { return o( ostr ); }
0065
0066 #endif
0067
0068
0069
0070 template<typename PrevType, typename T, typename StorageT=T const&>
0071 class lazy_ostream_impl : public lazy_ostream {
0072 public:
0073 lazy_ostream_impl( PrevType const& prev, T const& value )
0074 : lazy_ostream( false )
0075 , m_prev( prev )
0076 , m_value( value )
0077 {
0078 }
0079
0080 std::ostream& operator()( std::ostream& ostr ) const BOOST_OVERRIDE
0081 {
0082 return m_prev(ostr) << test_tools::tt_detail::print_helper(m_value);
0083 }
0084 private:
0085
0086 PrevType const& m_prev;
0087 StorageT m_value;
0088 };
0089
0090
0091
0092 template<typename T>
0093 inline lazy_ostream_impl<lazy_ostream,T>
0094 operator<<( lazy_ostream const& prev, T const& v )
0095 {
0096 return lazy_ostream_impl<lazy_ostream,T>( prev, v );
0097 }
0098
0099
0100
0101 template<typename PrevPrevType, typename TPrev, typename T>
0102 inline lazy_ostream_impl<lazy_ostream_impl<PrevPrevType,TPrev>,T>
0103 operator<<( lazy_ostream_impl<PrevPrevType,TPrev> const& prev, T const& v )
0104 {
0105 typedef lazy_ostream_impl<PrevPrevType,TPrev> PrevType;
0106 return lazy_ostream_impl<PrevType,T>( prev, v );
0107 }
0108
0109
0110
0111 #if BOOST_TEST_USE_STD_LOCALE
0112
0113 template<typename R,typename S>
0114 inline lazy_ostream_impl<lazy_ostream,R& (BOOST_TEST_CALL_DECL *)(S&),R& (BOOST_TEST_CALL_DECL *)(S&)>
0115 operator<<( lazy_ostream const& prev, R& (BOOST_TEST_CALL_DECL *man)(S&) )
0116 {
0117 typedef R& (BOOST_TEST_CALL_DECL * ManipType)(S&);
0118
0119 return lazy_ostream_impl<lazy_ostream,ManipType,ManipType>( prev, man );
0120 }
0121
0122
0123
0124 template<typename PrevPrevType, typename TPrev,typename R,typename S>
0125 inline lazy_ostream_impl<lazy_ostream_impl<PrevPrevType,TPrev>,R& (BOOST_TEST_CALL_DECL *)(S&),R& (BOOST_TEST_CALL_DECL *)(S&)>
0126 operator<<( lazy_ostream_impl<PrevPrevType,TPrev> const& prev, R& (BOOST_TEST_CALL_DECL *man)(S&) )
0127 {
0128 typedef R& (BOOST_TEST_CALL_DECL * ManipType)(S&);
0129
0130 return lazy_ostream_impl<lazy_ostream_impl<PrevPrevType,TPrev>,ManipType,ManipType>( prev, man );
0131 }
0132
0133
0134
0135 #endif
0136
0137 #define BOOST_TEST_LAZY_MSG( M ) (::boost::unit_test::lazy_ostream::instance() << M)
0138
0139 }
0140 }
0141
0142 #include <boost/test/detail/enable_warnings.hpp>
0143
0144 #endif