// Copyright Catch2 Authors // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) // SPDX-License-Identifier: BSL-1.0 #pragma once #include #include #include #include #include #include #include namespace Catch { namespace Detail { template struct has_description : std::false_type {}; template struct has_description< T, void_t> : std::true_type {}; //! Actually registers the factory, independent on listener's concrete type void registerListenerImpl( Detail::unique_ptr listenerFactory ); } // namespace Detail class IEventListener; using IEventListenerPtr = Detail::unique_ptr; template class ListenerRegistrar { class TypedListenerFactory : public EventListenerFactory { StringRef m_listenerName; std::string getDescriptionImpl( std::true_type ) const { return T::getDescription(); } std::string getDescriptionImpl( std::false_type ) const { return "(No description provided)"; } public: TypedListenerFactory( StringRef listenerName ): m_listenerName( listenerName ) {} IEventListenerPtr create( IConfig const* config ) const override { return Detail::make_unique( config ); } StringRef getName() const override { return m_listenerName; } std::string getDescription() const override { return getDescriptionImpl( Detail::has_description{} ); } }; public: ListenerRegistrar(StringRef listenerName) { registerListenerImpl( Detail::make_unique(listenerName) ); } }; } #if !defined(CATCH_CONFIG_DISABLE) # define CATCH_REGISTER_LISTENER( listenerType ) \ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ namespace { \ const Catch::ListenerRegistrar \ INTERNAL_CATCH_UNIQUE_NAME( catch_internal_RegistrarFor )( \ #listenerType##_catch_sr ); \ } \ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION #else // CATCH_CONFIG_DISABLE #define CATCH_REGISTER_LISTENER(listenerType) #endif // CATCH_CONFIG_DISABLE