diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2023-06-13 10:07:16 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2023-06-13 10:07:16 +0200 |
| commit | fc4547b412e28164af1bf8981234c6af959ccc0b (patch) | |
| tree | 061253e7a4f6abaca282223b36d10f0bed8cad23 /sax/inc/sax_processor_builder.hh | |
WIP
Diffstat (limited to 'sax/inc/sax_processor_builder.hh')
| -rw-r--r-- | sax/inc/sax_processor_builder.hh | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/sax/inc/sax_processor_builder.hh b/sax/inc/sax_processor_builder.hh new file mode 100644 index 0000000..070fbbf --- /dev/null +++ b/sax/inc/sax_processor_builder.hh @@ -0,0 +1,82 @@ +#ifndef MODXML_SAX_PROCESSOR_BUILDER_HH +#define MODXML_SAX_PROCESSOR_BUILDER_HH + +#include <memory> +#include <string> + +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<ProcessorBuilder> 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<DecoderFactory> 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 needed. + */ + 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<Processor> build( + std::shared_ptr<Delegate> 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 |
