summaryrefslogtreecommitdiff
path: root/sax/inc/sax_processor_builder.hh
blob: 8b114e4dec13bf1549e32e865cf1a13ad770e152 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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 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<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