File indexing completed on 2025-01-30 10:02:48
0001
0002
0003
0004
0005
0006
0007
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 }
0027
0028 class IMutableEnumValuesRegistry {
0029 public:
0030 virtual ~IMutableEnumValuesRegistry();
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 }
0046
0047 #endif