#ifndef MODXML_SAX_PROCESSOR_BUILDER_HH #define MODXML_SAX_PROCESSOR_BUILDER_HH #include #include namespace modxml { namespace sax { class DecoderFactory; class Delegate; class Processor; /** * Used to construct Processor's with options set if needed. */ class ProcessorBuilder { public: virtual ~ProcessorBuilder() = default; /** * Construct a ProcessorBuilder. All options are set to default. */ static std::unique_ptr create(); /** * If you know the encoding of the data sent to the processor set it here, * this will stop the processor from trying to autodetect and will ignore * encoding in any xml declaration if found. * If the encoding is unsupported/unknown the processor will fail with * an error indicating this, same as if it read a xml declaration with * an unsupported or unknown encoding. */ virtual ProcessorBuilder* force_encoding(std::string const& str) = 0; /** * Set a decoder factory for encodings not supported by library. * Library only calls this for encodings it doesn't support itself. * Library supports UTF-8, UTF-16, UTF-32 and US-ASCII. * If you want to force the decoder factory to be used, force a custom * encoding with force_encoding above. */ virtual ProcessorBuilder* custom_decoder_factory( std::shared_ptr custom_decoder_factory) = 0; /** * Set the default buffer size the processor should use. * If you give a too small buffer size (such as zero) it will be ignored * and a implementation specific minimum will be used instead. * This is meant as a possible optimization and can be completely ignored. * Note that the processor will allocate more data if it needs to. */ virtual ProcessorBuilder* set_default_buffer_size(std::size_t size) = 0; /** * Set the max buffer size the processor should use. * If you have memory constraints this will block the processing of CDATA, * or other entities from allocating more than the given size. * Default is 10MiB. */ virtual ProcessorBuilder* set_max_buffer_size(std::size_t size) = 0; /** * Call to construct a Processor with the options setup in this builder, * using the delegate given as parameter. * May be called multiple times, will create an unique Processor each time. */ virtual std::unique_ptr build( std::shared_ptr delegate) const = 0; protected: ProcessorBuilder() = default; private: ProcessorBuilder(ProcessorBuilder const&) = delete; ProcessorBuilder& operator=(ProcessorBuilder const&) = delete; }; } // namespace sax } // namespace modxml #endif // MODXML_SAX_PROCESSOR_BUILDER_HH