X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacketParser.hh;h=76b8252a5e9f303e8a44d3a1ff4351b93d8dafa4;hb=41fe0d795abca302db24e7a955df6ef15ffed722;hp=1b8c21432cfcffac5e9d79fc1ee00267c666dac5;hpb=8d2d26f114d3df0a60c5c516fcf40671b1e55558;p=senf.git diff --git a/Packets/PacketParser.hh b/Packets/PacketParser.hh index 1b8c214..76b8252 100644 --- a/Packets/PacketParser.hh +++ b/Packets/PacketParser.hh @@ -63,13 +63,13 @@ Parsers can be grouped into several categories. These categories are not all defined rigorously but are nevertheless helpful when working with the parsers: - \li Value parsers provide the lowest level parsers (e.g. senf::Parse_UInt16 which + \li \ref parserimpl_value provide the lowest level parsers (e.g. senf::Parse_UInt16 which returns an integer value). - \li Collection parsers are parsers which model a collection of sub-elements like + \li \ref parserimpl_collection are parsers which model a collection of sub-elements like senf::Parse_List or senf::Parse_Vector. - \li Composite parsers collect several fields of arbitrary type into a new + \li \ref parserimpl_composite collect several fields of arbitrary type into a new parser. Parsers defined using the \ref packetparsermacros fall under this category. - \li Packet parsers are used to define a packet type. + \li \ref parserimpl_packet are used to define a packet type. \warning Parsers are like iterators: They are invalidated whenever the size of the packet's data is changed. You should not store a parser anywhere. If you want to keep a parser @@ -118,7 +118,7 @@ You will probably only very seldom need to implement a completely new collection parser. Instead, you can rely on senf::Parse_Vector or senf::Parse_List and implement new - polcies. + policies. \subsection parserimpl_composite Composite parsers @@ -140,7 +140,8 @@ interface. These members may access the packet data in any way. You just need to ensure, that the integration into the packet-type is correct (the senf::PacketTypeMixin will by default use senf::bytes() to find the end of the header). - + +
*/ #ifndef HH_PacketParser_ @@ -158,6 +159,8 @@ ///////////////////////////////hh.p//////////////////////////////////////// namespace senf { + + class Packet; /** \brief Parser Base class @@ -291,10 +294,10 @@ namespace senf { container does not hold at least \a size bytes beginning at \a i. */ - bool check(size_type size); ///< Check size of data container + bool check(size_type size) const; ///< Check size of data container /**< \returns \c true, if the data container holds at least \a size beginning at i(), \c false otherwise. */ - void validate(size_type size); ///< Validate size of data container + void validate(size_type size) const; ///< Validate size of data container /**< \throws TruncatedPacketException if the raw data container does not hold at least \a size bytes beginning at i(). */ @@ -313,8 +316,13 @@ namespace senf { implementation. Re-implement this member in your own parsers if needed. */ + Packet packet() const; ///< Get packet this parser is parsing from + /**< \important This member should only be used from packet + parsers when access to previous or following packets is + needed e.g. for calculating checksums etc. */ + private: - data_iterator end(); + data_iterator end() const; data_iterator i_; PacketData * data_; @@ -369,6 +377,7 @@ namespace senf { # else /** \brief Generic parser copying + This operator allows to copy the values of identical parsers. This operation does \e not depend on the parsers detailed implementation, it will just replace the data bytes of the target parser with those from the source parser. This allows to easily copy around complex @@ -403,6 +412,28 @@ namespace senf { Parser operator<<(Parser target, Value const & value); # endif +# ifndef DOXYGEN + template + typename boost::enable_if_c < + boost::is_base_of::value + && ! boost::is_base_of::value, + Parser >::type + operator<<(Parser target, boost::optional const & value); +# else + /** \brief Generic parser value assignment + + This operator allows to assign a value to parsers which implement a value(\a + value) member. This special version allows to assign optional values: IF the + optional value is not set, the assignment will be skipped. + + This operator allows to use a common syntax for assigning values or parsers to a parser. + + \ingroup packetparser + */ + template + Parser operator<<(Parser target, boost::optional const & value); +# endif + /** \defgroup packetparsermacros Helper macros for defining new packet parsers To simplify the definition of simple packet parsers, several macros are provided. Before