X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FVariantParser.hh;h=17b0ca414445dfeaebcbb89ead5bde5424f04799;hb=6745b9a3712f3221fe4b076ed7abb1ab92d6ac2b;hp=8516a9f1e7e82e484efbdcf73c2ca1b8e280c401;hpb=734c0be097d831c8b6e1e797bae08262fc9b4dfe;p=senf.git
diff --git a/Packets/VariantParser.hh b/Packets/VariantParser.hh
index 8516a9f..17b0ca4 100644
--- a/Packets/VariantParser.hh
+++ b/Packets/VariantParser.hh
@@ -23,10 +23,10 @@
/** \file
\brief VariantParser public header */
-#ifndef HH_VariantParser_
-#define HH_VariantParser_ 1
+#ifndef HH_SENF_Packets_VariantParser_
+#define HH_SENF_Packets_VariantParser_ 1
-#ifndef HH_Packets_
+#ifndef HH_SENF_Packets_Packets_
#error "Don't include 'VariantParser.hh' directly, include 'Packets.hh'"
#endif
@@ -125,29 +125,31 @@ namespace senf {
/** \brief Define VariantParser field
- This macro is a special helper to define a senf::DirectVariantParser type field. This is a
- variant field which chooses the sub-type by directly taking the value of some other field.
-
+ This macro is a special helper to define a senf::VariantParser type field.
\code
struct SomeParser : public PacketParserBase
{
# include SENF_PARSER()
SENF_PARSER_PRIVATE_FIELD( type, senf::UInt8Parser );
- SENF_PARSER_PRIVATE_VARIANT( content, type,
- (novalue( disable, senf::VoidPacketParser ))
- ( id( uint8, senf::UInt8Parser ))
- ( id( uint16, senf::UInt16Parser ))
- ( id( uint24, senf::UInt24Parser ))
- ( id( uint32, senf::UInt32Parser )) );
+ SENF_PARSER_VARIANT( content, type,
+ (novalue( disable, senf::VoidPacketParser ))
+ ( id( uint8value, senf::UInt8Parser ))
+ ( id( uint16value, senf::UInt16Parser ))
+ ( id( uint24value, senf::UInt24Parser ))
+ ( id( uint32value, senf::UInt32Parser )) );
SENF_PARSER_FINALIZE(SomeParser);
};
- \endcode
-
+ \endcode
+
The variant \c content chooses one of the sub parsers depending on the \c type field. If \c
type is 0, senf::VoidPacketParser is selected, if it is 1, senf::UInt8Parser and so on.
+ \warning Realize, that the \a chooser field is controlled by the variant parser. This field
+ should therefore be declared either read-only or private and must be changed only via
+ the variant parser.
+
The \a types parameter specifies the types of sub-objects supported by this variant
parser. This parameter is a (Boost.Preprocessor style) sequence
(\a type) (\a type) ...
@@ -157,25 +159,34 @@ namespace senf {
\a type | Do not provide accessor and use the 0-based type index as
key. |
- \c id(\a name, \a type) | Automatically create an accessor \a name for this
- type |
+ \c id(\a name, \a type) | Automatically create an accessor \a name, a test
+ function has_\a name and a function to switch to this type init_\a name
+ for this type. Identical to \c ids(\a name, has_\a name, init_\a name, \a
+ type) |
\c novalue(\a name, \a type) | This is like \c id but only provides an
- initializer called \a name and no accessor |
+ initializer called \a name and no accessor. Identical to \c ids(\c na, \c na, \a name, \a
+ type)
+
+ \c ids(\a accessorId, \a testId, \a initId, \a type) | This is again like \c
+ id but the names of the accessor, test function and init function are given
+ explicitly. Setting any of the id's to \c na will disable that function. |
\c key(\a value, \a type) | Use \a value to identity this type. The type is
selected, when the \a chooser is equal to \a value |
\c id(\a name, \c key(\a value, \a type)) \c novalue(\a name, \c key(\a value,
- \a type)) | The options may be nested in this way. |
+ \a type))The options may be nested in this way. |
+
+
+ Whenever an id is specified for any type, the variant itself will automatically be made
+ private so the only access to the variant from the outside is via the accessors.
- It is customary, to hide the variant parser (by defining it private) and provide
- more conveniently named accessors. In above example, these accessors are automatically
- generated using the id's given. The exact members defined are:
+ The functions defined by specifying an id are:
- \a name \c _t | The type for this specific variant value if not \c
- novalue. |
+ name_t | The type for this specific variant value if not \c
+ novalue. |
name_t name() | Return the variant value at this id
if not \c novalue. |
@@ -187,7 +198,7 @@ namespace senf {
currently holds this kind of value, \c false otherwise. Only if not \c novalue.
- If \a value keys are given, they designate the value to expect in the \a chooser field to
+ If \c key specs are given, they designate the value to expect in the \a chooser field to
select a specific variant type. If the \a chooser value does not match any key, the variant
will be initialized to the \e first type.
@@ -226,7 +237,7 @@ namespace senf {
\param[in] types a Boost.Preprocessor style sequence of sub-parser types
\see
- senf::VariantParser \n
+ senf::VariantParser for the VariantParser API\n
\ref SENF_PARSER_PRIVATE_VARIANT()
\hideinitializer
\ingroup packetparsermacros
@@ -246,8 +257,8 @@ namespace senf {
///////////////////////////////hh.e////////////////////////////////////////
#endif
-#if !defined(HH_Packets__decls_) && !defined(HH_VariantParser_i_)
-#define HH_VariantParser_i_
+#if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_VariantParser_i_)
+#define HH_SENF_Packets_VariantParser_i_
//#include "VariantParser.cci"
#include "VariantParser.ct"
#include "VariantParser.cti"