small documentation fixes
[senf.git] / Packets / ParseHelpers.hh
index bc22591..31fa8b5 100644 (file)
@@ -1,8 +1,8 @@
 // $Id$
 //
-// Copyright (C) 2007 
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
 //     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
@@ -47,7 +47,7 @@
     the ethernet packet in <tt>DefaultBundle/EthernetPacket.hh</tt>)
 
     \code
-    struct Parse_EthVLan : public PacketParserBase
+    struct EthVLanPacketParser : public PacketParserBase
     {
     #   include SENF_FIXED_PARSER()
 
@@ -55,9 +55,9 @@
         SENF_PARSER_BITFIELD( cfi,       1, bool     );
         SENF_PARSER_BITFIELD( vlanId,   12, unsigned );
 
-        SENF_PARSER_FIELD( type, Parse_UInt16 );
+        SENF_PARSER_FIELD( type, UInt16Parser );
 
-        SENF_PARSER_FINALIZE(Parse_EthVLan);
+        SENF_PARSER_FINALIZE(EthVLanPacketParser);
     };
     \endcode
 
     {
     #   include SENF_FIXED_PARSER()
 
-        SENF_PARSER_FIELD    ( table_id            , Parse_UInt8   );
+        SENF_PARSER_FIELD    ( table_id            , UInt8Parser   );
         
         SENF_PARSER_BITFIELD ( ssi                 ,  1 , bool     );
         SENF_PARSER_BITFIELD ( private_indicator   ,  1 , bool     );
         SENF_PARSER_SKIP_BITS( 2 );
         SENF_PARSER_BITFIELD ( sec_length          , 12 , unsigned );
         
-        SENF_PARSER_FIELD    ( table_id_extension  , Parse_UInt16  );
+        SENF_PARSER_FIELD    ( table_id_extension  , UInt16Parser  );
         
         SENF_PARSER_FINALIZE( Parse_DSMCCSection );
     };
 
         SENF_PARSER_INHERIT( Parse_DSMCCSection );
 
-        SENF_PARSER_FIELD    ( mac_addr_4          , Parse_UInt8   );
-        SENF_PARSER_FIELD    ( mac_addr_3          , Parse_UInt8   );
+        SENF_PARSER_FIELD    ( mac_addr_4          , UInt8Parser   );
+        SENF_PARSER_FIELD    ( mac_addr_3          , UInt8Parser   );
 
         SENF_PARSER_FINALIZE( Parse_DatagramSection );
 
         // Parse table_id_extension as two bytes
         SENF_PARSER_GOTO( table_id_extension );
-        SENF_PARSER_FIELD    ( mac_addr_6          , Parse_UInt8   );
-        SENF_PARSER_FIELD    ( mac_addr_5          , Parse_UInt8   );
+        SENF_PARSER_FIELD    ( mac_addr_6          , UInt8Parser   );
+        SENF_PARSER_FIELD    ( mac_addr_5          , UInt8Parser   );
     };
     \endcode
 
     See the documentation of each of these macros for a detailed description of the macro arguments
     and usage. Bit-fields are handled in the following section.
 
+    There also some supplementary macros for defining fields of more complex composite types
+    (e.g. vectors). See the list of 'Defines' further down this page.
+
     \subsection parsermacrosbitfields Bit-fields
 
     \par "" 
 
     Bit-fields play a special role. They are quite frequent in packet definitions but don't fit into
     the byte offset based parsing infrastructure defined so far. Since defining the correctly
-    parameterized senf::Parse_IntField, senf::Parse_UIntField and senf::Parse_Flag typedefs is quite
+    parameterized senf::IntFieldParser, senf::UIntFieldParser and senf::FlagParser typedefs is quite
     tedious, these helper macros are provided.
 
     It is important to recognize, that the current offset does \e not include the current bit
     at the end), those bit's will be skipped.
 
     Since consecutive bit-field commands are aggregated into a single bit-field group, the offset of
