senf::ExampleListPolicy Struct Reference

Example of a list policy. ONLY FOR EXPOSITION. More...

List of all members.


Detailed Description

Example of a list policy. ONLY FOR EXPOSITION.

This class shows the interface which must be implemented by a list policy. It is not a list policy only a declaration of the interface:

struct ExampleListPolicy
{
    // optional typedefs used to simplify all other declarations
    typedef PacketParserBase::data_iterator data_iterator;
    typedef PacketParserBase::state_type state_type;
    typedef PacketParserBase::size_type size_type;

    // mandatory typedefs in the parser and container policy
    typedef ElementParser element_type;
    typedef ListParser< ExampleListPolicy > parser_type;
    typedef ListParser_Container< ExampleListPolicy > container_type;

    // mandatory constant in parser and container policy
    static const size_type init_bytes = 0;

    // Members needed in the parser and the container policy
    size_type bytes  (data_iterator i, state_type s) const;
    size_type size   (data_iterator i, state_type s) const;
    void      init   (data_iterator i, state_type s) const;

    // Members needed only in the container policy
    void      erase  (container_type & c, data_iterator p) const;
    void      insert (container_type & c, data_iterator p) const;
    void      update (container_type const & c, data_iterator p) const;

    // Members needed in the container policy for iteration
    struct iterator_data {};

    data_iterator setBegin        (container_type const & c, iterator_data & d) const;
    data_iterator setEnd          (container_type const & c, iterator_data & d) const;
    void          setFromPosition (container_type const & c, iterator_data & d, iterator p) const;
    data_iterator next            (container_type const & c, iterator_data & d) const;
    data_iterator raw             (container_type const & c, iterator_data const & d) const;
};

The list policy must be either default constructible or copy constructible. The policy may contain arbitrary additional data members. However, their number and size should be kept at an absolute minimum, since they will increase the size of the list parser.

If necessary, you may use a different policy in the container_type. The ListPolicy must define the elements bytes(), size() and init(), the container policy needs all these and additionally needs erase() and insert(). The container policy will also need the element_type, parser_type and container_type typedefs.

See also:
ListParser

Definition at line 77 of file ListParser.dox.


Classes

struct   iterator_data

Public Types

typedef
PacketParserBase::data_iterator 
iterator
typedef
PacketParserBase::state_type 
state_type
typedef PacketParserBase::size_type  size_type
typedef unspecified  element_type
  Type of list elements.
typedef unspecified  parser_type
  List parser type.
typedef unspecified  container_type
  Type of container wrapper.

Public Member Functions

size_type  bytes (iterator i, state_type s) const
  Size of list in bytes.
size_type  size (iterator i, state_type s) const
  Number of elements in list.
void  init (iterator i, state_type s) const
  Initialize new list.
void  erase (iterator i, state_type s, iterator p) const
  Erase element from list.
void  insert (iterator i, state_type s, iterator p) const
  Insert element into list.
iterator  setBegin (iterator i, state_type s)
  Initialize iterator to begin().
iterator  setEnd (iterator i, state_type s)
  Initialize iterator to end().
void  setFromPosition (iterator i, state_type s, iterator p)
  Initialize iterator from the given raw position.
iterator  next (iterator i, state_type s)
  Advance to next element.
iterator  raw (iterator i, state_type s)
  Return raw position of element.
void  update (iterator i, state_type s)
  Called before every container access.

Static Public Attributes

static const size_type  init_bytes = 0
  Size of a new list of this type.

Member Typedef Documentation

typedef unspecified senf::ExampleListPolicy::
container_type

Type of container wrapper.

This is the container wrapper of the list, e.g. ListParser_Container<ExampleListPolicy>. The container may however use a different policy, as long as that policy is constructible from the parser policy.

Definition at line 89 of file ListParser.dox.

typedef unspecified senf::ExampleListPolicy::
element_type

Type of list elements.

This is the parser used to parse the list elements.

Definition at line 83 of file ListParser.dox.

typedef PacketParserBase::data_iterator senf::ExampleListPolicy::
iterator

Definition at line 79 of file ListParser.dox.

typedef unspecified senf::ExampleListPolicy::
parser_type

List parser type.

parser_type is the list parser used to parse a list of this type, e.g. senf::ListParser<ExampleListPolicy>.

Definition at line 85 of file ListParser.dox.

typedef PacketParserBase::size_type senf::ExampleListPolicy::
size_type

Definition at line 81 of file ListParser.dox.

typedef PacketParserBase::state_type senf::ExampleListPolicy::
state_type

Definition at line 80 of file ListParser.dox.


Member Function Documentation

size_type senf::ExampleListPolicy::
bytes ( iterator  i,
state_type  s )

Size of list in bytes.

Return the complete size of the list in bytes. Depending on the type of list, this call may need to completely traverse the list ...

void senf::ExampleListPolicy::
erase ( iterator  i,
state_type  s,
iterator  p )

Erase element from list.

Delete the list element at p from the List (i,s). When this operation is called, the element is still part of the list. This call must update the meta-data as needed. The data will be removed after this call returns.

void senf::ExampleListPolicy::
init ( iterator  i,
state_type  s )

Initialize new list.

Called after init_size bytes have been allocated to initialize the list. After init() is called, the list is traversed to initialize any members (probably none)

void senf::ExampleListPolicy::
insert ( iterator  i,
state_type  s,
iterator  p )

Insert element into list.

This is called after an element has been inserted at p into the List (i,s) to update the meta-data.

iterator senf::ExampleListPolicy::
next ( iterator  i,
state_type  s )

Advance to next element.

given an iterator to an element, go to the next element.

iterator senf::ExampleListPolicy::
raw ( iterator  i,
state_type  s )

Return raw position of element.

Given the iterator state (i,s), return the raw iterator to the datum. This will be i in almost all cases EXCEPT if a special sentinel value is used as end() value. In this case, this member must return the real position after the last element.

iterator senf::ExampleListPolicy::
setBegin ( iterator  i,
state_type  s )

Initialize iterator to begin().

Initialize the policy from the given List (i,s). Set the iterator to the beginning iterator. Return data_iterator to the first element.

Warning:
if the list is empty, the returned iterator must be the same as the one returned by setEnd.

iterator senf::ExampleListPolicy::
setEnd ( iterator  i,
state_type  s )

Initialize iterator to end().

Initialize the policy from the given List (i,s). Set the iterator to the end iterator. Return data_iterator used to mark the end of the range. This may be a special sentinel value (e.g. data().end()) if needed.

void senf::ExampleListPolicy::
setFromPosition ( iterator  i,
state_type  s,
iterator  p )

Initialize iterator from the given raw position.

Set the iterator to the Element at raw position p. This operation can potentially be very inefficient if the list needs to be traversed from the beginning until the iterator is found.

size_type senf::ExampleListPolicy::
size ( iterator  i,
state_type  s )

Number of elements in list.

Return the number of elements in the list. This operation may be quite inefficient for some lists (the list must be traversed to find that number.

void senf::ExampleListPolicy::
update ( iterator  i,
state_type  s )

Called before every container access.


Member Data Documentation

Size of a new list of this type.

Initial size which needs to be allocated to this type of list

Definition at line 96 of file ListParser.dox.


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