tudocomp
– The TU Dortmund Compression Framework
GenericConstU8View.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <fstream>
7 #include <iostream>
8 #include <memory>
9 #include <sstream>
10 #include <string>
11 #include <type_traits>
12 #include <utility>
13 #include <iomanip>
14 #include <cstring>
15 #include <glog/logging.h>
16 #include <functional>
17 
20 
21 namespace tdc {
22 
30 template<>
31 class ConstGenericView<uliteral_t>: GenericViewBase<uliteral_t, const uliteral_t*> {
33  inline ConstGenericView(const Super& other): Super::GenericViewBase(other) {}
34  friend class GenericView<uliteral_t>;
35 
36  using Super::op_eq;
37  using Super::op_not_eq;
38  using Super::op_greater;
39  using Super::op_greater_eq;
40  using Super::op_less;
41  using Super::op_less_eq;
42 public:
43  using value_type = typename Super::value_type;
49  using size_type = typename Super::size_type;
50 
52  static const size_type npos = Super::npos;
53 
55  inline ConstGenericView():
56  Super::GenericViewBase() {}
57 
59  inline ConstGenericView(const uliteral_t* data, size_t len):
60  Super::GenericViewBase(data, len) {}
61 
63  inline ConstGenericView(const ConstGenericView& other):
64  Super::GenericViewBase(other) {}
65 
68  ConstGenericView(other.data(), other.size()) {}
69 
71  inline ConstGenericView(const std::vector<uliteral_t>& other):
72  Super::GenericViewBase(other.data(), other.size()) {}
73 
75  template<size_t N>
76  inline ConstGenericView(const std::array<uliteral_t, N>& other):
77  Super::GenericViewBase(other.data(), other.size()) {}
78 
80  inline operator std::vector<uliteral_t>() const {
81  return Super::operator std::vector<uliteral_t>();
82  }
83 
85  inline const_iterator begin() const {
86  return Super::begin();
87  }
88 
90  inline const_iterator end() const {
91  return Super::end();
92  }
93 
95  inline const_reverse_iterator rbegin() const {
96  return Super::rbegin();
97  }
98 
100  inline const_reverse_iterator rend() const {
101  return Super::rend();
102  }
103 
105  inline const_iterator cbegin() const {
106  return Super::cbegin();
107  }
108 
110  inline const_iterator cend() const {
111  return Super::cend();
112  }
113 
116  return Super::crbegin();
117  }
118 
120  inline const_reverse_iterator crend() const {
121  return Super::crend();
122  }
123 
125  inline size_type size() const {
126  return Super::size();
127  }
128 
130  inline size_type max_size() const {
131  return Super::max_size();
132  }
133 
135  inline bool empty() const {
136  return Super::empty();
137  }
138 
143  return Super::operator[](pos);
144  }
145 
149  inline const_reference at(size_type pos) const {
150  return Super::at(pos);
151  }
152 
154  inline const_reference front() const {
155  return Super::front();
156  }
157 
159  inline const_reference back() const {
160  return Super::back();
161  }
162 
164  inline const value_type* data() const noexcept {
165  return Super::data();
166  }
167 
169  inline void pop_back() {
170  Super::pop_back();
171  }
172 
174  inline void pop_front() {
175  Super::pop_front();
176  }
177 
179  inline void swap(ConstGenericView& other) {
180  Super::swap(other);
181  }
182 
184  inline void clear() {
185  Super::clear();
186  }
187 
202  return ConstGenericView(Super::substr(pos, len));
203  }
204 
216  inline ConstGenericView slice(size_type from, size_type to = npos) const {
217  return ConstGenericView(Super::slice(from, to));
218  }
219 
221  inline void remove_prefix(size_type n) {
222  return Super::remove_prefix(n);
223  }
224 
226  inline void remove_suffix(size_type n) {
227  return Super::remove_suffix(n);
228  }
229 
231  inline bool starts_with(const uliteral_t& other) const {
232  return Super::starts_with(other);
233  }
234 
237  inline bool starts_with(const ConstGenericView<uliteral_t>& other) const {
238  return Super::starts_with(other);
239  }
240 
242  inline bool ends_with(const uliteral_t& other) const {
243  return Super::ends_with(other);
244  }
245 
248  inline bool ends_with(const ConstGenericView<uliteral_t>& other) const {
249  return Super::ends_with(other);
250  }
251 
252  template<class U>
253  friend void swap(ConstGenericView<U>& lhs, ConstGenericView<U>& rhs);
254 
255  friend bool operator==(const ConstGenericView<uliteral_t>& lhs,
256  const ConstGenericView<uliteral_t>& rhs);
257  friend bool operator!=(const ConstGenericView<uliteral_t>& lhs,
258  const ConstGenericView<uliteral_t>& rhs);
259  friend bool operator<(const ConstGenericView<uliteral_t>& lhs,
260  const ConstGenericView<uliteral_t>& rhs);
261  friend bool operator<=(const ConstGenericView<uliteral_t>& lhs,
262  const ConstGenericView<uliteral_t>& rhs);
263  friend bool operator>(const ConstGenericView<uliteral_t>& lhs,
264  const ConstGenericView<uliteral_t>& rhs);
265  friend bool operator>=(const ConstGenericView<uliteral_t>& lhs,
266  const ConstGenericView<uliteral_t>& rhs);
267 
268  // string extensions
269 
271  inline ConstGenericView(const std::string& other):
272  ConstGenericView((const uliteral_t*) other.data(), other.size()) {}
273 
277  inline ConstGenericView(const char* other):
278  ConstGenericView((const uliteral_t*) other, strlen(other)) {}
279 
281  inline ConstGenericView(const char* data, size_t len):
282  ConstGenericView((const uliteral_t*) data, len) {}
283 
285  inline operator std::string() const {
286  return std::string(cbegin(), cend());
287  }
288 
289 };
290 
292  const ConstGenericView<uliteral_t>& rhs) {
293  return ConstGenericView<uliteral_t>::op_eq(lhs, rhs);
294 }
295 
297  const ConstGenericView<uliteral_t>& rhs) {
299 }
300 
301 inline bool operator<(const ConstGenericView<uliteral_t>& lhs,
302  const ConstGenericView<uliteral_t>& rhs) {
303  return ConstGenericView<uliteral_t>::op_less(lhs, rhs);
304 }
305 
306 inline bool operator<=(const ConstGenericView<uliteral_t>& lhs,
307  const ConstGenericView<uliteral_t>& rhs) {
309 }
310 
312  const ConstGenericView<uliteral_t>& rhs) {
314 }
315 
317  const ConstGenericView<uliteral_t>& rhs) {
319 }
320 
321 inline std::ostream& operator<<(std::ostream& os,
322  const ConstGenericView<uliteral_t>& v) {
323  os.write((const char*) v.data(), v.size());
324  return os;
325 }
326 
330 inline ConstGenericView<uliteral_t> operator "" _v(const char* str, size_t n)
331 {
332  return ConstGenericView<uliteral_t>(str, n);
333 }
334 
335 }
typename Super::const_reference const_reference
bool operator!=(const ConstGenericView< uliteral_t > &lhs, const ConstGenericView< uliteral_t > &rhs)
Contains the text compression and encoding framework.
Definition: namespaces.hpp:11
void pop_front()
Remove the first element from the View.
bool ends_with(const ConstGenericView< uliteral_t > &other) const
Returns true if the View ends with the sequence of literals contained in other.
A view into a slice of memory.
ConstGenericView substr(size_type pos, size_type len=npos) const
Construct a new View that is a sub view into the current one.
void pop_back()
Remove the last element from the View.
A const view into a slice of memory.
ConstGenericView()
Construct a empty View.
uint8_t uliteral_t
Type to represent signed single literals.
Definition: def.hpp:131
const_reverse_iterator crend() const
End of const reverse iterator.
bool operator==(const ConstGenericView< uliteral_t > &lhs, const ConstGenericView< uliteral_t > &rhs)
std::ostream & operator<<(std::ostream &os, const ConstGenericView< uliteral_t > &v)
bool starts_with(const uliteral_t &other) const
Returns true if the View starts with the literal other
bool operator>=(const ConstGenericView< uliteral_t > &lhs, const ConstGenericView< uliteral_t > &rhs)
ConstGenericView(const std::vector< uliteral_t > &other)
Construct a View pointing at the contents of a vector.
size_type size() const
Returns size of the View.
bool ends_with(const uliteral_t &other) const
Returns true if the View ends with the literal other
len_compact_t len
Definition: LZSSFactors.hpp:38
size_type max_size() const
Returns max size of the View. Always the same as size()
const_reverse_iterator rend() const
End of reverse iterator.
ConstGenericView(const char *data, size_t len)
Construct a View pointing at len elements starting from data
ConstGenericView(const uliteral_t *data, size_t len)
Construct a View pointing at len elements starting from data
ConstGenericView(const char *other)
Construct a View pointing at a C-style null terminated string.
const_iterator end() const
End of iterator.
typename Super::value_type value_type
const_reference operator[](size_type pos) const
Access the element at pos
ConstGenericView(const ConstGenericView &other)
Construct a View as a copy of other
void swap(ConstGenericView &other)
Swap two Views.
void swap(IntVector< T > &lhs, IntVector< T > &rhs)
Definition: IntVector.hpp:532
const_iterator begin() const
Begin of iterator.
std::reverse_iterator< const_iterator > const_reverse_iterator
ConstGenericView slice(size_type from, size_type to=npos) const
Construct a new View that is a sub view into the current one.
const_reverse_iterator rbegin() const
Begin of reverse iterator.
ConstGenericView(const GenericView< uliteral_t > &other)
Construct a View as a copy of other
ConstGenericView(const std::array< uliteral_t, N > &other)
Construct a View pointing at the contents of a array.
len_compact_t pos
Definition: LZSSFactors.hpp:38
const_iterator cend() const
End of const iterator.
const_reference front() const
Access the first element.
typename Super::difference_type difference_type
void remove_suffix(size_type n)
Removes the last n elements from the View.
bool starts_with(const ConstGenericView< uliteral_t > &other) const
Returns true if the View starts with the sequence of literals contained in other. ...
const value_type * data() const noexcept
The backing memory location.
bool empty() const
Returns true if empty.
const_reference at(size_type pos) const
Access the element at pos
const_reverse_iterator crbegin() const
Begin of const reverse iterator.
ConstGenericView()
Construct a empty View.
ConstGenericView(const std::string &other)
Construct a View pointing at the contents of a string.
typename Super::const_pointer const_pointer
typename Super::const_iterator const_iterator
const_iterator cbegin() const
Begin of const iterator.
bool operator>(const ConstGenericView< uliteral_t > &lhs, const ConstGenericView< uliteral_t > &rhs)
typename Super::const_reverse_iterator const_reverse_iterator
A const view into a slice of memory.
const_reference back() const
Access the last element.
void remove_prefix(size_type n)
Removes the first n elements from the View.