tudocomp
– The TU Dortmund Compression Framework
InputSize.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 namespace tdc {namespace io {
4  inline size_t Input::Variant::size() const {
5  if (source().is_view()) {
6 
7  auto actual_to = to();
8  if (to_unknown()) {
9  actual_to = source().view().size();
10  }
11  if(escaped_size_unknown()) {
12  if(restrictions().has_no_restrictions()) {
13  set_escaped_size(actual_to - from());
14  } else {
15  auto strm = as_stream();
16  size_t i = 0;
17  char c;
18  while (strm.get(c)) {
19  ++i;
20  }
21 
22  set_escaped_size(i);
23  }
24  }
25 
26  } else if (source().is_file()) {
27 
28  auto actual_to = to();
29  if (to_unknown()) {
30  actual_to = read_file_size(source().file());
31  }
32  if(escaped_size_unknown()) {
33  if(restrictions().has_no_restrictions()) {
34  set_escaped_size(actual_to - from());
35  } else {
36  auto strm = as_stream();
37  size_t i = 0;
38  char c;
39  while (strm.get(c)) {
40  ++i;
41  }
42 
43  set_escaped_size(i);
44  }
45  }
46 
47  } else if (source().is_stream()) {
48  if(escaped_size_unknown()) {
49  auto p = alloc().find_or_construct(
50  InputSource(source().stream()), from(), to(), restrictions());
51  set_escaped_size(p->view().size());
52  unregister_alloc_chunk_handle(p);
53  }
54 
55  }
56 
57  return escaped_size();
58  }
59 
60  inline std::shared_ptr<Input::Variant> Input::Variant::slice(
61  size_t from, size_t to = npos) const
62  {
63  size_t new_from = this->from() + from;
64  size_t new_to;
65  if (to == npos) {
66  new_to = npos;
67  } else {
68  new_to = this->from() + to;
69  }
70 
71  return std::shared_ptr<Variant>(new Variant(*this, new_from, new_to));
72  }
73 
74  inline std::shared_ptr<Input::Variant> Input::Variant::restrict(
75  const InputRestrictions& rest) const
76  {
77  return std::shared_ptr<Variant>(new Variant(*this, restrictions() | rest));
78  }
79 
80 }}
Contains the text compression and encoding framework.
Definition: namespaces.hpp:11