LCOV - code coverage report
Current view: top level - opt/homebrew/include/boost/test/utils - lazy_ostream.hpp (source / functions) Hit Total Coverage
Test: test_dash_coverage.info Lines: 18 18 100.0 %
Date: 2026-06-25 07:23:51 Functions: 1312 2214 59.3 %

          Line data    Source code
       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             : 
      29             : namespace boost {
      30             : namespace unit_test {
      31             : 
      32             : class BOOST_TEST_DECL lazy_ostream {
      33             : public:
      34    13766870 :     virtual                 ~lazy_ostream()                                         {}
      35             : 
      36    13192849 :     static lazy_ostream&    instance()                                              { return inst; }
      37             : 
      38             :     #if !defined(BOOST_EMBTC)
      39             :       
      40         128 :     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     6628731 :     bool                    empty() const                                           { return m_empty; }
      50             : 
      51             :     // actual printing interface; to be accessed only by this class and children
      52         128 :     virtual std::ostream&   operator()( std::ostream& ostr ) const                  { return ostr; }
      53             : protected:
      54    13767162 :     explicit                lazy_ostream( bool p_empty = true ) : m_empty( p_empty )    {}
      55             : 
      56             : private:
      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             : 
      70             : template<typename PrevType, typename T, typename StorageT=T const&>
      71             : class lazy_ostream_impl : public lazy_ostream {
      72             : public:
      73    27533740 :     lazy_ostream_impl( PrevType const& prev, T const& value )
      74    13766870 :     : lazy_ostream( false )
      75    13766870 :     , m_prev( prev )
      76    13766870 :     , m_value( value )
      77    27533740 :     {
      78    27533740 :     }
      79             : 
      80         227 :     std::ostream&   operator()( std::ostream& ostr ) const BOOST_OVERRIDE
      81             :     {
      82         227 :         return m_prev(ostr) << test_tools::tt_detail::print_helper(m_value);
      83             :     }
      84             : private:
      85             :     // Data members
      86             :     PrevType const&         m_prev;
      87             :     StorageT                m_value;
      88             : };
      89             : 
      90             : //____________________________________________________________________________//
      91             : 
      92             : template<typename T>
      93             : inline lazy_ostream_impl<lazy_ostream,T>
      94    13192849 : operator<<( lazy_ostream const& prev, T const& v )
      95             : {
      96    13192849 :     return lazy_ostream_impl<lazy_ostream,T>( prev, v );
      97             : }
      98             : 
      99             : //____________________________________________________________________________//
     100             : 
     101             : template<typename PrevPrevType, typename TPrev, typename T>
     102             : inline lazy_ostream_impl<lazy_ostream_impl<PrevPrevType,TPrev>,T>
     103      574021 : operator<<( lazy_ostream_impl<PrevPrevType,TPrev> const& prev, T const& v )
     104             : {
     105             :     typedef lazy_ostream_impl<PrevPrevType,TPrev> PrevType;
     106      574021 :     return lazy_ostream_impl<PrevType,T>( prev, v );
     107             : }
     108             : 
     109             : //____________________________________________________________________________//
     110             : 
     111             : #if BOOST_TEST_USE_STD_LOCALE
     112             : 
     113             : template<typename R,typename S>
     114             : inline lazy_ostream_impl<lazy_ostream,R& (BOOST_TEST_CALL_DECL *)(S&),R& (BOOST_TEST_CALL_DECL *)(S&)>
     115             : operator<<( 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             : 
     124             : template<typename PrevPrevType, typename TPrev,typename R,typename S>
     125             : inline lazy_ostream_impl<lazy_ostream_impl<PrevPrevType,TPrev>,R& (BOOST_TEST_CALL_DECL *)(S&),R& (BOOST_TEST_CALL_DECL *)(S&)>
     126             : operator<<( 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

Generated by: LCOV version 1.16