Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/Progmasoft/Catch3/Internal/EnumInfo.hpp
blob: 3c4a58d7585bd4cfdb1bb69279193db895c6b0de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

//              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 <Progmasoft/Catch3/Internal/StringRef.hpp>

#include <cstdint>
#include <utility>
#include <vector>

namespace Catch {
    namespace Detail {

        struct EnumInfo {
            StringRef m_name;
            std::vector<std::pair<int64_t, StringRef>> m_values;

            StringRef lookup( int64_t value ) const;
        };

        EnumInfo makeEnumInfo( StringRef enumName,
                               StringRef allValueNames,
                               std::vector<int64_t> const& values );
        template <typename E>
        Detail::EnumInfo makeEnumInfo( StringRef enumName,
                                       StringRef allEnums,
                                       std::initializer_list<E> values ) {
            static_assert( sizeof( int64_t ) >= sizeof( E ),
                           "Cannot serialize enum to int64_t" );
            std::vector<int64_t> intValues;
            intValues.reserve( values.size() );
            for ( auto enumValue : values )
                intValues.push_back( static_cast<int64_t>( enumValue ) );
            return makeEnumInfo( enumName, allEnums, intValues );
        }

        std::vector<StringRef> parseEnums( StringRef enums );

    } // namespace Detail
} // namespace Catch