#pragma once #include #include namespace DB { class Context; /** Creates function by name. * Function could use for initialization (take ownership of shared_ptr, for example) * some dictionaries from Context. */ class FunctionFactory : public Singleton { friend class StorageSystemFunctions; private: typedef FunctionPtr (*Creator)(const Context & context); /// Not std::function, for lower object size and less indirection. std::unordered_map functions; public: FunctionFactory(); FunctionPtr get(const String & name, const Context & context) const; /// Throws an exception if not found. FunctionPtr tryGet(const String & name, const Context & context) const; /// Returns nullptr if not found. template void registerFunction() { static_assert(std::is_same::value, "F::create has incorrect type"); functions[F::name] = &F::create; } }; }