tudocomp
– The TU Dortmund Compression Framework
tdc::ConstGenericView< T > Class Template Reference

A const view into a slice of memory. More...

#include <GenericConstView.hpp>

Inheritance diagram for tdc::ConstGenericView< T >:
tdc::GenericViewBase< T, P > tdc::io::InputView

Public Types

using value_type = typename Super::value_type
 
using const_reference = typename Super::const_reference
 
using const_pointer = typename Super::const_pointer
 
using const_iterator = typename Super::const_iterator
 
using const_reverse_iterator = typename Super::const_reverse_iterator
 
using difference_type = typename Super::difference_type
 
using size_type = typename Super::size_type
 

Public Member Functions

 ConstGenericView ()
 Construct a empty View. More...
 
 ConstGenericView (const T *data, size_t len)
 Construct a View pointing at len elements starting from data More...
 
 ConstGenericView (const ConstGenericView &other)
 Construct a View as a copy of other More...
 
 ConstGenericView (const GenericView< T > &other)
 Construct a View as a copy of other More...
 
 ConstGenericView (const std::vector< T > &other)
 Construct a View pointing at the contents of a vector. More...
 
template<size_t N>
 ConstGenericView (const std::array< T, N > &other)
 Construct a View pointing at the contents of a array. More...
 
 operator std::vector< T > () const
 Construct a vector with the contents of this View. More...
 
const_iterator begin () const
 Begin of iterator. More...
 
const_iterator end () const
 End of iterator. More...
 
const_reverse_iterator rbegin () const
 Begin of reverse iterator. More...
 
const_reverse_iterator rend () const
 End of reverse iterator. More...
 
const_iterator cbegin () const
 Begin of const iterator. More...
 
const_iterator cend () const
 End of const iterator. More...
 
const_reverse_iterator crbegin () const
 Begin of const reverse iterator. More...
 
const_reverse_iterator crend () const
 End of const reverse iterator. More...
 
size_type size () const
 Returns size of the View. More...
 
size_type max_size () const
 Returns max size of the View. Always the same as size() More...
 
bool empty () const
 Returns true if empty. More...
 
const_reference operator[] (size_type pos) const
 Access the element at pos More...
 
const_reference at (size_type pos) const
 Access the element at pos More...
 
const_reference front () const
 Access the first element. More...
 
const_reference back () const
 Access the last element. More...
 
const value_typedata () const noexcept
 The backing memory location. More...
 
void pop_back ()
 Remove the last element from the View. More...
 
void pop_front ()
 Remove the first element from the View. More...
 
void swap (ConstGenericView &other)
 Swap two Views. More...
 
void clear ()
 Sets the size to 0. More...
 
ConstGenericView substr (size_type pos, size_type len=npos) const
 Construct a new View that is a sub view into the current one. More...
 
ConstGenericView slice (size_type from, size_type to=npos) const
 Construct a new View that is a sub view into the current one. More...
 
void remove_prefix (size_type n)
 Removes the first n elements from the View. More...
 
void remove_suffix (size_type n)
 Removes the last n elements from the View. More...
 
bool starts_with (const T &other) const
 Returns true if the View starts with the literal other More...
 
bool starts_with (const ConstGenericView< T > &other) const
 Returns true if the View starts with the sequence of literals contained in other. More...
 
bool ends_with (const T &other) const
 Returns true if the View ends with the literal other More...
 
bool ends_with (const ConstGenericView< T > &other) const
 Returns true if the View ends with the sequence of literals contained in other. More...
 

Static Public Attributes

static const size_type npos = Super::npos
 Sentinel value indicating a index at the end of the view. More...
 

Friends

class GenericView< T >
 
template<class U >
void swap (ConstGenericView< U > &lhs, ConstGenericView< U > &rhs)
 
template<typename U >
bool operator== (const ConstGenericView< U > &lhs, const ConstGenericView< U > &rhs)
 
template<typename U >
bool operator!= (const ConstGenericView< U > &lhs, const ConstGenericView< U > &rhs)
 
