1 /*
2  *  Created by Phil on 03/11/2010.
3  *  Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
4  *
5  *  Distributed under the Boost Software License, Version 1.0. (See accompanying
6  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  */
8 #ifndef TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
9 #define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
10 
11 #include "catch_section.h"
12 #include "catch_capture.hpp"
13 #include "catch_compiler_capabilities.h"
14 
15 namespace Catch {
16 
SectionInfo(SourceLineInfo const & _lineInfo,std::string const & _name,std::string const & _description)17     SectionInfo::SectionInfo
18         (   SourceLineInfo const& _lineInfo,
19             std::string const& _name,
20             std::string const& _description )
21     :   name( _name ),
22         description( _description ),
23         lineInfo( _lineInfo )
24     {}
25 
Section(SectionInfo const & info)26     Section::Section( SectionInfo const& info )
27     :   m_info( info ),
28         m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) )
29     {
30         m_timer.start();
31     }
32 
33 #if defined(_MSC_VER)
34 #pragma warning(push)
35 #pragma warning(disable:4996) // std::uncaught_exception is deprecated in C++17
36 #endif
~Section()37     Section::~Section() {
38         if( m_sectionIncluded ) {
39             SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() );
40             if( std::uncaught_exception() )
41                 getResultCapture().sectionEndedEarly( endInfo );
42             else
43                 getResultCapture().sectionEnded( endInfo );
44         }
45     }
46 #if defined(_MSC_VER)
47 #pragma warning(pop)
48 #endif
49 
50     // This indicates whether the section should be executed or not
operator bool() const51     Section::operator bool() const {
52         return m_sectionIncluded;
53     }
54 
55 
56 } // end namespace Catch
57 
58 #endif // TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
59