MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
enum.hpp File Reference
#include <algorithm>
#include <cassert>
#include <string>
#include <optional>

Go to the source code of this file.

Classes

class  mbgl::Enum< T >
 

Namespaces

 mbgl
 

Macros

#define MBGL_DEFINE_ENUM(T, ...)
 

Macro Definition Documentation

◆ MBGL_DEFINE_ENUM

#define MBGL_DEFINE_ENUM (   T,
  ... 
)
Value:
\
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 <> \
std::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) ? std::optional<T>() : it->first; \
}
std::unique_ptr< Expression > toString(std::unique_ptr< Expression >, std::unique_ptr< Expression > def=nullptr)
std::unique_ptr< Expression > string(std::unique_ptr< Expression >, std::unique_ptr< Expression > def=nullptr)

Definition at line 18 of file enum.hpp.