| 
									
										
										
										
											2011-04-20 15:40:40 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  *  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)
 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-09-17 01:42:29 -04:00
										 |  |  | #ifndef TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
 | 
					
						
							|  |  |  | #define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
 | 
					
						
							| 
									
										
										
										
											2011-04-20 15:40:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							| 
									
										
										
										
											2015-11-18 08:39:21 +00:00
										 |  |  | #include <vector>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-07 07:58:34 +01:00
										 |  |  | #include "catch_interfaces_registry_hub.h"
 | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-15 08:02:36 +01:00
										 |  |  | namespace Catch { | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-20 15:40:40 +01:00
										 |  |  |     typedef std::string(*exceptionTranslateFunction)(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-18 08:39:21 +00:00
										 |  |  |     struct IExceptionTranslator; | 
					
						
							|  |  |  |     typedef std::vector<const IExceptionTranslator*> ExceptionTranslators; | 
					
						
							| 
									
										
										
										
											2015-12-04 10:20:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-15 08:02:36 +01:00
										 |  |  |     struct IExceptionTranslator { | 
					
						
							| 
									
										
										
										
											2012-08-13 07:46:10 +01:00
										 |  |  |         virtual ~IExceptionTranslator(); | 
					
						
							| 
									
										
										
										
											2015-11-18 08:39:21 +00:00
										 |  |  |         virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0; | 
					
						
							| 
									
										
										
										
											2011-04-20 15:40:40 +01:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-15 08:02:36 +01:00
										 |  |  |     struct IExceptionTranslatorRegistry { | 
					
						
							| 
									
										
										
										
											2012-08-13 07:46:10 +01:00
										 |  |  |         virtual ~IExceptionTranslatorRegistry(); | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-15 08:02:36 +01:00
										 |  |  |         virtual std::string translateActiveException() const = 0; | 
					
						
							| 
									
										
										
										
											2011-04-20 15:40:40 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-15 08:02:36 +01:00
										 |  |  |     class ExceptionTranslatorRegistrar { | 
					
						
							| 
									
										
										
										
											2011-04-20 19:09:41 +01:00
										 |  |  |         template<typename T> | 
					
						
							| 
									
										
										
										
											2012-05-15 08:02:36 +01:00
										 |  |  |         class ExceptionTranslator : public IExceptionTranslator { | 
					
						
							| 
									
										
										
										
											2011-04-20 19:09:41 +01:00
										 |  |  |         public: | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-15 08:02:36 +01:00
										 |  |  |             ExceptionTranslator( std::string(*translateFunction)( T& ) ) | 
					
						
							| 
									
										
										
										
											2011-04-20 19:09:41 +01:00
										 |  |  |             : m_translateFunction( translateFunction ) | 
					
						
							|  |  |  |             {} | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-25 12:41:30 +02:00
										 |  |  |             virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override { | 
					
						
							| 
									
										
										
										
											2012-05-15 08:02:36 +01:00
										 |  |  |                 try { | 
					
						
							| 
									
										
										
										
											2015-11-18 08:39:21 +00:00
										 |  |  |                     if( it == itEnd ) | 
					
						
							|  |  |  |                         throw; | 
					
						
							|  |  |  |                     else | 
					
						
							|  |  |  |                         return (*it)->translate( it+1, itEnd ); | 
					
						
							| 
									
										
										
										
											2011-04-20 19:09:41 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2012-05-15 08:02:36 +01:00
										 |  |  |                 catch( T& ex ) { | 
					
						
							| 
									
										
										
										
											2011-04-20 19:09:41 +01:00
										 |  |  |                     return m_translateFunction( ex ); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2011-04-20 15:40:40 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-20 19:09:41 +01:00
										 |  |  |         protected: | 
					
						
							|  |  |  |             std::string(*m_translateFunction)( T& ); | 
					
						
							|  |  |  |         }; | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-20 19:09:41 +01:00
										 |  |  |     public: | 
					
						
							|  |  |  |         template<typename T> | 
					
						
							| 
									
										
										
										
											2012-05-15 08:02:36 +01:00
										 |  |  |         ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) { | 
					
						
							| 
									
										
										
										
											2012-08-07 07:58:34 +01:00
										 |  |  |             getMutableRegistryHub().registerTranslator | 
					
						
							| 
									
										
										
										
											2011-04-20 19:09:41 +01:00
										 |  |  |                 ( new ExceptionTranslator<T>( translateFunction ) ); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-04-20 15:40:40 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-20 19:09:41 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2015-12-15 07:50:51 +00:00
										 |  |  | #define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \
 | 
					
						
							|  |  |  |     static std::string translatorName( signature ); \ | 
					
						
							|  |  |  |     namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); }\ | 
					
						
							|  |  |  |     static std::string translatorName( signature ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
 | 
					
						
							| 
									
										
										
										
											2011-04-20 19:09:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-17 01:42:29 -04:00
										 |  |  | #endif // TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
 |