A toolkit for working with phylogenetic data.
v0.24.0
NewickInputIterator Class Reference

#include <genesis/tree/formats/newick/input_iterator.hpp>

Detailed Description

Iterate an input stream and parse it as Newick trees.

This class allows to iterate over an input stream, iterpreting it as Newick trees, and yielding one such tree per iteration step. This is useful for processing large files without having to keep them fully in memory.

Example:

for( auto const& t : NewickInputIterator( from_file( "/path/to/trees.newick" ))) {
    std::cout << t.node_count() << "\n";
}

Alternatively, the following also works:

auto it = NewickInputIterator( from_file( "/path/to/trees.newick" ));
while( it ) {
    Tree const& t = *it;
    std::cout << t.node_count() << "\n";
    ++it;
}

Use functions such as utils::from_file() and utils::from_string() to conveniently get an input source that can be used here.

See NewickReader for a description of the expected format. In order to change the reading behaviour, a NewickReader object can be handed over from which the settings are copied.

Definition at line 76 of file tree/formats/newick/input_iterator.hpp.

Public Member Functions

 NewickInputIterator ()
 Create a default instance, with no input. More...
 
 NewickInputIterator (std::shared_ptr< utils::BaseInputSource > source)
 Create an instance that reads from an input source, using a default NewickReader. More...
 
 NewickInputIterator (std::shared_ptr< utils::BaseInputSource > source, NewickReader const &settings)
 Create an instance that reads from an input source, using the settings of a given NewickReader. More...
 
 NewickInputIterator (self_type const &)=delete
 
 NewickInputIterator (self_type &&)=default
 
 ~NewickInputIterator ()=default
 
self_typebegin ()
 Beginning of the iterator. More...
 
Tree const & dereference () const
 
self_type end ()
 End of the iterator. More...
 
void increment ()
 
 operator bool () const
 Return true iff dereferencing is valid, i.e., iff there is a Tree available. More...
 
bool operator!= (self_type const &other) const
 
Tree const & operator* () const
 
self_typeoperator++ ()
 
Tree const * operator-> () const
 
self_typeoperator= (self_type const &)=delete
 
self_typeoperator= (self_type &&)=default
 
bool operator== (self_type const &other) const
 

Public Types

using iterator_category = std::input_iterator_tag
 
using self_type = NewickInputIterator
 

Constructor & Destructor Documentation

◆ NewickInputIterator() [1/5]

NewickInputIterator ( )
inline

Create a default instance, with no input.

Definition at line 94 of file tree/formats/newick/input_iterator.hpp.

◆ NewickInputIterator() [2/5]

NewickInputIterator ( std::shared_ptr< utils::BaseInputSource source)
inlineexplicit

Create an instance that reads from an input source, using a default NewickReader.

Definition at line 103 of file tree/formats/newick/input_iterator.hpp.

◆ NewickInputIterator() [3/5]

NewickInputIterator ( std::shared_ptr< utils::BaseInputSource source,
NewickReader const &  settings 
)
inline

Create an instance that reads from an input source, using the settings of a given NewickReader.

Definition at line 119 of file tree/formats/newick/input_iterator.hpp.

◆ ~NewickInputIterator()

~NewickInputIterator ( )
default

◆ NewickInputIterator() [4/5]

NewickInputIterator ( self_type const &  )
delete

◆ NewickInputIterator() [5/5]

NewickInputIterator ( self_type &&  )
default

Member Function Documentation

◆ begin()

self_type& begin ( )
inline

Beginning of the iterator.

This is a bit uncommon, as the iterator provides its own begin() and end() functions. We do this to allow the easy use case that is explained above.

Definition at line 190 of file tree/formats/newick/input_iterator.hpp.

◆ dereference()

Tree const& dereference ( ) const
inline

Definition at line 175 of file tree/formats/newick/input_iterator.hpp.

◆ end()

self_type end ( )
inline

End of the iterator.

Beginning of the iterator. This is a bit uncommon, as the iterator provides its own begin() and end() functions. We do this to allow the easy use case that is explained above.

Definition at line 200 of file tree/formats/newick/input_iterator.hpp.

◆ increment()

void increment ( )
inline

Definition at line 211 of file tree/formats/newick/input_iterator.hpp.

◆ operator bool()

operator bool ( ) const
inlineexplicit

Return true iff dereferencing is valid, i.e., iff there is a Tree available.

Definition at line 156 of file tree/formats/newick/input_iterator.hpp.

◆ operator!=()

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

Definition at line 148 of file tree/formats/newick/input_iterator.hpp.

◆ operator*()

Tree const& operator* ( ) const
inline

Definition at line 165 of file tree/formats/newick/input_iterator.hpp.

◆ operator++()

self_type& operator++ ( )
inline

Definition at line 205 of file tree/formats/newick/input_iterator.hpp.

◆ operator->()

Tree const* operator-> ( ) const
inline

Definition at line 170 of file tree/formats/newick/input_iterator.hpp.

◆ operator=() [1/2]

self_type& operator= ( self_type const &  )
delete

◆ operator=() [2/2]

self_type& operator= ( self_type &&  )
default

◆ operator==()

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

Definition at line 143 of file tree/formats/newick/input_iterator.hpp.

Member Typedef Documentation

◆ iterator_category

using iterator_category = std::input_iterator_tag

Definition at line 85 of file tree/formats/newick/input_iterator.hpp.

◆ self_type


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