blob: da3fa2267d6602ffafbd5fc7b36a7969da95a406 [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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070015#ifndef NDNBOOST_TEST_LAZY_OSTREAM_HPP_070708GER
16#define NDNBOOST_TEST_LAZY_OSTREAM_HPP_070708GER
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070017
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070051#if NDNBOOST_WORKAROUND(__BORLANDC__, NDNBOOST_TESTED_AT(0x582))
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070052public:
53#endif
Jeff Thompson3d613fd2013-10-15 15:39:04 -070054 NDNBOOST_TEST_PROTECTED_VIRTUAL ~lazy_ostream() {}
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070055
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070093#if NDNBOOST_TEST_USE_STD_LOCALE
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070094
95template<typename R,typename S>
Jeff Thompson3d613fd2013-10-15 15:39:04 -070096inline lazy_ostream_impl<R& (NDNBOOST_TEST_CALL_DECL *)(S&)>
97operator<<( lazy_ostream const& prev, R& (NDNBOOST_TEST_CALL_DECL *man)(S&) )
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070098{
Jeff Thompson3d613fd2013-10-15 15:39:04 -070099 return lazy_ostream_impl<R& (NDNBOOST_TEST_CALL_DECL *)(S&)>( prev, man );
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700100}
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700114#endif // NDNBOOST_TEST_LAZY_OSTREAM_HPP_070708GER