senf::VariantParser< AuxPolicy, Parsers > Class Template Reference
[Collection parsers]

Variant parser. More...

#include <senf/Packets/VariantParser.hh>

Inheritance diagram for senf::VariantParser< AuxPolicy, Parsers >:
Inheritance graph
[legend]

List of all members.


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.

typedef senf::VariantParser<
    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 80 of file VariantParser.hh.


Public Member Functions

unsigned  variant () const
  Get current variant.
template<unsigned N>
boost::mpl::at< parsers,
boost::mpl::int_< N > >::type 
get () const
  Access sub-parser.
template<unsigned N>
void  init ()
  Re-initialize field.

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 ()

Constructor & Destructor Documentation

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

Definition at line 40 of file VariantParser.cti.

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

Definition at line 46 of file VariantParser.cti.


Member Function Documentation

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

Definition at line 52 of file VariantParser.cti.

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

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

Definition at line 79 of file VariantParser.cti.

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

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

Definition at line 36 of file VariantParser.ct.

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

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)

Definition at line 68 of file VariantParser.cti.


Member Data Documentation

template<class AuxPolicy, class Parsers>
const size_type senf::VariantParser< AuxPolicy, Parsers >::init_bytes
[static]

Initial value:

 senf::init_bytes<
            typename boost::mpl::at<parsers, boost::mpl::int_<0> >::type>::value
                + AuxPolicy::aux_bytes

Definition at line 95 of file VariantParser.hh.


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