1 // (C) Copyright Gennadiy Rozental 2001.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
8 // Description : contains definition for all test tools in test toolbox
9 // ***************************************************************************
11 #ifndef BOOST_TEST_UTILS_LAZY_OSTREAM_HPP
12 #define BOOST_TEST_UTILS_LAZY_OSTREAM_HPP
15 #include <boost/test/detail/config.hpp>
20 #include <boost/test/detail/suppress_warnings.hpp>
22 //____________________________________________________________________________//
24 // ************************************************************************** //
25 // ************** lazy_ostream ************** //
26 // ************************************************************************** //
33 virtual ~lazy_ostream() {}
35 static lazy_ostream& instance() { static lazy_ostream inst; return inst; }
37 friend std::ostream& operator<<( std::ostream& ostr, lazy_ostream const& o ) { return o( ostr ); }
40 bool empty() const { return m_empty; }
42 // actual printing interface; to be accessed only by this class and children
43 virtual std::ostream& operator()( std::ostream& ostr ) const { return ostr; }
45 explicit lazy_ostream( bool p_empty = true ) : m_empty( p_empty ) {}
52 //____________________________________________________________________________//
54 template<typename PrevType, typename T, typename StorageT=T const&>
55 class lazy_ostream_impl : public lazy_ostream {
57 lazy_ostream_impl( PrevType const& prev, T const& value )
58 : lazy_ostream( false )
64 virtual std::ostream& operator()( std::ostream& ostr ) const
66 return m_prev(ostr) << m_value;
70 PrevType const& m_prev;
74 //____________________________________________________________________________//
77 inline lazy_ostream_impl<lazy_ostream,T>
78 operator<<( lazy_ostream const& prev, T const& v )
80 return lazy_ostream_impl<lazy_ostream,T>( prev, v );
83 //____________________________________________________________________________//
85 template<typename PrevPrevType, typename TPrev, typename T>
86 inline lazy_ostream_impl<lazy_ostream_impl<PrevPrevType,TPrev>,T>
87 operator<<( lazy_ostream_impl<PrevPrevType,TPrev> const& prev, T const& v )
89 typedef lazy_ostream_impl<PrevPrevType,TPrev> PrevType;
90 return lazy_ostream_impl<PrevType,T>( prev, v );
93 //____________________________________________________________________________//
95 #if BOOST_TEST_USE_STD_LOCALE
97 template<typename R,typename S>
98 inline lazy_ostream_impl<lazy_ostream,R& (BOOST_TEST_CALL_DECL *)(S&),R& (BOOST_TEST_CALL_DECL *)(S&)>
99 operator<<( lazy_ostream const& prev, R& (BOOST_TEST_CALL_DECL *man)(S&) )
101 typedef R& (BOOST_TEST_CALL_DECL * ManipType)(S&);
103 return lazy_ostream_impl<lazy_ostream,ManipType,ManipType>( prev, man );
106 //____________________________________________________________________________//
108 template<typename PrevPrevType, typename TPrev,typename R,typename S>
109 inline lazy_ostream_impl<lazy_ostream_impl<PrevPrevType,TPrev>,R& (BOOST_TEST_CALL_DECL *)(S&),R& (BOOST_TEST_CALL_DECL *)(S&)>
110 operator<<( lazy_ostream_impl<PrevPrevType,TPrev> const& prev, R& (BOOST_TEST_CALL_DECL *man)(S&) )
112 typedef R& (BOOST_TEST_CALL_DECL * ManipType)(S&);
114 return lazy_ostream_impl<lazy_ostream_impl<PrevPrevType,TPrev>,ManipType,ManipType>( prev, man );
117 //____________________________________________________________________________//
121 #define BOOST_TEST_LAZY_MSG( M ) (::boost::unit_test::lazy_ostream::instance() << M)
123 } // namespace unit_test
126 #include <boost/test/detail/enable_warnings.hpp>
128 #endif // BOOST_TEST_UTILS_LAZY_OSTREAM_HPP