* [qt] Updating CMake project files for Qt6 * [qt] Updating non-test projects for Qt6 and msvc2019 * [qt] Test fixes for Qt6 and msvc2019 * [qt] Link whole test archive for Qt and msvc2019 * [qt] Fixing Qt6 headless backend renderer * [qt] Fixes for test failures * [qt] Expression and style parser test fixes * [qt] Backwards compatibility with Qt5 and Qt6 Minimum version is Qt 5.4 due to use of QOpenGLWidget * [qt] LLVM is no longer required for a Windows build * [msvc] msvc2019 fixes for maplibre * Update test/storage/offline_database.test.cpp Co-authored-by: Tadej Novak <tadej@tano.si> * Vector + const is not standard C++ Co-authored-by: Tadej Novak <tadej@tano.si>
38 lines
1.6 KiB
C++
38 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <mbgl/util/optional.hpp>
|
|
|
|
#include <algorithm>
|
|
#include <cassert>
|
|
#include <string>
|
|
|
|
namespace mbgl {
|
|
|
|
template <typename T>
|
|
class Enum {
|
|
public:
|
|
using Type = T;
|
|
static const char * toString(T);
|
|
static optional<T> toEnum(const std::string&);
|
|
};
|
|
|
|
#define MBGL_DEFINE_ENUM(T, ...) \
|
|
\
|
|
static const constexpr std::pair<const T, const char *> T##_names[] = __VA_ARGS__; \
|
|
\
|
|
template <> \
|
|
const char * Enum<T>::toString(T t) { \
|
|
auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \
|
|
[&] (const auto& v) { return t == v.first; }); \
|
|
assert(it != std::end(T##_names)); return it->second; \
|
|
} \
|
|
\
|
|
template <> \
|
|
optional<T> Enum<T>::toEnum(const std::string& s) { \
|
|
auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \
|
|
[&] (const auto& v) { return s == v.second; }); \
|
|
return it == std::end(T##_names) ? optional<T>() : it->first; \
|
|
}
|
|
|
|
} // namespace mbgl
|