LineReader module
Module contents
-
template<class StringT = std::string>
class LineReader Read data from a stream one line at a time.
This class is an adapter that takes a
std::istreamas input and provides an InputIterator that loops over the lines of the stream. In its current version it delegates to thegetline()function to determine when a line has ended.The behavior is meant to be the same as the Python idiom
for line in file.We do not expect you to instantiate this class directly. Instead, it shows up as part of
PointReaderwhere you put a stream in one end and get points out the other end.Public Types
-
typedef std::basic_istream<char_type, traits_type> istream_type
-
typedef LineReaderIterator iterator
-
typedef LineReaderIterator const const_iterator
Public Functions
-
inline LineReader()
Instantiate an empty line reader.
-
inline LineReader(const LineReader &other)
Copy contructor, create a reader with a copy of another
- Parameters:
other – [in] Line reader to copy from
-
inline LineReader(istream_type &stream)
Instantiate a line reader with
std::basic_istream- Parameters:
stream – [in] Stream to read lines in
-
inline virtual ~LineReader()
Destructor for a line reader.
-
inline LineReader &operator=(LineReader const &other)
Assign a LineReader to the value of another.
- Parameters:
other – [in] LineReader to assign value of
- Returns:
Stream with the new assigned value
-
inline void set_input(istream_type &stream)
Set the input for the LineReader stream to that of the given istream
- Parameters:
stream – [in] The input to use for input
-
inline istream_type &input() const
Get the input value of the stream
- Returns:
The stream input value
-
inline bool operator==(LineReader const &other) const
Check whether one stream is equal to another by comparing all the items.
Two reader are equal if all of their streams are equal.
- Parameters:
other – [in] LineReader for comparison
- Returns:
Boolean indicating equivalency
-
inline bool operator!=(LineReader const &other) const
Check whether two LineReaders are unequal.
- Parameters:
other – [in] LineReader for comparison
- Returns:
Boolean indicating equivalency
-
inline iterator begin() const
Get an iterator pointing to the beginning of the stream
- Returns:
Iterator pointing to current stream
-
inline iterator end() const
Get an iterator pointing to the end of the stream
- Returns:
Iterator pointing to end of current stream
-
inline const_iterator const_begin() const
Get an iterator pointing to the beginning of the stream
- Returns:
Iterator pointing to current stream
-
inline const_iterator const_end() const
Get an iterator pointing to the end of the stream
- Returns:
Iterator pointing to end of current stream
Private Members
-
istream_type *Stream
-
class LineReaderIterator
Line Reader iterator class
Generates a iterator that can traverse the given parent LineReader
Public Types
-
using iterator_category = std::input_iterator_tag
-
using difference_type = std::ptrdiff_t
Public Functions
-
inline LineReaderIterator()
Instantiate an empty reader iterator.
-
inline LineReaderIterator(istream_type *stream)
Copy contructor, create a line reader iterator with a copy of a
std::basic_istream
-
inline LineReaderIterator(LineReaderIterator const &other)
Copy contructor, create a line reader iterator with a copy of another.
-
inline ~LineReaderIterator()
Destructor for a line reader iterator.
-
inline LineReaderIterator &operator=(LineReaderIterator const &other)
Assign a LineReaderIterator to the value of another.
- Parameters:
other – [in] LineReaderIterator to assign value of
- Returns:
Iterator with the new assigned value
-
inline value_type const &operator*() const
Multiply an iterator.
- Returns:
Result of the multiplication
-
inline value_type *operator->() const
Get the current iterator value.
- Returns:
Current iterator value
-
inline LineReaderIterator &operator++()
Advance the iterator to the next line.
- Returns:
Pointer to the next line
-
inline LineReaderIterator &operator++(int)
Advance the iterator to the next line.
- Returns:
Pointer to the next line
-
inline bool operator==(LineReaderIterator const &other) const
Check whether one iterator is equal to another by comparing the values and streams.
Two items are equal if all of their values and streams are equal.
- Parameters:
other – [in] Iterator for comparison
- Returns:
Boolean indicating equivalency
-
inline bool operator!=(LineReaderIterator const &other) const
Check whether two iterators are unequal.
- Parameters:
other – [in] Iterator for comparison
- Returns:
Boolean indicating equivalency
-
inline value_type get_value() const
Get the stored value
This is to handle the case where the stream is NULL but there wasn’t a new line at the end of the file. In that case we return an empty value so that comparisons evaluate properly.
- Returns:
Value unless the Stream is Null, in which case we return an empty value
-
using iterator_category = std::input_iterator_tag
-
typedef std::basic_istream<char_type, traits_type> istream_type