P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::Util::Enumerator< T > Class Template Referenceabstract

Type-erased Enumerator interface. More...

#include <enumerator.h>

Inheritance diagram for P4::Util::Enumerator< T >:
[legend]

Public Types

using value_type = T
 

Public Member Functions

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

Static Public Member Functions

static Enumerator< T > * concatAll (Enumerator< Enumerator< T > * > *inputs)
 Concatenate all these collections into a single one.
 
template<typename Container>
static Enumerator< typename Container::value_type > * createEnumerator (const Container &data)
 
template<typename Iter>
static Enumerator< typename Iter::value_type > * createEnumerator (Iter begin, Iter end)
 
template<typename Iter>
static Enumerator< typename Iter::value_type > * createEnumerator (iterator_range< Iter > range)
 
static Enumerator< T > * emptyEnumerator ()
 

Protected Attributes

EnumeratorState state = EnumeratorState::NotStarted
 

Static Protected Attributes

static std::vector< T > emptyVector
 

Friends

template<typename S>
class EnumeratorHandle
 

Detailed Description

template<class T>
class P4::Util::Enumerator< T >

Type-erased Enumerator interface.

Member Function Documentation

◆ concat()

template<typename T>
Enumerator< T > * P4::Util::Enumerator< T >::concat ( Enumerator< T > * other)
virtual

Append all elements of other after all elements of this.

Reimplemented in P4::Util::ConcatEnumerator< T >.

◆ getCurrent()

◆ moveNext()

template<class T>
virtual bool P4::Util::Enumerator< T >::moveNext ( )
pure virtual

◆ reset()

template<class T>
virtual void P4::Util::Enumerator< T >::reset ( )
inlinevirtual

◆ singleOrDefault()

template<class T>
T P4::Util::Enumerator< T >::singleOrDefault ( )
inline

The only next element or default value if none exists; throws if the enumerator does not have exactly 0 or 1 element