aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Common/StatusInfo.cpp
blob: 1f9ddfaf4b9e7d792e46630ec2bc2f448ee1aaa5 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <Common/StatusInfo.h>
#include <Common/ExternalLoaderStatus.h>

/// Available status. Add something here as you wish.
#define APPLY_FOR_STATUS(M) \
    M(DictionaryStatus, "Dictionary Status.", DB::getStatusEnumAllPossibleValues()) \


namespace CurrentStatusInfo
{
    #define M(NAME, DOCUMENTATION, ENUM) extern const Status NAME = Status(__COUNTER__);
        APPLY_FOR_STATUS(M)
    #undef M
    constexpr Status END = Status(__COUNTER__);

    std::mutex locks[END] {};
    std::unordered_map<String, Int8> values[END] {};

    const char * getName(Status event)
    {
        static const char * strings[] =
        {
        #define M(NAME, DOCUMENTATION, ENUM) #NAME,
            APPLY_FOR_STATUS(M)
        #undef M
        };

        return strings[event];
    }

    const char * getDocumentation(Status event)
    {
        static const char * strings[] =
        {
        #define M(NAME, DOCUMENTATION, ENUM) #DOCUMENTATION,
            APPLY_FOR_STATUS(M)
        #undef M
        };

        return strings[event];
    }

    const std::vector<std::pair<String, Int8>> & getAllPossibleValues(Status event)
    {
        static const std::vector<std::pair<String, Int8>> enum_values [] =
        {
        #define M(NAME, DOCUMENTATION, ENUM) ENUM,
            APPLY_FOR_STATUS(M)
        #undef M
        };
        return enum_values[event];
    }

    Status end() { return END; }
}

#undef APPLY_FOR_STATUS