template<typename U >
bool operator< (const ConstGenericView< U > &lhs, const ConstGenericView< U > &rhs)
 
template<typename U >
bool operator<= (const ConstGenericView< U > &lhs, const ConstGenericView< U > &rhs)
 
template<typename U >
bool operator> (const ConstGenericView< U > &lhs, const ConstGenericView< U > &rhs)
 
template<typename U >
bool operator>= (const ConstGenericView< U > &lhs, const ConstGenericView< U > &rhs)
 

Detailed Description

template<class T>
class tdc::ConstGenericView< T >

A const view into a slice of memory.

This is an abstraction around a const pointer to T and a size, and represents N elements consecutive in memory.

Creating/Copying/Modifying a View will not copy any of the data it points at. Its API mostly mirrors that of a std::vector<T>.

Definition at line 33 of file GenericConstView.hpp.

Member Typedef Documentation

◆ const_iterator

template<class T>
using tdc::ConstGenericView< T >::const_iterator = typename Super::const_iterator

Definition at line 48 of file GenericConstView.hpp.

◆ const_pointer

template<class T>
using tdc::ConstGenericView< T >::const_pointer = typename Super::const_pointer

Definition at line 47 of file GenericConstView.hpp.

◆ const_reference

template<class T>
using tdc::ConstGenericView< T >::const_reference = typename Super::const_reference

Definition at line 46 of file GenericConstView.hpp.

◆ const_reverse_iterator

Definition at line 49 of file GenericConstView.hpp.

◆ difference_type

template<class T>
using tdc::ConstGenericView< T >::difference_type = typename Super::difference_type

Definition at line 50 of file GenericConstView.hpp.

◆ size_type

template<class T>
using tdc::ConstGenericView< T >::size_type = typename Super::size_type

Definition at line 51 of file GenericConstView.hpp.

◆ value_type

template<class T>
using tdc::ConstGenericView< T >::value_type = typename Super::value_type

Definition at line 45 of file GenericConstView.hpp.

Constructor & Destructor Documentation

◆ ConstGenericView() [1/6]

template<class T>
tdc::ConstGenericView< T >::ConstGenericView ( )
inline

Construct a empty View.

Definition at line 57 of file GenericConstView.hpp.

◆ ConstGenericView() [2/6]

template<class T>
tdc::ConstGenericView< T >::ConstGenericView ( const T *  data,
size_t  len 
)
inline

Construct a View pointing at len elements starting from data

Definition at line 61 of file GenericConstView.hpp.

◆ ConstGenericView() [3/6]

template<class T>
tdc::ConstGenericView< T >::ConstGenericView ( const ConstGenericView< T > &  other)
inline

Construct a View as a copy of other

Definition at line 65 of file GenericConstView.hpp.

◆ ConstGenericView() [4/6]

template<class T>
tdc::ConstGenericView< T >::ConstGenericView ( const GenericView< T > &  other)
inline

Construct a View as a copy of other

Definition at line 69 of file GenericConstView.hpp.

◆ ConstGenericView() [5/6]

template<class T>
tdc::ConstGenericView< T >::ConstGenericView ( const std::vector< T > &  other)
inline

Construct a View pointing at the contents of a vector.

Definition at line 73 of file GenericConstView.hpp.

◆ ConstGenericView() [6/6]

template<class T>
template<size_t N>
tdc::ConstGenericView< T >::ConstGenericView ( const std::array< T, N > &  other)
inline

Construct a View pointing at the contents of a array.

Definition at line 78 of file GenericConstView.hpp.

Member Function Documentation

◆ at()

template<class T>
const_reference tdc::ConstGenericView< T >::at ( size_type  pos) const
inline

Access the element at pos

This method is always bounds checked

Definition at line 151 of file GenericConstView.hpp.

◆ back()

template<class T>
const_reference tdc::ConstGenericView< T >::back ( ) const
inline

Access the last element.

