tudocomp
– The TU Dortmund Compression Framework
GenericConstView.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 
19 
20 namespace tdc {
21 
22 template<class T>
24 
32 template<class T>
33 class ConstGenericView: GenericViewBase<T, const T*> {
35  inline ConstGenericView(const Super& other): Super::GenericViewBase(other) {}
36  friend class GenericView<T>;
37 
38  using Super::op_eq;
39  using Super::op_not_eq;
40  using Super::op_greater;
41  using Super::op_greater_eq;
42  using Super::op_less;
43  using Super::op_less_eq;
44 public:
45  using value_type = typename Super::value_type;
51  using size_type = typename Super::size_type;
52 
54  static const size_type npos = Super::npos;
55 
57  inline ConstGenericView():
59 
61  inline ConstGenericView(const T* data, size_t len):
62  Super::GenericViewBase(data, len) {}
63 
65  inline ConstGenericView(const ConstGenericView& other):
66  Super::GenericViewBase(other) {}
67 
69  inline ConstGenericView(const GenericView<T>& other):
70  ConstGenericView(other.data(), other.size()) {}
71 
73  inline ConstGenericView(const std::vector<T>& other):
74  Super::GenericViewBase(other.data(), other.size()) {}
75 
77  template<size_t N>
78  inline ConstGenericView(const std::array<T, N>& other):
79  Super::GenericViewBase(other.data(), other.size()) {}
80 
82  inline operator std::vector<T>() const {
83  return Super::operator std::vector<T>();
84  }
85 
87  inline const_iterator begin() const {
88  return Super::begin();
89  }
90 
92  inline const_iterator end() const {
93  return Super::end();
94  }
95 
97  inline const_reverse_iterator rbegin() const {
98  return Super::rbegin();
99  }
100 
102  inline const_reverse_iterator rend() const {
103  return Super::rend();
104  }
105 
107  inline const_iterator cbegin() const {
108  return Super::cbegin();
109  }
110 
112  inline const_iterator cend() const {
113  return Super::cend();
114  }
115 
118  return Super::crbegin();
119  }
120 
122  inline const_reverse_iterator crend() const {
123  return Super::crend();
124  }
125 
127  inline size_type size() const {
128  return Super::size();
129  }
130 
132  inline size_type max_size() const {
133  return Super::max_size();
134  }
135 
137  inline bool empty() const {
138  return Super::empty();
139  }
140 
144  inline const_reference operator[](size_type pos) const {
145  return Super::operator[](pos);
146  }
147 
151  inline const_reference at(size_type pos) const {
152  return Super::at(pos);
153  }
154 
156  inline const_reference front() const {
157  return Super::front();
158  }
159 
161  inline const_reference back() const {
162  return Super::back();
163  }
164 
166  inline const value_type* data() const noexcept {
167  return Super::data();
168  }
169 
171  inline void pop_back() {
172  Super::pop_back();
173  }
174 
176  inline void pop_front() {
177  Super::pop_front();
178  }
179 
181  inline void swap(ConstGenericView& other) {
182  Super::swap(other);
183  }
184 
186  inline void clear() {
187  Super::clear();
188  }
189 
203  inline ConstGenericView substr(size_type pos, size_type len = npos) const {
204  return ConstGenericView(Super::substr(pos, len));
205  }
206 
218  inline ConstGenericView slice(size_type from, size_type to = npos) const {
219  return ConstGenericView(Super::slice(from, to));
220  }
221 
223  inline void remove_prefix(size_type n) {
224  return Super::remove_prefix(n);
225  }
226 
228  inline void remove_suffix(size_type n) {
229  return Super::remove_suffix(n);
230  }
231 
233  inline bool starts_with(const T& other) const {
234  return Super::starts_with(other);
235  }
236 
239  inline bool starts_with(const ConstGenericView<T>& other) const {
240  return Super::starts_with(other);
241  }
242 
244  inline bool ends_with(const T& other) const {
245  return Super::ends_with(other);
246  }
247 
250  inline bool ends_with(const ConstGenericView<T>& other) const {
251  return Super::ends_with(other);
252  }
253 
254  template<class U>
255  friend void swap(ConstGenericView<U>& lhs, ConstGenericView<U>& rhs);
256 
257  template<typename U>
258  friend bool operator==(const ConstGenericView<U>& lhs,
259  const ConstGenericView<U>& rhs);
260  template<typename U>
261  friend bool operator!=(const ConstGenericView<U>& lhs,
262  const ConstGenericView<U>& rhs);
263  template<typename U>
264  friend bool operator<(const ConstGenericView<U>& lhs,
265  const ConstGenericView<U>& rhs);
266  template<typename U>
267  friend bool operator<=(const ConstGenericView<U>& lhs,
268  const ConstGenericView<U>& rhs);
269  template<typename U>
270  friend bool operator>(const ConstGenericView<U>& lhs,
271  const ConstGenericView<U>& rhs);
272  template<typename U>
273  friend bool operator>=(const ConstGenericView<U>& lhs,
274  const ConstGenericView<U>& rhs);
275 };
276 
277 template<class T>
278 bool operator==(const ConstGenericView<T>& lhs, const ConstGenericView<T>& rhs) {
279  return ConstGenericView<T>::op_eq(lhs, rhs);
280 }
281 
282 template<class T>
283 bool operator!=(const ConstGenericView<T>& lhs, const ConstGenericView<T>& rhs) {
284  return ConstGenericView<T>::op_not_eq(lhs, rhs);
285 }
286 
287 template<class T>
288 bool operator<(const ConstGenericView<T>& lhs, const ConstGenericView<T>& rhs) {
289  return ConstGenericView<T>::op_less(lhs, rhs);
290 }
291 
292 template<class T>
293 bool operator<=(const ConstGenericView<T>& lhs, const ConstGenericView<T>& rhs) {
294  return ConstGenericView<T>::op_less_eq(lhs, rhs);
295 }
296 
297 template<class T>
298 bool operator>(const ConstGenericView<T>& lhs, const ConstGenericView<T>& rhs) {
299  return ConstGenericView<T>::op_greater(lhs, rhs);
300 }
301 
302 template<class T>
303 bool operator>=(const ConstGenericView<T>& lhs, const ConstGenericView<T>& rhs) {
304  return ConstGenericView<T>::op_greater_eq(lhs, rhs);
305 }
306 
307 template<class T>
309  using Super = typename ConstGenericView<T>::Super;
310  return swap((Super&) lhs, (Super&) rhs);
311 }
312 
313 }
314 
315 namespace std {
316  template<class T>
317  struct hash<tdc::ConstGenericView<T>>
318  {
319  size_t operator()(const tdc::ConstGenericView<T>& x) const {
320  std::size_t seed = 0;
321  std::hash<T> hasher;
322  for (const auto& v : x) {
323  seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
324  }
325  return seed;
326  }
327  };
328 }
Contains the text compression and encoding framework.
Definition: namespaces.hpp:11
const_reference front() const
Access the first element.
bool starts_with(const T &other) const
Returns true if the View starts with the literal other
bool ends_with(const T &other) const
Returns true if the View ends with the literal other
void pop_front()
Remove the first element from the View.
bool ends_with(const ConstGenericView< T > &other) const
Returns true if the View ends with the sequence of literals contained in other.
const_reverse_iterator crend() const
End of const reverse iterator.
A view into a slice of memory.
A const view into a slice of memory.
ConstGenericView()
Construct a empty View.
bool starts_with(const ConstGenericView< T > &other) const
Returns true if the View starts with the sequence of literals contained in other. ...
bool operator>(const ConstGenericView< T > &lhs, const ConstGenericView< T > &rhs)
ConstGenericView(const T *data, size_t len)
Construct a View pointing at len elements starting from data
void swap(ConstGenericView &other)
Swap two Views.
len_compact_t len
Definition: LZSSFactors.hpp:38
ConstGenericView(const std::vector< T > &other)
Construct a View pointing at the contents of a vector.
void remove_prefix(size_type n)
Removes the first n elements from the View.
const_reference at(size_type pos) const
Access the element at pos
size_type size() const
Returns size of the View.
ConstGenericView(const ConstGenericView &other)
Construct a View as a copy of other
ConstGenericView(const GenericView< T > &other)
Construct a View as a copy of other
ConstGenericView substr(size_type pos, size_type len=npos) const
Construct a new View that is a sub view into the current one.
bool operator>=(const ConstGenericView< T > &lhs, const ConstGenericView< T > &rhs)
const_reverse_iterator rbegin() const
Begin of reverse iterator.
const_reference operator[](size_type pos) const
Access the element at pos
ConstGenericView(const std::array< T, N > &other)
Construct a View pointing at the contents of a array.
const_iterator cbegin() const
Begin of const iterator.
ConstGenericView slice(size_type from, size_type to=npos) const
Construct a new View that is a sub view into the current one.
std::reverse_iterator< const_iterator > const_reverse_iterator
len_compact_t pos
Definition: LZSSFactors.hpp:38
void remove_suffix(size_type n)
Removes the last n elements from the View.
size_t operator()(const tdc::ConstGenericView< T > &x) const
void clear()
Sets the size to 0.
bool operator!=(const ConstGenericView< T > &lhs, const ConstGenericView< T > &rhs)
bool operator==(const ConstGenericView< T > &lhs, const ConstGenericView< T > &rhs)
const value_type * data() const noexcept
The backing memory location.
void pop_back()
Remove the last element from the View.
bool empty() const
Returns true if empty.
const_reverse_iterator rend() const
End of reverse iterator.
const_iterator begin() const
Begin of iterator.
const_iterator cend() const
End of const iterator.
const_iterator end() const
End of iterator.
const_reverse_iterator crbegin() const
Begin of const reverse iterator.
const_reference back() const
Access the last element.
size_type max_size() const
Returns max size of the View. Always the same as size()
void swap(ConstGenericView< T > &lhs, ConstGenericView< T > &rhs)