#pragma once #include #include namespace DB { class Context; /** Позволяет получить функцию по имени. * Функция при создании также может использовать для инициализации (например, захватить shared_ptr) * какие-нибудь справочники, находящиеся в Context-е. */ class FunctionFactory : public Singleton { friend class StorageSystemFunctions; private: typedef FunctionPtr (*Creator)(const Context & context); /// Не std::function, так как меньше indirection и размер объекта. std::unordered_map functions; public: FunctionFactory(); FunctionPtr get(const String & name, const Context & context) const; /// Кидает исключение, если не нашлось. FunctionPtr tryGet(const String & name, const Context & context) const; /// Возвращает nullptr, если не нашлось. template void registerFunction() { static_assert(std::is_same::value, "F::create has incorrect type"); functions[F::name] = &F::create; } }; }