senf::VariantParser< AuxPolicy, Parsers > Class Template Reference

Variant parser. More...

#include <senf/Packets/VariantParser.hh>

Inheritance diagram for senf::VariantParser< AuxPolicy, Parsers >:

Public Member Functions

unsigned variant () const
 Get current variant. More...
 
template<unsigned N>
boost::mpl::at< parsers, boost::mpl::int_< N > >::type get () const
 Access sub-parser. More...
 
template<unsigned N>
void init ()
 Re-initialize field. More...
 
- Public Member Functions inherited from senf::PacketParserBase
data_iterator i () const
 Return beginning of data to parse. More...
 
data_iterator i (size_type offset) const
 Return iterator offset bytes from the start. More...
 
state_type state () const
 Return state of this parser. More...
 
PacketDatadata () const
 Access the packets raw data container. More...
 
void init () const
 Default implementation. More...
 

Parser interface

static const size_type init_bytes
 
 VariantParser (data_iterator i, state_type s)
 
 VariantParser (AuxPolicy policy, data_iterator i, state_type s)
 
size_type bytes () const
 
void init ()
 

Additional Inherited Members

- Public Types inherited from senf::PacketParserBase
typedef detail::packet::iterator data_iterator
 Raw data iterator type. More...
 
typedef detail::packet::size_type size_type
 Unsigned integral type. More...
 
typedef detail::packet::difference_type difference_type
 Signed integral type. More...
 
typedef detail::packet::byte byte
 Unsigned 8bit value, the raw value type. More...
 
typedef PacketDatastate_type
 Type of the 'state' parameter. More...
 
typedef PacketParserBase parser_base_type
 Base type of the next parser. More...
 
- Protected Member Functions inherited from senf::PacketParserBase
ParserProtector protect () const
 
 PacketParserBase (data_iterator i, state_type s)
 Standard constructor. More...
 
 PacketParserBase (data_iterator i, state_type s, size_type size)
 Size checking constructor. More...
 
bool check (size_type size) const
 Check size of data container. More...
 
void validate (size_type size) const
 Validate size of data container. More...
 
template<class Parser >
Parser parse (data_iterator i) const
 Create sub-parser. More...
 
template<class Parser , class Arg >
Parser parse (Arg const &arg, data_iterator i) const
 Create sub-parser. More...
 
template<class Parser >
Parser parse (size_type n) const
 Create sub-parser. More...
 
template<class Parser , class Arg >
Parser parse (Arg const &arg, size_type n) const
 Create sub-parser. More...
 
void defaultInit () const
 Default implementation. More...
 
Packet packet () const
 Get packet this parser is parsing from. More...
 
void resize (size_type oldSize, size_type newSize)
 Resize data container. More...
 

Detailed Description

template<class AuxPolicy, class Parsers>
class senf::VariantParser< AuxPolicy, Parsers >

Variant parser.

This is not really a collection parser (it does not provide a collection interface). However, it is not a composite parser or value parser either.

A variant parser will parse any number of sub-parsers discriminated by an arbitrary, policy defined condition. This is the parser to use, if the type and/or number of fields of a packet change depending on some condition.

MyAuxPolicy,
senf::mpl::vector<senf::VoidPacketParser, TypeAParser, TypeBParser> > MyVariantParser;

This typedef defines a variant parser choosing one of three sub parsers. senf::VoidPacketParser is an empty parser, it effectively makes this parser optional.

When creating a new packet containing a variant parser, the variant parser will always be initialized to the first sub-parser.

See also
ExampleAuxPolicy on how to implement the AuxPolicy
SENF_PARSER_VARIANT() on how to integrate the parser into another parser

Definition at line 71 of file VariantParser.hh.

Constructor & Destructor Documentation

◆ VariantParser() [1/2]

template<class AuxPolicy , class Parsers >
senf::VariantParser< AuxPolicy, Parsers >::VariantParser ( data_iterator  i,
state_type  s 
)

◆ VariantParser() [2/2]

template<class AuxPolicy , class Parsers >
senf::VariantParser< AuxPolicy, Parsers >::VariantParser ( AuxPolicy  policy,
data_iterator  i,
state_type  s 
)

Member Function Documentation

◆ bytes()

template<class AuxPolicy , class Parsers >
size_type senf::VariantParser< AuxPolicy, Parsers >::bytes ( ) const

◆ get()

template<class AuxPolicy , class Parsers >
template<unsigned N>
boost::mpl::at< parsers, boost::mpl::int_<N> >::type senf::VariantParser< AuxPolicy, Parsers >::get ( ) const

Access sub-parser.

This call will return the sub-parser at index N. This call will fail, if the currently active variant() is not N.

Precondition
variant() == N
Returns
sub-parser at index N

◆ init() [1/2]

template<class AuxPolicy , class Parsers >
void senf::VariantParser< AuxPolicy, Parsers >::init ( )

◆ init() [2/2]

template<class AuxPolicy , class Parsers >
template<unsigned N>
void senf::VariantParser< AuxPolicy, Parsers >::init ( )

Re-initialize field.

This will reinitialize the field to the variant sub-parser at index N changing the currently selected variant.

Postcondition
variant() == N

◆ variant()

template<class AuxPolicy , class Parsers >
unsigned senf::VariantParser< AuxPolicy, Parsers >::variant ( ) const

Get current variant.

Get the currently selected variant index. The returned number directly indexes the list of sub parsers.

Returns
Index of currently selected variant. Integer in the range from 0 to (number-of-sub-parsers - 1)

Member Data Documentation

◆ init_bytes

template<class AuxPolicy , class Parsers >
const size_type senf::VariantParser< AuxPolicy, Parsers >::init_bytes
static
Initial value:
typename boost::mpl::at<parsers, boost::mpl::int_<0> >::type>::value
+ AuxPolicy::aux_bytes

Definition at line 86 of file VariantParser.hh.


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