Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
catch_interfaces_exception.h
Go to the documentation of this file.
1/*
2 * Created by Phil on 20/04/2011.
3 * Copyright 2011 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_INTERFACES_EXCEPTION_H_INCLUDED
9#define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
10
12
13#if defined(CATCH_CONFIG_DISABLE)
14 #define INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( translatorName, signature) \
15 static std::string translatorName( signature )
16#endif
17
18#include <exception>
19#include <string>
20#include <vector>
21
22namespace Catch {
23 using exceptionTranslateFunction = std::string(*)();
24
26 using ExceptionTranslators = std::vector<std::unique_ptr<IExceptionTranslator const>>;
27
30 virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0;
31 };
32
35
36 virtual std::string translateActiveException() const = 0;
37 };
38
40 template<typename T>
41 class ExceptionTranslator : public IExceptionTranslator {
42 public:
43
44 ExceptionTranslator( std::string(*translateFunction)( T& ) )
45 : m_translateFunction( translateFunction )
46 {}
47
48 std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override {
49 try {
50 if( it == itEnd )
51 std::rethrow_exception(std::current_exception());
52 else
53 return (*it)->translate( it+1, itEnd );
54 }
55 catch( T& ex ) {
56 return m_translateFunction( ex );
57 }
58 }
59
60 protected:
61 std::string(*m_translateFunction)( T& );
62 };
63
64 public:
65 template<typename T>
66 ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) {
68 ( new ExceptionTranslator<T>( translateFunction ) );
69 }
70 };
71}
72
74#define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \
75 static std::string translatorName( signature ); \
76 CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
77 namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \
78 CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
79 static std::string translatorName( signature )
80
81#define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
82
83#endif // TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
ExceptionTranslatorRegistrar(std::string(*translateFunction)(T &))
std::vector< std::unique_ptr< IExceptionTranslator const > > ExceptionTranslators
IMutableRegistryHub & getMutableRegistryHub()
std::string(*)() exceptionTranslateFunction
#define T(meth, val, expected)
virtual std::string translate(ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd) const =0
virtual std::string translateActiveException() const =0
virtual void registerTranslator(const IExceptionTranslator *translator)=0