Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:02:48

0001 
0002 //              Copyright Catch2 Authors
0003 // Distributed under the Boost Software License, Version 1.0.
0004 //   (See accompanying file LICENSE.txt or copy at
0005 //        https://www.boost.org/LICENSE_1_0.txt)
0006 
0007 // SPDX-License-Identifier: BSL-1.0
0008 #ifndef CATCH_INTERFACES_ENUM_VALUES_REGISTRY_HPP_INCLUDED
0009 #define CATCH_INTERFACES_ENUM_VALUES_REGISTRY_HPP_INCLUDED
0010 
0011 #include <catch2/internal/catch_stringref.hpp>
0012 
0013 #include <vector>
0014 
0015 namespace Catch {
0016 
0017     namespace Detail {
0018         struct EnumInfo {
0019             StringRef m_name;
0020             std::vector<std::pair<int, StringRef>> m_values;
0021 
0022             ~EnumInfo();
0023 
0024             StringRef lookup( int value ) const;
0025         };
0026     } // namespace Detail
0027 
0028     class IMutableEnumValuesRegistry {
0029     public:
0030         virtual ~IMutableEnumValuesRegistry(); // = default;
0031 
0032         virtual Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values ) = 0;
0033 
0034         template<typename E>
0035         Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::initializer_list<E> values ) {
0036             static_assert(sizeof(int) >= sizeof(E), "Cannot serialize enum to int");
0037             std::vector<int> intValues;
0038             intValues.reserve( values.size() );
0039             for( auto enumValue : values )
0040                 intValues.push_back( static_cast<int>( enumValue ) );
0041             return registerEnum( enumName, allEnums, intValues );
0042         }
0043     };
0044 
0045 } // Catch
0046 
0047 #endif // CATCH_INTERFACES_ENUM_VALUES_REGISTRY_HPP_INCLUDED