tudocomp
– The TU Dortmund Compression Framework
tdc::io::Input Class Reference

An abstraction layer for algorithm input. More...

#include <Input.hpp>

Inheritance diagram for tdc::io::Input:
tdc::test::TestInput

Public Member Functions

 Input ()
 Constructs an empty input. More...
 
 Input (const Input &other)
 Constructs an input from another input, retaining its internal state ("cursor"). More...
 
 Input (Input &&other)
 Move constructor. More...
 
 Input (Path &&path)
 Constructs a file input reading from the file at the given path. More...
 
 Input (const string_ref &buf)
 Constructs an input reading from a string in memory. More...
 
 Input (const std::vector< uint8_t > &buf)
 Constructs an input reading from the specified byte buffer. More...
 
 Input (std::istream &stream)
 Constructs an input reading from a stream. More...
 
Inputoperator= (Input &&other)
 Move assignment operator. More...
 
Inputoperator= (const Input &other)
 Copy assignment operator. More...
 
InputView as_view () const
 Provides a view on the input that allows for random access. More...
 
InputStream as_stream () const
 Creates a stream that allows for character-wise reading of the input. More...
 
size_t size () const
 Yields the total amount of characters in the input. More...
 

Static Public Member Functions

static Input from_path (std::string path)
 Constructs a file input reading from the file at the given path. More...
 
static Input from_memory (const std::vector< uint8_t > &buf)
 Constructs a file input reading from a byte buffer. More...
 
static Input from_memory (const string_ref buf)
 Constructs a file input reading from a string in memory. More...
 

Friends

class InputStream
 
class InputStreamInternal
 
class InputView
 

Detailed Description

An abstraction layer for algorithm input.

This class serves as a generic abstraction over different sources of input: memory buffers, files or streams. It provides two ways of handling the input: streams or views. While a view allows random access on all of the input, it requires the entire input to be stored in memory. Streaming, on the other hand, is used for character-wise reading without the ability to rewind (online).

Copying or otherwise manipulating instances of this class is cheap, since this class does not contain the input data itself, only information on how to access it.

Definition at line 37 of file Input.hpp.

Constructor & Destructor Documentation

◆ Input() [1/7]

tdc::io::Input::Input ( )
inline

Constructs an empty input.

Definition at line 118 of file Input.hpp.

◆ Input() [2/7]

tdc::io::Input::Input ( const Input other)
inline

Constructs an input from another input, retaining its internal state ("cursor").

Use this in combination with streams to store a rewind point.

Parameters
otherThe input to copy.

Definition at line 127 of file Input.hpp.

◆ Input() [3/7]

tdc::io::Input::Input ( Input &&  other)
inline

Move constructor.

Definition at line 131 of file Input.hpp.

◆ Input() [4/7]

tdc::io::Input::Input ( Path &&  path)
inline

Constructs a file input reading from the file at the given path.

Parameters
pathThe path to the input file.

Definition at line 138 of file Input.hpp.

◆ Input() [5/7]

tdc::io::Input::Input ( const string_ref buf)
inline

Constructs an input reading from a string in memory.

Parameters
bufThe input string.

Definition at line 144 of file Input.hpp.

◆ Input() [6/7]

tdc::io::Input::Input ( const std::vector< uint8_t > &  buf)
inline

Constructs an input reading from the specified byte buffer.

Parameters
bufThe input byte buffer.

Definition at line 150 of file Input.hpp.

◆ Input() [7/7]

tdc::io::Input::Input ( std::istream &  stream)
inline

Constructs an input reading from a stream.

The stream will still be buffered in memory.

Parameters
streamThe input stream.

Definition at line 158 of file Input.hpp.

Member Function Documentation

◆ as_stream()

InputStream tdc::io::Input::as_stream ( ) const
inline

Creates a stream that allows for character-wise reading of the input.

This might have to allocate a copy of the data into memory depending on its source or on data restrictions placed on it.

For example, if your source is a istream it will generally have to create a copy to allow calling this method multiple times.

Returns
A character stream for the input.

Definition at line 264 of file Input.hpp.

◆ as_view()

InputView tdc::io::Input::as_view ( ) const
inline

Provides a view on the input that allows for random access.

This might have to allocate a copy of the data into memory depending on its source or on data restrictions placed on it.

For example, if your source is a istream it will generally have to create a copy.

Returns
A random access view on the input.

Definition at line 260 of file Input.hpp.

◆ from_memory() [1/2]

static Input tdc::io::Input::from_memory ( const std::vector< uint8_t > &  buf)
inlinestatic

Constructs a file input reading from a byte buffer.

Deprecated:
Use the respective constructor instead.
Parameters
bufThe input byte buffer.

Definition at line 187 of file Input.hpp.

◆ from_memory() [2/2]

static Input tdc::io::Input::from_memory ( const string_ref  buf)
inlinestatic

Constructs a file input reading from a string in memory.

Deprecated:
Use the respective constructor instead.
Parameters
bufThe input string.

Definition at line 195 of file Input.hpp.

◆ from_path()

static Input tdc::io::Input::from_path ( std::string  path)
inlinestatic

Constructs a file input reading from the file at the given path.

Deprecated:
Use the respective constructor instead.
Parameters
pathThe path to the input file.

Definition at line 179 of file Input.hpp.

◆ operator=() [1/2]

Input& tdc::io::Input::operator= ( Input &&  other)
inline

Move assignment operator.

Definition at line 162 of file Input.hpp.

◆ operator=() [2/2]

Input& tdc::io::Input::operator= ( const Input other)
inline

Copy assignment operator.

Definition at line 168 of file Input.hpp.

◆ size()

size_t tdc::io::Input::size ( ) const
inline

Yields the total amount of characters in the input.

This might have to allocate a copy of the data into memory depending on its source or on data restrictions placed on it.

For example, if your source is a istream it will generally have to create a copy to allow calling this method multiple times.

Returns
The total amount of characters in the input.

Definition at line 233 of file Input.hpp.

Friends And Related Function Documentation

◆ InputStream

friend class InputStream
friend

Definition at line 111 of file Input.hpp.

◆ InputStreamInternal

friend class InputStreamInternal
friend

Definition at line 112 of file Input.hpp.

◆ InputView

friend class InputView
friend

Definition at line 113 of file Input.hpp.


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