blob: 4b9a0a36aa7ad970606b1c6ed912a9ef049baa6e [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// (C) Copyright Gennadiy Rozental 2008.
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// File : $RCSfile$
9//
10// Version : $Revision: 49312 $
11//
12// Description : contains definition for all test tools in test toolbox
13// ***************************************************************************
14
15#ifndef BOOST_TEST_LAZY_OSTREAM_HPP_070708GER
16#define BOOST_TEST_LAZY_OSTREAM_HPP_070708GER
17
18// Boost.Test
19#include <ndnboost/test/detail/config.hpp>
20
21// STL
22#include <iosfwd>
23
24#include <ndnboost/test/detail/suppress_warnings.hpp>
25
26//____________________________________________________________________________//
27
28// ************************************************************************** //
29// ************** lazy_ostream ************** //
30// ************************************************************************** //
31
32namespace ndnboost {
33
34namespace unit_test {
35
36class lazy_ostream {
37public:
38 static lazy_ostream& instance() { static lazy_ostream inst; return inst; }
39
40 friend std::ostream& operator<<( std::ostream& ostr, lazy_ostream const& o ) { return o( ostr ); }
41
42 // access method
43 bool empty() const { return m_empty; }
44
45 // actual printing interface; to be accessed only by this class and children
46 virtual std::ostream& operator()( std::ostream& ostr ) const { return ostr; }
47protected:
48 explicit lazy_ostream( bool empty = true ) : m_empty( empty ) {}
49
50 // protected destructor to make sure right one is called
51#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
52public:
53#endif
54 BOOST_TEST_PROTECTED_VIRTUAL ~lazy_ostream() {}
55
56private:
57 // Data members
58 bool m_empty;
59};
60
61//____________________________________________________________________________//
62
63template<typename T>
64class lazy_ostream_impl : public lazy_ostream {
65public:
66 lazy_ostream_impl( lazy_ostream const& prev, T value )
67 : lazy_ostream( false )
68 , m_prev( prev )
69 , m_value( value )
70 {}
71private:
72 virtual std::ostream& operator()( std::ostream& ostr ) const
73 {
74 return m_prev(ostr) << m_value;
75 }
76
77 // Data members
78 lazy_ostream const& m_prev;
79 T m_value;
80};
81
82//____________________________________________________________________________//
83
84template<typename T>
85inline lazy_ostream_impl<T const&>
86operator<<( lazy_ostream const& prev, T const& v )
87{
88 return lazy_ostream_impl<T const&>( prev, v );
89}
90
91//____________________________________________________________________________//
92
93#if BOOST_TEST_USE_STD_LOCALE
94
95template<typename R,typename S>
96inline lazy_ostream_impl<R& (BOOST_TEST_CALL_DECL *)(S&)>
97operator<<( lazy_ostream const& prev, R& (BOOST_TEST_CALL_DECL *man)(S&) )
98{
99 return lazy_ostream_impl<R& (BOOST_TEST_CALL_DECL *)(S&)>( prev, man );
100}
101
102//____________________________________________________________________________//
103
104#endif
105
106} // namespace unit_test
107
108} // namespace ndnboost
109
110//____________________________________________________________________________//
111
112#include <ndnboost/test/detail/enable_warnings.hpp>
113
114#endif // BOOST_TEST_LAZY_OSTREAM_HPP_070708GER