Definition at line 161 of file GenericConstView.hpp.

◆ begin()

template<class T>
const_iterator tdc::ConstGenericView< T >::begin ( ) const
inline

Begin of iterator.

Definition at line 87 of file GenericConstView.hpp.

◆ cbegin()

template<class T>
const_iterator tdc::ConstGenericView< T >::cbegin ( ) const
inline

Begin of const iterator.

Definition at line 107 of file GenericConstView.hpp.

◆ cend()

template<class T>
const_iterator tdc::ConstGenericView< T >::cend ( ) const
inline

End of const iterator.

Definition at line 112 of file GenericConstView.hpp.

◆ clear()

template<class T>
void tdc::ConstGenericView< T >::clear ( )
inline

Sets the size to 0.

Definition at line 186 of file GenericConstView.hpp.

◆ crbegin()

template<class T>
const_reverse_iterator tdc::ConstGenericView< T >::crbegin ( ) const
inline

Begin of const reverse iterator.

Definition at line 117 of file GenericConstView.hpp.

◆ crend()

template<class T>
const_reverse_iterator tdc::ConstGenericView< T >::crend ( ) const
inline

End of const reverse iterator.

Definition at line 122 of file GenericConstView.hpp.

◆ data()

template<class T>
const value_type* tdc::ConstGenericView< T >::data ( ) const
inlinenoexcept

The backing memory location.

Definition at line 166 of file GenericConstView.hpp.

◆ empty()

template<class T>
bool tdc::ConstGenericView< T >::empty ( ) const
inline

Returns true if empty.

Definition at line 137 of file GenericConstView.hpp.

◆ end()

template<class T>
const_iterator tdc::ConstGenericView< T >::end ( ) const
inline

End of iterator.

Definition at line 92 of file GenericConstView.hpp.

◆ ends_with() [1/2]

template<class T>
bool tdc::ConstGenericView< T >::ends_with ( const T &  other) const
inline

Returns true if the View ends with the literal other

Definition at line 244 of file GenericConstView.hpp.

◆ ends_with() [2/2]

template<class T>
bool tdc::ConstGenericView< T >::ends_with ( const ConstGenericView< T > &  other) const
inline

Returns true if the View ends with the sequence of literals contained in other.

Definition at line 250 of file GenericConstView.hpp.

◆ front()

template<class T>
const_reference tdc::ConstGenericView< T >::front ( ) const
inline

Access the first element.

Definition at line 156 of file GenericConstView.hpp.

◆ max_size()

template<class T>
size_type tdc::ConstGenericView< T >::max_size ( ) const
inline

Returns max size of the View. Always the same as size()

Definition at line 132 of file GenericConstView.hpp.

◆ operator std::vector< T >()

template<class T>
tdc::ConstGenericView< T >::operator std::vector< T > ( ) const
inline

Construct a vector with the contents of this View.

Definition at line 82 of file GenericConstView.hpp.

◆ operator[]()

template<class T>
const_reference tdc::ConstGenericView< T >::operator[] ( size_type  pos) const
inline

Access the element at pos

This method is bounds checked in debug builds

Definition at line 144 of file GenericConstView.hpp.

◆ pop_back()

template<class T>
void tdc::ConstGenericView< T >::pop_back ( )
inline

Remove the last element from the View.

Definition at line 171 of file GenericConstView.hpp.

◆ pop_front()

template<class T>
void tdc::ConstGenericView< T >::pop_front ( )
inline

Remove the first element from the View.

Definition at line 176 of file GenericConstView.hpp.

◆ rbegin()

template<class T>
const_reverse_iterator tdc::ConstGenericView< T >::rbegin ( ) const
inline

Begin of reverse iterator.

Definition at line 97 of file GenericConstView.hpp.

◆ remove_prefix()

template<class T>
void tdc::ConstGenericView< T >::remove_prefix ( size_type  n)
inline

Removes the first n elements from the View.

Definition at line 223 of file GenericConstView.hpp.

◆ remove_suffix()

