mirror of https://github.com/catchorg/Catch2.git
Hold exception translators by unique_ptr
- and removed range deleters
This commit is contained in:
parent
cb6963216f
commit
46bf7605f4
|
@ -45,16 +45,6 @@ namespace Catch {
|
||||||
virtual ~NonCopyable();
|
virtual ~NonCopyable();
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename ContainerT>
|
|
||||||
void deleteAll( ContainerT& container ) {
|
|
||||||
for( auto p : container )
|
|
||||||
delete p;
|
|
||||||
}
|
|
||||||
template<typename AssociativeContainerT>
|
|
||||||
void deleteAllValues( AssociativeContainerT& container ) {
|
|
||||||
for( auto const& kvp : container )
|
|
||||||
delete kvp.second;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool startsWith( std::string const& s, std::string const& prefix );
|
bool startsWith( std::string const& s, std::string const& prefix );
|
||||||
bool startsWith( std::string const& s, char prefix );
|
bool startsWith( std::string const& s, char prefix );
|
||||||
|
|
|
@ -16,11 +16,10 @@
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
ExceptionTranslatorRegistry::~ExceptionTranslatorRegistry() {
|
ExceptionTranslatorRegistry::~ExceptionTranslatorRegistry() {
|
||||||
deleteAll( m_translators );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExceptionTranslatorRegistry::registerTranslator( const IExceptionTranslator* translator ) {
|
void ExceptionTranslatorRegistry::registerTranslator( const IExceptionTranslator* translator ) {
|
||||||
m_translators.push_back( translator );
|
m_translators.push_back( std::unique_ptr<const IExceptionTranslator>( translator ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ExceptionTranslatorRegistry::translateActiveException() const {
|
std::string ExceptionTranslatorRegistry::translateActiveException() const {
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "catch_interfaces_exception.h"
|
#include "catch_interfaces_exception.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ namespace Catch {
|
||||||
std::string tryTranslators() const;
|
std::string tryTranslators() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<const IExceptionTranslator*> m_translators;
|
std::vector<std::unique_ptr<IExceptionTranslator const>> m_translators;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace Catch {
|
||||||
typedef std::string(*exceptionTranslateFunction)();
|
typedef std::string(*exceptionTranslateFunction)();
|
||||||
|
|
||||||
struct IExceptionTranslator;
|
struct IExceptionTranslator;
|
||||||
typedef std::vector<const IExceptionTranslator*> ExceptionTranslators;
|
typedef std::vector<std::unique_ptr<IExceptionTranslator const>> ExceptionTranslators;
|
||||||
|
|
||||||
struct IExceptionTranslator {
|
struct IExceptionTranslator {
|
||||||
virtual ~IExceptionTranslator();
|
virtual ~IExceptionTranslator();
|
||||||
|
@ -40,7 +40,7 @@ namespace Catch {
|
||||||
: m_translateFunction( translateFunction )
|
: m_translateFunction( translateFunction )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override {
|
std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override {
|
||||||
try {
|
try {
|
||||||
if( it == itEnd )
|
if( it == itEnd )
|
||||||
throw;
|
throw;
|
||||||
|
|
Loading…
Reference in New Issue