mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-11-04 00:51:52 +01:00 
			
		
		
		
	Standardize header names and file locations
This is both a really big and a really small commit. It is small in
that it only contains renaming, moving and modification of include
directives caused by this.
It is really big in the obvious way of touching something like 200
files.
The new rules for naming files is simple: headers use the `.hpp`
extension. The rules for physical file layout is still kinda in
progress, but the basics are also simple:
 * Significant parts of functionality get their own subfolder
   * Benchmarking is in `catch2/benchmark`
   * Matchers are in `catch2/matchers`
   * Generators are in `catch2/generators`
   * Reporters are in `catch2/reporters`
   * Baseline testing facilities are in `catch2/`
 * Various top level folders also contain `internal` subfolder,
   with files that users probably do not want to include directly,
   at least not until they have to write something like their own
   reporter.
    * The exact files in these subfolders is likely to change later
      on
Note that while some includes were cleaned up in this commit, it
is only the low hanging fruit and further cleanup using automatic
tooling will happen later.
Also note that various include guards, copyright notices and file
headers will also be standardized later, rather than in this commit.
			
			
This commit is contained in:
		
							
								
								
									
										89
									
								
								src/catch2/interfaces/catch_interfaces_exception.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								src/catch2/interfaces/catch_interfaces_exception.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,89 @@
 | 
			
		||||
/*
 | 
			
		||||
 *  Created by Phil on 20/04/2011.
 | 
			
		||||
 *  Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
 | 
			
		||||
 *
 | 
			
		||||
 *  Distributed under the Boost Software License, Version 1.0. (See accompanying
 | 
			
		||||
 *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 | 
			
		||||
 */
 | 
			
		||||
#ifndef TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
 | 
			
		||||
#define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
 | 
			
		||||
 | 
			
		||||
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
 | 
			
		||||
#include <catch2/internal/catch_compiler_capabilities.hpp>
 | 
			
		||||
 | 
			
		||||
#if defined(CATCH_CONFIG_DISABLE)
 | 
			
		||||
    #define INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( translatorName, signature) \
 | 
			
		||||
        static std::string translatorName( signature )
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include <exception>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
namespace Catch {
 | 
			
		||||
    using exceptionTranslateFunction = std::string(*)();
 | 
			
		||||
 | 
			
		||||
    struct IExceptionTranslator;
 | 
			
		||||
    using ExceptionTranslators = std::vector<std::unique_ptr<IExceptionTranslator const>>;
 | 
			
		||||
 | 
			
		||||
    struct IExceptionTranslator {
 | 
			
		||||
        virtual ~IExceptionTranslator();
 | 
			
		||||
        virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    struct IExceptionTranslatorRegistry {
 | 
			
		||||
        virtual ~IExceptionTranslatorRegistry();
 | 
			
		||||
 | 
			
		||||
        virtual std::string translateActiveException() const = 0;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    class ExceptionTranslatorRegistrar {
 | 
			
		||||
        template<typename T>
 | 
			
		||||
        class ExceptionTranslator : public IExceptionTranslator {
 | 
			
		||||
        public:
 | 
			
		||||
 | 
			
		||||
            ExceptionTranslator( std::string(*translateFunction)( T& ) )
 | 
			
		||||
            : m_translateFunction( translateFunction )
 | 
			
		||||
            {}
 | 
			
		||||
 | 
			
		||||
            std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override {
 | 
			
		||||
#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
 | 
			
		||||
                try {
 | 
			
		||||
                    if( it == itEnd )
 | 
			
		||||
                        std::rethrow_exception(std::current_exception());
 | 
			
		||||
                    else
 | 
			
		||||
                        return (*it)->translate( it+1, itEnd );
 | 
			
		||||
                }
 | 
			
		||||
                catch( T& ex ) {
 | 
			
		||||
                    return m_translateFunction( ex );
 | 
			
		||||
                }
 | 
			
		||||
#else
 | 
			
		||||
                return "You should never get here!";
 | 
			
		||||
#endif
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        protected:
 | 
			
		||||
            std::string(*m_translateFunction)( T& );
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
    public:
 | 
			
		||||
        template<typename T>
 | 
			
		||||
        ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) {
 | 
			
		||||
            getMutableRegistryHub().registerTranslator
 | 
			
		||||
                ( new ExceptionTranslator<T>( translateFunction ) );
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
#define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \
 | 
			
		||||
    static std::string translatorName( signature ); \
 | 
			
		||||
    CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
 | 
			
		||||
    CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
 | 
			
		||||
    namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \
 | 
			
		||||
    CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
 | 
			
		||||
    static std::string translatorName( signature )
 | 
			
		||||
 | 
			
		||||
#define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
 | 
			
		||||
 | 
			
		||||
#endif // TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
 | 
			
		||||
		Reference in New Issue
	
	Block a user