vg
tools for working with variation graphs
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
vg::io::ProtobufIterator< T > Class Template Reference

#include <protobuf_iterator.hpp>

Public Member Functions

 ProtobufIterator (istream &in)
 Constructor. More...
 
 ProtobufIterator ()=default
 Default constructor for an end iterator. More...
 
T & operator* ()
 
const T & operator* () const
 
const ProtobufIterator< T > & operator++ ()
 In-place pre-increment to advance the iterator. More...
 
bool operator== (const ProtobufIterator< T > &other) const
 
bool operator!= (const ProtobufIterator< T > &other) const
 
bool has_current () const
 Return true if dereferencing the iterator will produce a valid value, and false otherwise. More...
 
void advance ()
 
take ()
 Take the current item, which must exist, and advance the iterator to the next one. More...
 
int64_t tell_group () const
 
bool seek_group (int64_t virtual_offset)
 

Static Public Member Functions

static pair< ProtobufIterator< T >, ProtobufIterator< T > > range (istream &in)
 Returns iterators that act like begin() and end() for a stream containing messages. More...
 
static bool parse_from_string (T &dest, const string &data)
 

Private Member Functions

void fill_value ()
 

Private Attributes

MessageIterator message_it
 Wrap a MessageIterator and just do Protobuf parsing on top of that. More...
 
value
 We always maintain a parsed version of the current message. More...
 

Detailed Description

template<typename T>
class vg::io::ProtobufIterator< T >

Refactored io::for_each function that follows the unidirectional iterator interface. Also supports seeking and telling at the group level in bgzip files. Cannot be copied, but can be moved.

Constructor & Destructor Documentation

◆ ProtobufIterator() [1/2]

template<typename T >
vg::io::ProtobufIterator< T >::ProtobufIterator ( istream &  in)

◆ ProtobufIterator() [2/2]

template<typename T >
vg::io::ProtobufIterator< T >::ProtobufIterator ( )
default

Default constructor for an end iterator.

Member Function Documentation

◆ advance()

template<typename T >
auto vg::io::ProtobufIterator< T >::advance

Advance the iterator to the next message, or the end if this was the last message. Basically the same as ++.

◆ fill_value()

template<typename T >
auto vg::io::ProtobufIterator< T >::fill_value
private

Fill in value, if message_it has a value of an appropriate tag. Scans through tag-only groups.

◆ has_current()

template<typename T >
auto vg::io::ProtobufIterator< T >::has_current

Return true if dereferencing the iterator will produce a valid value, and false otherwise.

◆ operator!=()

template<typename T >
auto vg::io::ProtobufIterator< T >::operator!= ( const ProtobufIterator< T > &  other) const

Check if two iterators are not equal. Since you can only have one on a stream, this only has two equality classes: iterators that have hit the end, and iterators that haven't.

◆ operator*() [1/2]

template<typename T >
auto vg::io::ProtobufIterator< T >::operator*

Get the current item. Caller may move it away. Only legal to call if we are not an end iterator.

◆ operator*() [2/2]

template<typename T >
const T& vg::io::ProtobufIterator< T >::operator* ( ) const

Get the current item when we are const. Only legal to call if we are not an end iterator.

◆ operator++()

template<typename T >
auto vg::io::ProtobufIterator< T >::operator++

In-place pre-increment to advance the iterator.

◆ operator==()

template<typename T >
auto vg::io::ProtobufIterator< T >::operator== ( const ProtobufIterator< T > &  other) const

Check if two iterators are equal. Since you can only have one on a stream, this only has two equality classes: iterators that have hit the end, and iterators that haven't.

◆ parse_from_string()

template<typename T >
auto vg::io::ProtobufIterator< T >::parse_from_string ( T &  dest,
const string &  data 
)
static

Parse a Protobuf message that may be very large from a string. Use this instead of ParseFromString on the message itself.

Returns the result of the parse attempt (i.e. whether it succeeded).

◆ range()

template<typename T >
auto vg::io::ProtobufIterator< T >::range ( istream &  in)
static

Returns iterators that act like begin() and end() for a stream containing messages.

◆ seek_group()

template<typename T >
auto vg::io::ProtobufIterator< T >::seek_group ( int64_t  virtual_offset)

Seek to the given virtual offset and start reading the group that is there. The next value produced will be the first value in that group (or in the next group that actually has values). If already at the start of the group at the given virtual offset, does nothing. Return false if seeking is unsupported or the seek fails.

◆ take()

template<typename T >
auto vg::io::ProtobufIterator< T >::take

Take the current item, which must exist, and advance the iterator to the next one.

◆ tell_group()

template<typename T >
auto vg::io::ProtobufIterator< T >::tell_group

Return the virtual offset of the group being currently read (i.e. the group to which the current message belongs), to seek back to. You can't seek back to the current message, just to the start of the group. Returns -1 instead if the underlying file doesn't support seek/tell. Returns the past-the-end virtual offset of the file if EOF is reached.

Member Data Documentation

◆ message_it

template<typename T >
MessageIterator vg::io::ProtobufIterator< T >::message_it
private

Wrap a MessageIterator and just do Protobuf parsing on top of that.

◆ value

template<typename T >
T vg::io::ProtobufIterator< T >::value
private

We always maintain a parsed version of the current message.


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