aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/deprecated/enum_codegen/enum_codegen.h
blob: dfb04ecac29ab2f6cd7f48f6c0bb659e009a94f3 (plain) (blame)
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
#pragma once

/// see enum_codegen_ut.cpp for examples

#define ENUM_VALUE_GEN(name, value, ...) name = value,
#define ENUM_VALUE_GEN_NO_VALUE(name, ...) name,

#define ENUM_TO_STRING_IMPL_ITEM(name, ...) \
    case name:                              \
        return #name;
#define ENUM_LTLT_IMPL_ITEM(name, ...) \
    case name:                         \
        os << #name;                   \
        break;

#define ENUM_TO_STRING(type, MAP)                                            \
    static inline const char* ToCString(type value) {                        \
        switch (value) {                                                     \
            MAP(ENUM_TO_STRING_IMPL_ITEM)                                    \
            default:                                                         \
                return "UNKNOWN";                                            \
        }                                                                    \
    }                                                                        \
                                                                             \
    static inline IOutputStream& operator<<(IOutputStream& os, type value) { \
        switch (value) {                                                     \
            MAP(ENUM_LTLT_IMPL_ITEM)                                         \
            default:                                                         \
                os << int(value);                                            \
                break;                                                       \
        }                                                                    \
        return os;                                                           \
    }