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)
5
6// See http://www.boost.org/libs/test for the library home page.
7//
8// Description : contains definition for all test tools in test toolbox
9// ***************************************************************************
10
11#ifndef BOOST_TEST_UTILS_LAZY_OSTREAM_HPP
12#define BOOST_TEST_UTILS_LAZY_OSTREAM_HPP
13
14// Boost.Test
15#include <boost/test/detail/config.hpp>
16#include <boost/test/tools/detail/print_helper.hpp>
17
18// STL
19#include <iosfwd>
20
21#include <boost/test/detail/suppress_warnings.hpp>
22
23//____________________________________________________________________________//
24
25// ************************************************************************** //
26// ************** lazy_ostream ************** //
27// ************************************************************************** //
28
29namespace boost {
30namespace unit_test {
31
32class BOOST_TEST_DECL lazy_ostream {
33public:
34 virtual ~lazy_ostream() {}
35
36 static lazy_ostream& instance() { return inst; }
37
38 #if !defined(BOOST_EMBTC)
39
40 friend std::ostream& operator<<( std::ostream& ostr, lazy_ostream const& o ) { return o( ostr ); }
41
42 #else
43
44 friend std::ostream& operator<<( std::ostream& ostr, lazy_ostream const& o );
45
46 #endif
47
48 // access method
49 bool empty() const { return m_empty; }
50
51 // actual printing interface; to be accessed only by this class and children
52 virtual std::ostream& operator()( std::ostream& ostr ) const { return ostr; }
53protected:
54 explicit lazy_ostream( bool p_empty = true ) : m_empty( p_empty ) {}
55
56private:
57 // Data members
58 bool m_empty;
59 static lazy_ostream inst;
60};
61
62#if defined(BOOST_EMBTC)
63
64 inline std::ostream& operator<<( std::ostream& ostr, lazy_ostream const& o ) { return o( ostr ); }
65
66#endif
67
68//____________________________________________________________________________//
69
70template<typename PrevType, typename T, typename StorageT=T const&>
71class lazy_ostream_impl : public lazy_ostream {
72public:
73 lazy_ostream_impl( PrevType const& prev, T const& value )
74 : lazy_ostream( false )
75 , m_prev( prev )
76 , m_value( value )
77 {
78 }
79
80 std::ostream& operator()( std::ostream& ostr ) const BOOST_OVERRIDE
81 {
82 return m_prev(ostr) << test_tools::tt_detail::print_helper(m_value);
83 }
84private:
85 // Data members
86 PrevType const& m_prev;
87 StorageT m_value;
88};
89
90//____________________________________________________________________________//
91
92template<typename T>
93inline lazy_ostream_impl<lazy_ostream,T>
94operator<<( lazy_ostream const& prev, T const& v )
95{
96 return lazy_ostream_impl<lazy_ostream,T>( prev, v );
97}
98
99//____________________________________________________________________________//
100
101template<typename PrevPrevType, typename TPrev, typename T>
102inline lazy_ostream_impl<lazy_ostream_impl<PrevPrevType,TPrev>,T>
103operator<<( lazy_ostream_impl<PrevPrevType,TPrev> const& prev, T const& v )
104{
105 typedef lazy_ostream_impl<PrevPrevType,TPrev> PrevType;
106 return lazy_ostream_impl<PrevType,T>( prev, v );
107}
108
109//____________________________________________________________________________//
110
111#if BOOST_TEST_USE_STD_LOCALE
112
113template<typename R,typename S>
114inline lazy_ostream_impl<lazy_ostream,R& (BOOST_TEST_CALL_DECL *)(S&),R& (BOOST_TEST_CALL_DECL *)(S&)>
115operator<<( lazy_ostream const& prev, R& (BOOST_TEST_CALL_DECL *man)(S&) )
116{
117 typedef R& (BOOST_TEST_CALL_DECL * ManipType)(S&);
118
119 return lazy_ostream_impl<lazy_ostream,ManipType,ManipType>( prev, man );
120}
121
122//____________________________________________________________________________//
123
124template<typename PrevPrevType, typename TPrev,typename R,typename S>
125inline lazy_ostream_impl<lazy_ostream_impl<PrevPrevType,TPrev>,R& (BOOST_TEST_CALL_DECL *)(S&),R& (BOOST_TEST_CALL_DECL *)(S&)>
126operator<<( lazy_ostream_impl<PrevPrevType,TPrev> const& prev, R& (BOOST_TEST_CALL_DECL *man)(S&) )
127{
128 typedef R& (BOOST_TEST_CALL_DECL * ManipType)(S&);
129
130 return lazy_ostream_impl<lazy_ostream_impl<PrevPrevType,TPrev>,ManipType,ManipType>( prev, man );
131}
132
133//____________________________________________________________________________//
134
135#endif
136
137#define BOOST_TEST_LAZY_MSG( M ) (::boost::unit_test::lazy_ostream::instance() << M)
138
139} // namespace unit_test
140} // namespace boost
141
142#include <boost/test/detail/enable_warnings.hpp>
143
144#endif // BOOST_TEST_UTILS_LAZY_OSTREAM_HPP
145

source code of boost/libs/test/include/boost/test/utils/lazy_ostream.hpp