#pragma once #include #include #include #include #include namespace DB { class Block; class Context; struct FormatSettings; class ReadBuffer; class WriteBuffer; class IBlockInputStream; class IBlockOutputStream; using BlockInputStreamPtr = std::shared_ptr; using BlockOutputStreamPtr = std::shared_ptr; /** Allows to create an IBlockInputStream or IBlockOutputStream by the name of the format. * Note: format and compression are independent things. */ class FormatFactory final : public ext::singleton { private: using InputCreator = std::function; using OutputCreator = std::function; using Creators = std::pair; using FormatsDictionary = std::unordered_map; public: BlockInputStreamPtr getInput(const String & name, ReadBuffer & buf, const Block & sample, const Context & context, UInt64 max_block_size) const; BlockOutputStreamPtr getOutput(const String & name, WriteBuffer & buf, const Block & sample, const Context & context) const; /// Register format by its name. void registerInputFormat(const String & name, InputCreator input_creator); void registerOutputFormat(const String & name, OutputCreator output_creator); const FormatsDictionary & getAllFormats() const { return dict; } private: FormatsDictionary dict; FormatFactory(); friend class ext::singleton; const Creators & getCreators(const String & name) const; }; }