P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::Util::AsEnumerator< T, S > Class Template Referencefinal

Casts each element, preserving ownership when S is a smart pointer. More...

#include <enumerator.h>

Inheritance diagram for P4::Util::AsEnumerator< T, S >:
[legend]

Public Member Functions

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

Protected Attributes

EnumeratorPtr< T > input
 
- Protected Attributes inherited from P4::Util::Enumerator< S >
EnumeratorState state
 

Additional Inherited Members

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

Detailed Description

template<typename T, typename S>
class P4::Util::AsEnumerator< T, S >

Casts each element, preserving ownership when S is a smart pointer.

Member Function Documentation

◆ getCurrent()

template<typename T, typename S>
S P4::Util::AsEnumerator< T, S >::getCurrent ( ) const
inlineoverridevirtual

Get current element in the collection.

Implements P4::Util::Enumerator< S >.

◆ moveNext()

template<typename T, typename S>
bool P4::Util::AsEnumerator< T, S >::moveNext ( )
inlineoverridevirtual

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

Implements P4::Util::Enumerator< S >.

◆ reset()

template<typename T, typename S>
void P4::Util::AsEnumerator< T, S >::reset ( )
inlineoverridevirtual

Move back to the beginning of the collection.

Reimplemented from P4::Util::Enumerator< S >.