-    all these bit-fields will be the offset of the \e beginning of the bit-field irrespective of the
+    all these bit-fields will be the offset of the \e beginning of the group irrespective of the
     number of bits parsed so far. Changing the offset to some bitfield using \ref SENF_PARSER_GOTO()
     will therefore always go to the position at the beginning of this bitfield group. And since the
     current offset does not include the bit position, the bit position will be 0, the first bit. You
 
     \hideinitializer
  */
-#define SENF_PARSER_INIT()       void init(int)
+#define SENF_PARSER_INIT()       void init(int) const
 
 #ifdef DOXYGEN
 
         SENF_PARSER_PRIVATE_FIELD_RO()
     \hideinitializer
  */
-#define SENF_PARSER_FIELD(name, type)
+#define SENF_PARSER_FIELD(name, type) 
 
 /** \brief Define parser field (read-only)
     
     \see SENF_PARSER_FIELD() 
     \hideinitializer
 */
-#define SENF_PARSER_FIELD_RO(name, type)
+#define SENF_PARSER_FIELD_RO(name, type) 
 
 /** \brief Define parser field (private)
 
     \see SENF_PARSER_FIELD()
     \hideinitializer
  */
-#define SENF_PARSER_PRIVATE_FIELD(name, type)
+#define SENF_PARSER_PRIVATE_FIELD(name, type) 
 
 /** \brief Define parser field (private + read-only)
 
     \see SENF_PARSER_FIELD()
     \hideinitializer
  */
-#define SENF_PARSER_PRIVATE_FIELD_RO(name, type)
+#define SENF_PARSER_PRIVATE_FIELD_RO(name, type) 
 
 /** \brief Define custom field accessor
 
     This macro is used to define a field using a custom access method:
     \code
-    // The following is the same as SENF_PARSER_FIELD( xyz, senf::Parse_UInt16 )
+    // The following is the same as SENF_PARSER_FIELD( xyz, senf::UInt16Parser )
     // in a fixed size parser.
 
-    SENF_PARSER_CUSTOM_FIELD(xyz, senf::Parse_UInt16, xyz_t::fixed_bytes) {
+    SENF_PARSER_CUSTOM_FIELD(xyz, senf::UInt16Parser, xyz_t::fixed_bytes) {
         return parse<xyz_t>( xyz_offset );
     }
     \endcode
     \param[in] size size of the field, either a single value \a bytes for fixed size parsers or two
         separate arguments \a bytes and \a init_bytes for dynamically sized parsers
  */
-#define SENF_PARSER_CUSTOM_FIELD(name, type, size)
+#define SENF_PARSER_CUSTOM_FIELD(name, type, size) 
 
 ///@}
 
 /** \brief Define bit-field
 
     Bit fields are supported by a special family of parser macros. These macros simplify defining
-    fields using the senf::Parse_Int, senf::Parse_UInt and senf::Parse_Flag parsers by keeping track
+    fields using the senf::Parse_Int, senf::Parse_UInt and senf::FlagParser parsers by keeping track
     of the current bit position and automatically creating the correct template parameters.
     
     The \a type parameter specifies the type of bitfield to define. This value is one of
-    \li \c signed, for signed bit fields (senf::Parse_IntField)
-    \li \c unsigned, for unsigned bit fields (senf::Parse_UIntField) or 
-    \li \c bool, for single-bit flags (senf::Parse_Flag). 
+    \li \c signed, for signed bit fields (senf::IntFieldParser)
+    \li \c unsigned, for unsigned bit fields (senf::UIntFieldParser) or 
+    \li \c bool, for single-bit flags (senf::FlagParser). 
 
     The \a bits parameter specifies the number of bits the field covers. For \c signed or \c
     unsigned fields, this value may be any numeric value from 1 to 32, for \c bool fields, this
 
     \hideinitializer
  */
-#define SENF_PARSER_BITFIELD(name, bits, type)
+#define SENF_PARSER_BITFIELD(name, bits, type) 
 
 /** \brief Define bit-field (read-only) 
 
     \see \ref SENF_PARSER_BITFIELD()
     \hideinitializer
  */