template<class T>
void tdc::ConstGenericView< T >::remove_suffix ( size_type  n)
inline

Removes the last n elements from the View.

Definition at line 228 of file GenericConstView.hpp.

◆ rend()

template<class T>
const_reverse_iterator tdc::ConstGenericView< T >::rend ( ) const
inline

End of reverse iterator.

Definition at line 102 of file GenericConstView.hpp.

◆ size()

template<class T>
size_type tdc::ConstGenericView< T >::size ( ) const
inline

Returns size of the View.

Definition at line 127 of file GenericConstView.hpp.

◆ slice()

template<class T>
ConstGenericView tdc::ConstGenericView< T >::slice ( size_type  from,
size_type  to = npos 
) const
inline

Construct a new View that is a sub view into the current one.

The returned view will be a "from-to" slice, and cover the bytes starting at from and ending just before to. T.slice(a,b) gives T[a..b-1]

Passing npos to to will create a slice until the end of the View

Example

View("abcd").slice(1, 3) == View("bc")

Definition at line 218 of file GenericConstView.hpp.

◆ starts_with() [1/2]

template<class T>
bool tdc::ConstGenericView< T >::starts_with ( const T &  other) const
inline

Returns true if the View starts with the literal other

Definition at line 233 of file GenericConstView.hpp.

◆ starts_with() [2/2]

template<class T>
bool tdc::ConstGenericView< T >::starts_with ( const ConstGenericView< T > &  other) const
inline

Returns true if the View starts with the sequence of literals contained in other.

Definition at line 239 of file GenericConstView.hpp.

◆ substr()

template<class T>
ConstGenericView tdc::ConstGenericView< T >::substr ( size_type  pos,
size_type  len = npos 
) const
inline

Construct a new View that is a sub view into the current one.

The returned view will be a "position-length" slice, and cover the bytes starting at pos and ending at pos + len.

Passing npos to len will create a slice until the end of the View

This method covers the same basic operation as slice(), but mirrors the semantic of std::string::substr.

Example

View("abcd").substr(1, 2) == View("bc")

Definition at line 203 of file GenericConstView.hpp.

◆ swap()

template<class T>
void tdc::ConstGenericView< T >::swap ( ConstGenericView< T > &  other)
inline

Swap two Views.

Definition at line 181 of file GenericConstView.hpp.

Friends And Related Function Documentation

◆ GenericView< T >

template<class T>
friend class GenericView< T >
friend

Definition at line 36 of file GenericConstView.hpp.

◆ operator!=

template<class T>
template<typename U >
bool operator!= ( const ConstGenericView< U > &  lhs,
const ConstGenericView< U > &  rhs 
)
friend

◆ operator<

template<class T>
template<typename U >
bool operator< ( const ConstGenericView< U > &  lhs,
const ConstGenericView< U > &  rhs 
)
friend

◆ operator<=

template<class T>
template<typename U >
bool operator<= ( const ConstGenericView< U > &  lhs,
const ConstGenericView< U > &  rhs 
)
friend

◆ operator==

template<class T>
template<typename U >
bool operator== ( const ConstGenericView< U > &  lhs,
const ConstGenericView< U > &  rhs 
)
friend

◆ operator>

template<class T>
template<typename U >
bool operator> ( const ConstGenericView< U > &  lhs,
const ConstGenericView< U > &  rhs 
)
friend

◆ operator>=

template<class T>
template<typename U >
bool operator>= ( const ConstGenericView< U > &  lhs,
const ConstGenericView< U > &  rhs 
)
friend

◆ swap

template<class T>
template<class U >
void swap ( ConstGenericView< U > &  lhs,
ConstGenericView< U > &  rhs 
)
friend

Member Data Documentation

◆ npos

template<class T>
const size_type tdc::ConstGenericView< T >::npos = Super::npos
static

Sentinel value indicating a index at the end of the view.

Definition at line 54 of file GenericConstView.hpp.


The documentation for this class was generated from the following file: