tudocomp
– The TU Dortmund Compression Framework
LiteralEncoder.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <tudocomp/Env.hpp>
5 #include <tudocomp/Literal.hpp>
6 #include <tudocomp/Range.hpp>
7 #include <tudocomp/io.hpp>
8 
9 namespace tdc {
10 
11 template<typename coder_t>
12 class LiteralEncoder: public Compressor {
13 
14 public:
15  inline static Meta meta() {
16  Meta m("compressor", "encode", "Simply encodes the input's individual characters.");
17  m.option("coder").templated<coder_t>("coder");
18  return m;
19  }
20 
21  inline LiteralEncoder(Env&& env) : Compressor(std::move(env)) {}
22 
23  inline virtual void compress(Input& input, Output& output) override final {
24  auto iview = input.as_view();
25 
26  typename coder_t::Encoder coder(
27  env().env_for_option("coder"), output, ViewLiterals(iview));
28 
29  for(uint8_t c : iview) {
30  coder.encode(c, literal_r);
31  }
32  }
33 
34  inline virtual void decompress(Input& input, Output& output) override final {
35  auto ostream = output.as_stream();
36  typename coder_t::Decoder decoder(env().env_for_option("coder"), input);
37 
38  while(!decoder.eof()) {
39  ostream << decoder.template decode<uint8_t>(literal_r);
40  }
41  }
42 };
43 
44 }
45 
Contains the text compression and encoding framework.
Definition: namespaces.hpp:11
Provides meta information about an Algorithm.
Definition: Meta.hpp:34
Base for data compressors.
Definition: Compressor.hpp:19
virtual void compress(Input &input, Output &output) override final
Compress the given input to the given output.
A literal iterator that yields every character from a View.
Definition: Literal.hpp:41
Env & env()
Provides access to the environment that the algorithm works in.
Definition: Algorithm.hpp:51
constexpr auto literal_r
Global predefined reange for literals.
Definition: Range.hpp:111
An abstraction layer for algorithm output.
Definition: Output.hpp:23
void templated(const std::string &accepted_type)
Declares that this option accepts values of the specified Algorithm type T.
Definition: Meta.hpp:93
virtual void decompress(Input &input, Output &output) override final
Decompress the given input to the given output.
OptionBuilder option(const std::string &name)
Declares an accepted option for this algorithm.
Definition: Meta.hpp:216
Local environment for a compression/encoding/decompression call.
An abstraction layer for algorithm input.
Definition: Input.hpp:37