-#define SENF_PARSER_BITFIELD_RO(name, bits, type)
+#define SENF_PARSER_BITFIELD_RO(name, bits, type) 
 
 /** \brief Define bit-field (private) 
 
     \see \ref SENF_PARSER_BITFIELD()
     \hideinitializer
  */
-#define SENF_PARSER_PRIVATE_BITFIELD(name, bits, type)
+#define SENF_PARSER_PRIVATE_BITFIELD(name, bits, type) 
 
 /** \brief Define bit-field (private + read-only) 
 
     This command will skip the given number of bits within a bitfield group. This command does \e
     only affect bitfield commands. Therefore, a SENF_PARSER_SKIP_BITS command which is not followed
     by a bitfield command will be ignored.
+
+    \hideinitializer
  */
 #define SENF_PARSER_SKIP_BITS(bits)
 
     group covers multiple bytes before the bit field \a name.
 
     \param[in] name field or label to jump to
+    \hideinitializer
  */
 #define SENF_PARSER_GOTO(name)
 
 
     \param[in] offset Depending on the parser type, either single \a bytes value or two arguments \a
         bytes and \a init_size.
+    \hideinitializer
  */
 #define SENF_PARSER_GOTO_OFFSET(offset)
 
     labeled with \ref SENF_PARSER_LABEL()
 
     \param[in] name label name
+    \hideinitializer
  */
 #define SENF_PARSER_LABEL(name)
 
     while defining the parser, normally while defining inline functions.
 
     This macro will return the correct value when defining fixed or dynamically sized parsers.
+
+    \param[in] name field or label name
+    \returns offset of the field from parsers start
+    \hideinitializer
  */
 #define SENF_PARSER_OFFSET(name)
 
+/** \brief Get fixed field offset, if possible
+
+    This macro will return the fixed offset to the field \a name, a compile-time constant
+    expression. This is identical to \ref SENF_PARSER_OFFSET() when defining a fixed size parser.
+
+    Even in dynamically sized parsers this macro will work, if the field \a name is preceded by
+    fixed size fields only. This macro does \e not validate this condition, it will return an
+    arbitrary incorrect value otherwise.
+
+    \pre Field \a name preceded by fixed size fields only
+    \param[in] name field or label name
+    \returns compile-time constant offset of the field from parsers start
+    \hideinitializer
+ */
+#define SENF_PARSER_FIXED_OFFSET(name)
+
+/** \brief Get current fixed offset, if possible
+    This macro will return the current fixed offset, a compile-time constant expression. This is
+    always possible when defining a fixed size parser.
+
+    Even in dynamically sized parsers this macro will work, if all parser defined \e before the
+    current position are fixed-size parsers. This macro does \e not validate this condition, it will
+    return an arbitrary incorrect value otherwise.
+
+    \pre Current position preceded by fixed-size parsers only
+    \returns compile-time constant offset from parsers start
+    \hideinitializer
+ */
+#define SENF_PARSER_CURRENT_FIXED_OFFSET()
+
 ///@}
 
 #else
 #define SENF_PARSER_LABEL        BOOST_PP_CAT(SENF_PARSER_LABEL_,       SENF_PARSER_TYPE)
 
 #define SENF_PARSER_OFFSET       BOOST_PP_CAT(SENF_PARSER_OFFSET_,      SENF_PARSER_TYPE)
+#define SENF_PARSER_FIXED_OFFSET BOOST_PP_CAT(SENF_PARSER_FIXED_OFFSET_,SENF_PARSER_TYPE)
+#define SENF_PARSER_CURRENT_FIXED_OFFSET BOOST_PP_CAT(SENF_PARSER_CURRENT_FIXED_OFFSET_, SENF_PARSER_TYPE)
 
 #define SENF_PARSER_FINALIZE     BOOST_PP_CAT(SENF_PARSER_FINALIZE_,    SENF_PARSER_TYPE)