P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::Util::IteratorEnumerator< Iter > Class Template Reference

A generic iterator returning elements of type T. More...

#include <enumerator.h>

Inheritance diagram for P4::Util::IteratorEnumerator< Iter >:
[legend]

Public Member Functions

 IteratorEnumerator (Iter begin, Iter end, const char *name)
 
std::iterator_traits< Iter >::value_type getCurrent () const
 Get current element in the collection.
 
bool moveNext ()
 
std::string toString () const
 
- Public Member Functions inherited from P4::Util::Enumerator< std::iterator_traits< Iter >::value_type >
bool any ()
 True if the enumerator has at least one element.
 
Enumerator< S > * as ()
 Cast to an enumerator of S objects.
 
EnumeratorHandle< std::iterator_traits< Iter >::value_type > begin ()
 
virtual Enumerator< std::iterator_traits< Iter >::value_type > * concat (Enumerator< std::iterator_traits< Iter >::value_type > *other)
 Append all elements of other after all elements of this.
 
uint64_t count ()
 Enumerate all elements and return the count.
 
EnumeratorHandle< std::iterator_traits< Iter >::value_type > end ()
 
Enumerator< std::invoke_result_t< Mapper, std::iterator_traits< Iter >::value_type > > * map (Mapper map)
 Apply specified function to all elements of this enumerator.
 
std::iterator_traits< Iter >::value_type next ()
 Next element; throws if there are no elements.
 
std::iterator_traits< Iter >::value_type nextOrDefault ()
 Next element, or the default value if none exists.
 
virtual void reset ()
 Move back to the beginning of the collection.
 
std::iterator_traits< Iter >::value_type single ()
 The only next element; throws if the enumerator does not have exactly 1 element.
 
std::iterator_traits< Iter >::value_type singleOrDefault ()
 
const char * stateName () const
 
std::vector< std::iterator_traits< Iter >::value_type > toVector ()
 
Enumerator< std::iterator_traits< Iter >::value_type > * where (Filter filter)
 Return an enumerator returning all elements that pass the filter.
 

Protected Attributes

Iter begin
 
Iter current
 
Iter end
 
const char * name
 
- Protected Attributes inherited from P4::Util::Enumerator< std::iterator_traits< Iter >::value_type >
EnumeratorState state
 

Friends

class Enumerator< typename std::iterator_traits< Iter >::value_type >
 

Additional Inherited Members

- Public Types inherited from P4::Util::Enumerator< std::iterator_traits< Iter >::value_type >
using value_type
 
- Static Public Member Functions inherited from P4::Util::Enumerator< std::iterator_traits< Iter >::value_type >
static Enumerator< std::iterator_traits< Iter >::value_type > * concatAll (Enumerator< Enumerator< std::iterator_traits< Iter >::value_type > * > *inputs)
 Concatenate all these collections into a single one.
 
static Enumerator< typename Container::value_type > * createEnumerator (const Container &data)
 
static Enumerator< typename Iter::value_type > * createEnumerator (Iter begin, Iter end)
 
static Enumerator< typename Iter::value_type > * createEnumerator (iterator_range< Iter > range)
 
static Enumerator< std::iterator_traits< Iter >::value_type > * emptyEnumerator ()
 
- Static Protected Attributes inherited from P4::Util::Enumerator< std::iterator_traits< Iter >::value_type >
static std::vector< std::iterator_traits< Iter >::value_type > emptyVector
 

Detailed Description

template<typename Iter>
class P4::Util::IteratorEnumerator< Iter >

A generic iterator returning elements of type T.

We have to be careful never to invoke getCurrent more than once on each element of the input iterators, since it could have side-effects

Member Function Documentation

◆ getCurrent()

template<typename Iter >
std::iterator_traits< Iter >::value_type P4::Util::IteratorEnumerator< Iter >::getCurrent ( ) const
inlinevirtual

Get current element in the collection.

Implements P4::Util::Enumerator< std::iterator_traits< Iter >::value_type >.

◆ moveNext()

template<typename Iter >
bool P4::Util::IteratorEnumerator< Iter >::moveNext ( )
inlinevirtual

Move to next element in the collection; return false if the next element does not exist

Implements P4::Util::Enumerator< std::iterator_traits< Iter >::value_type >.