tudocomp
– The TU Dortmund Compression Framework
NoopCompressor.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <tudocomp/Env.hpp>
5 #include <tudocomp/io.hpp>
6 
7 namespace tdc {
8 
9 class NoopCompressor: public Compressor {
10 public:
11  inline static Meta meta() {
12  Meta m("compressor", "noop");
13  m.option("mode").dynamic("stream");
14  m.option("debug").dynamic(false);
15  return m;
16  }
17 
18  inline NoopCompressor(Env&& env):
19  Compressor(std::move(env)) {}
20 
21 
22  inline virtual void compress(Input& i, Output& o) override final {
23  auto os = o.as_stream();
24 
25  if (env().option("mode").as_string() == "stream") {
26  auto is = i.as_stream();
27  if (env().option("debug").as_bool()) {
28  std::stringstream ss;
29  ss << is.rdbuf();
30  std::string txt = ss.str();
31  DLOG(INFO) << vec_to_debug_string(txt);
32  os << txt;
33  } else {
34  os << is.rdbuf();
35  }
36  } else {
37  auto iv = i.as_view();
38  if (env().option("debug").as_bool()) {
39  DLOG(INFO) << vec_to_debug_string(iv);
40  os << iv;
41  } else {
42  os << iv;
43  }
44  }
45  }
46 
47  inline virtual void decompress(Input& i, Output& o) override final {
48  auto os = o.as_stream();
49 
50  if (env().option("mode").as_string() == "stream") {
51  auto is = i.as_stream();
52  if (env().option("debug").as_bool()) {
53  std::stringstream ss;
54  ss << is.rdbuf();
55  std::string txt = ss.str();
56  DLOG(INFO) << vec_to_debug_string(txt);
57  os << txt;
58  } else {
59  os << is.rdbuf();
60  }
61  } else {
62  auto iv = i.as_view();
63  if (env().option("debug").as_bool()) {
64  DLOG(INFO) << vec_to_debug_string(iv);
65  os << iv;
66  } else {
67  os << iv;
68  }
69  }
70  }
71 };
72 
73 }
74 
Contains the text compression and encoding framework.
Definition: namespaces.hpp:11
Provides meta information about an Algorithm.
Definition: Meta.hpp:34
std::string vec_to_debug_string(const T &s, size_t indent=0)
Builds the string representation of a vector of byte values, sorrounded by square brackets ([ and ])...
Base for data compressors.
Definition: Compressor.hpp:19
virtual void decompress(Input &i, Output &o) override final
Decompress the given input to the given output.
Env & env()
Provides access to the environment that the algorithm works in.
Definition: Algorithm.hpp:51
An abstraction layer for algorithm output.
Definition: Output.hpp:23
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.
virtual void compress(Input &i, Output &o) override final
Compress the given input to the given output.
void dynamic()
Declares that this option accepts values of a simple type that can be parsed from a string (e...
Definition: Meta.hpp:150
An abstraction layer for algorithm input.
Definition: Input.hpp:37