mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-28 21:53:30 +01:00
f29c898443
Some files had include guards that didn't match the file name, and others were missing the include guards entirely. Standardized this so that every include file has an include guard, and all the guards are of the form TWOBLUECUBES_<FILENAME>_<EXT>_INCLUDED
67 lines
2.3 KiB
C++
67 lines
2.3 KiB
C++
/*
|
|
* 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 <string>
|
|
#include "catch_interfaces_registry_hub.h"
|
|
|
|
namespace Catch {
|
|
|
|
typedef std::string(*exceptionTranslateFunction)();
|
|
|
|
struct IExceptionTranslator {
|
|
virtual ~IExceptionTranslator();
|
|
virtual std::string translate() 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 )
|
|
{}
|
|
|
|
virtual std::string translate() const {
|
|
try {
|
|
throw;
|
|
}
|
|
catch( T& ex ) {
|
|
return m_translateFunction( ex );
|
|
}
|
|
}
|
|
|
|
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_EXCEPTION( signature ) \
|
|
static std::string INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator )( signature ); \
|
|
namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ) ); }\
|
|
static std::string INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator )( signature )
|
|
|
|
#endif // TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
|