X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FVectorParser.hh;h=db9e0de2c015adc79658c8c584caa848a65a2e50;hb=c45c112ae88196ea8da9c5a9efb0e167196744d2;hp=bfba929e266ac60a68094326ccbfee410430a55b;hpb=8f1a688cea76f2e76bfa0193dff9c1538929147e;p=senf.git diff --git a/Packets/VectorParser.hh b/Packets/VectorParser.hh index bfba929..db9e0de 100644 --- a/Packets/VectorParser.hh +++ b/Packets/VectorParser.hh @@ -23,8 +23,8 @@ /** \file \brief VectorParser public header */ -#ifndef HH_VectorParser_ -#define HH_VectorParser_ 1 +#ifndef HH_SENF_Packets_VectorParser_ +#define HH_SENF_Packets_VectorParser_ 1 // Custom includes #include @@ -51,14 +51,19 @@ namespace senf { A vector is a model of an STL random-access sequence. The parser only provides a reduced interface, the container wrapper however completes this interface. - VectorParser makes use of a policy template argument, \a Sizer, to customize the way the - containers size is obtained. You will normally not instantiate Parser_Vector directly, you - will use one of the 'template typedefs' (which are templated structures since C++ does not - provide real template typedefs) provided with the policy implementations. + VectorParser makes use of a policy template argument, \a AuxPolicy, to customize the way the + containers size is obtained. You will normally not instantiate VectorParser directly, you + will use the \ref SENF_PARSER_VECTOR() helper macro. + + Some basic vector access methods are defined as parser members. To access the complete list + API however you will need to instantiate a container wrapper for the vector. See \ref + packet_usage_fields_collection. - \todo Make the sizer a private base-class to profit from the empty-base-class optimization + \see + \ref How to access \ref packet_usage_fields_collection \n + SENF_PARSER_VECTOR() macro used to define vector fields \n + VectorParser_Container vector container wrapper API - \see ExampleVectorPolicy \ingroup parsecollection */ template @@ -113,44 +118,6 @@ namespace senf { friend class VectorParser_Container; }; - /** \brief Define VectorNParser field - - This macro is a special helper to define a senf::VectorNParser type field, a vector of - elements of type \a elt_type (a parser) which size is given by the \a size field. - - \code - // The size field should be declared private (size is accessible via the vector) - SENF_PARSER_PRIVATE_FIELD ( vec_size_, senf::UInt16Parser ); - // Define the vector, here it has 32bit unsigned integer elements - SENF_PARSER_VEC_N ( vec, vec_size_, senf::UInt32Parser ); - \endcode - - \param[in] name field name - \param[in] size name of field giving the vector size - \param[in] elt_type vector element type - \hideinitializer - \ingroup packetparsermacros - */ -# define SENF_PARSER_VEC_N(name, size, elt_type) \ - SENF_PARSER_VEC_N_I(SENF_PARSER_FIELD, name, size, elt_type) - - /** \brief Define VectorNParser field - - \see \ref SENF_PARSER_VEC_N() - \hideinitializer - \ingroup packetparsermacros - */ -# define SENF_PARSER_PRIVATE_VEC_N(name, size, elt_type) \ - SENF_PARSER_VEC_N_I(SENF_PARSER_PRIVATE_FIELD, name, size, elt_type) - -# define SENF_PARSER_VECTOR(name, size, elt_type) \ - SENF_PARSER_VECTOR_I(public, name, size, elt_type) - -# define SENF_PARSER_PRIVATE_VECTOR(name, size, elt_type) \ - SENF_PARSER_VECTOR_I(private, name, size, elt_type) - - - /** \brief VectorParser container wrapper This is the container wrapper used for vector parsers. The container wrapper will stay valid @@ -171,7 +138,7 @@ namespace senf { */ template class VectorParser_Container - : private AuxPolicy + : private AuxPolicy::WrapperPolicy { public: /////////////////////////////////////////////////////////////////////////// @@ -266,12 +233,84 @@ namespace senf { size_type i_; }; + /** \brief Define VectorParser field + + This macro is a special helper to define a senf::VectorParser type field, a vector of + elements of type \a elt_type (a parser) which size is given by the \a size field. + + \code + // The size field should be declared private (size is accessible via the vector) + SENF_PARSER_PRIVATE_FIELD ( vec_size_, senf::UInt16Parser ); + // Define the vector, here it has 32bit unsigned integer elements + SENF_PARSER_VECTOR ( vec, vec_size_, senf::UInt32Parser ); + \endcode + + \warning Realize, that the \a size field is controlled by the vector parser. This field + should therefore be declared either read-only or private and must be changed only via + the vector parser. + + Further additional tags are supported which modify the way, the \a size field is + interpreted: + + + + + + + +
\c bytes(\a size)\a size gives the size of the vector in bytes not the + number of contained elements
\c packetSize()Use the size of the packet to get the vector size. The + vector will occupy all space up to the end of the packet.
\c transform(\a transform, \a size)The \a transform is applied to the \a + size value, the value is not used directly
+ + The optional \a transform is a class with the following layout + + \code + struct MyTransform + { + typedef ... value_type; + static value_type get(other_type v); + static other_type set(value_type v); + }; + \endcode \c other_type is the \a size ::\c value_type where as the \c value_type typedef is + the arbitrary return type of the transform. + + The tags are applied to the \a size parameter: + \code + SENF_PARSER_VECTOR ( vec, transform(MyTransform, vec_size_), senf::UInt32Parser ); + SENF_PARSER_VECTOR ( vec, packetSize(), senf::UInt32Parser ); + \endcode + + \param[in] name field name + \param[in] size name of field giving the vector size + \param[in] elt_type vector element type + + \see + How to use \ref packet_usage_fields_collection \n + senf::VectorParser the vector parser API for vector field access + senf::VectorParser_Container the vector parser container API for vector field access + + \hideinitializer + \ingroup packetparsermacros + */ +# define SENF_PARSER_VECTOR(name, size, elt_type) \ + SENF_PARSER_VECTOR_I(public, name, size, elt_type) + + /** \brief Define private VectorParser field + + \see \ref SENF_PARSER_VECTOR() + + \hideinitializer + \ingroup packetparsermacros + */ +# define SENF_PARSER_PRIVATE_VECTOR(name, size, elt_type) \ + SENF_PARSER_VECTOR_I(private, name, size, elt_type) } ///////////////////////////////hh.e//////////////////////////////////////// #endif -#if !defined(HH_Packets__decls_) && !defined(HH_VectorParser_i_) -#define HH_VectorParser_i_ +#if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_VectorParser_i_) +#define HH_SENF_Packets_VectorParser_i_ //#include "VectorParser.cci" #include "VectorParser.ct" #include "VectorParser.cti"