aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Common/register_objects.h
blob: 0a08fdf43a405ba904634f6e95d832bb05891166 (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

#include <string_view>
#include <unordered_map>

namespace DB
{

class FunctionFactory;

using FunctionRegisterFunctionPtr = void (*)(::DB::FunctionFactory &);

struct FunctionRegisterMap : public std::unordered_map<std::string_view, FunctionRegisterFunctionPtr>
{
    static FunctionRegisterMap & instance();
};

struct FunctionRegister
{
    FunctionRegister(std::string_view name, FunctionRegisterFunctionPtr func_ptr)
    {
        FunctionRegisterMap::instance().emplace(std::move(name), func_ptr);
    }
};

}

#define REGISTER_FUNCTION_IMPL(fn, func_name, register_name) \
    void func_name(::DB::FunctionFactory & factory); \
    static ::DB::FunctionRegister register_name(#fn, func_name); \
    void func_name(::DB::FunctionFactory & factory)

#define REGISTER_FUNCTION(fn) REGISTER_FUNCTION_IMPL(fn, registerFunction##fn, REGISTER_FUNCTION_##fn)