SkipCommentsReader module

Module contents

template<typename IteratorT>
class SkipCommentsReader

Loop over a set of lines and skip comments.

Comments in a text file are often denoted by some special character like ‘#’ as the first non-whitespace character on a line. This filter takes a stream of lines and produces a stream that omits all comment lines.

Note that we only intercept lines where the comment character is at the beginning of the line. This filter will not detect lines where you attempt to remove data at the end by putting the comment character somewhere in the middle.

We do not expect that you will instantiate this class directly. Its main purpose is to be part of the stack that makes up PointReader.

Note

Although the CommentCharacter member is a string and can have arbitrary length, we only care about the first character.

Public Types

typedef IteratorT inner_iterator_type
typedef IteratorT::value_type value_type
typedef value_type::value_type char_type
typedef SkipCommentsIterator iterator
typedef SkipCommentsIterator const const_iterator

Public Functions

inline SkipCommentsReader()

Instantiate a default SkipCommentsReader.

inline SkipCommentsReader(const SkipCommentsReader &other)

Copy contructor, create a reader with a copy of another

Parameters:

other[in] SkipCommentsReader to copy from

inline SkipCommentsReader(inner_iterator_type const &start, inner_iterator_type const &finish, std::string const &comment = "#")

Instantiate a reader with a start and finish points along with a comment delimter

Parameters:
  • start[in] Iterator to start from

  • finish[in] Iterator to end at

  • comment[in] Character signifying a comment

inline SkipCommentsReader(inner_iterator_type const &start, inner_iterator_type const &finish, int const &skip)

Instantiate a reader with a start and finish points along with number of header lines to skip

Parameters:
  • start[in] Iterator to start from

  • finish[in] Iterator to end at

  • skip[in] Number of header lines to skip

inline virtual ~SkipCommentsReader()

Destructor.

inline void set_comment_character(std::string const &c)

Specify comment character for skipping lines

A line is a comment if and only if its first non-whitespace character is the comment character (# by default). We will skip such lines entirely. We do not handle inline or trailing comments: a line will either be included in its entirety or skipped completely.

Parameters:

comment[in] Single character

inline std::string const &comment_character() const

Retrieve current value of comment character.

This function invalidates any outstanding iterators.

Returns:

Current value of comment character

inline void set_skip_n_lines(int const &skips)

Specify number of header lines to skip

In the case where headers are not delimited with a comment character we allow the user to specify how many lines are skipped at the beginning of a file.

Parameters:

skips[in] Number of lines to skip

inline int const &num_skips() const

Retrieve number of header lines to skip.

This function invalidates any outstanding iterators.

Returns:

Current value of number of lines to skip

inline SkipCommentsReader &operator=(SkipCommentsReader const &other)

Assign a SkipCommentsReader to the value of another.

Parameters:

other[in] SkipCommentsReader to assign value of

Returns:

Reader with the new assigned value

inline bool operator==(SkipCommentsReader const &other) const

Check whether one reader is equal to another by comparing all the properties.

Two readers are equal if all of their properties are equal.

Parameters:

other[in] SkipCommentsReader for comparison

Returns:

Boolean indicating equivalency

inline bool operator!=(SkipCommentsReader const &other) const

Check whether two SkipCommentsReader are unequal.

Parameters:

other[in] SkipCommentsReader for comparison

Returns:

Boolean indicating equivalency

inline void set_input_range(inner_iterator_type const &start, inner_iterator_type const &finish)

Set the beginning and the end of the input range

Parameters:
  • start[in] The iterator to use for the start of input

  • finish[in] The iterator to use for the end of input

inline iterator begin() const

Get an iterator pointing to the current sequence

Returns:

Iterator pointing to current sequence

inline iterator end() const

Get an iterator pointing past the end of the sequence

Returns:

Iterator pointing to end of sequence

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

inner_iterator_type InnerBegin
inner_iterator_type InnerEnd
std::string CommentCharacter
int NumLinesToSkip
class SkipCommentsIterator

Public Types

using iterator_category = std::input_iterator_tag
using value_type = typename inner_iterator_type::value_type
using difference_type = std::ptrdiff_t
using pointer = const typename inner_iterator_type::value_type*
using reference = const typename inner_iterator_type::value_type&
using char_type = typename inner_iterator_type::value_type::value_type

Public Functions

inline SkipCommentsIterator()

Instantiate an default SkipCommentsIterator.

inline SkipCommentsIterator(inner_iterator_type Begin, inner_iterator_type End, std::string const &Comment, int const &Skips)

Instantiate a reader with a start and finish points along with a comment delimter

Parameters:
  • Begin[in] Iterator to start from

  • End[in] Iterator to end at

  • Comment[in] Character signifying a comment

  • Number[in] of header lines to skip

inline SkipCommentsIterator(SkipCommentsIterator const &other)

Copy contructor, create a reader with a copy of another

Parameters:

other[in] SkipCommentsIterator to copy from

inline ~SkipCommentsIterator()

Destructor.

inline SkipCommentsIterator &operator=(SkipCommentsIterator const &other)

Assign a SkipCommentsIterator to the value of another.

Parameters:

other[in] SkipCommentsReader to assign value of

Returns:

Reader with the new assigned value

inline value_type const &operator*() const

Multiply an iterator.

Returns:

Result of the multiplication

inline value_type const *operator->() const

Get the current iterator object.

Returns:

Current iterator

inline SkipCommentsIterator &operator++()

Advance the iterator to the next position in the sequence.

Returns:

Pointer to the next iterator in the sequence

inline SkipCommentsIterator &operator++(int)

Advance the iterator to the next position in the sequence.

Returns:

Pointer to the next iterator in the sequence

inline bool operator==(SkipCommentsIterator const &other) const

Check whether one SkipCommentsReader is equal to another by comparing all the properties.

Two SkipCommentsReaders are equal if all of their properties are equal.

Parameters:

other[in] SkipCommentsReader for comparison

Returns:

Boolean indicating equivalency

inline bool operator!=(SkipCommentsIterator const &other) const

Check whether two iterators are unequal.

Parameters:

other[in] Iterator for comparison

Returns:

Boolean indicating equivalency

Private Functions

inline void _advance_to_valid_string()
inline bool _string_is_comment(value_type const &test_string) const

Private Members

inner_iterator_type InnerIterator
inner_iterator_type InnerEnd
std::string CommentCharacter
int NumLinesToSkip