X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FVectorParser.hh;h=db9e0de2c015adc79658c8c584caa848a65a2e50;hb=5443435c4c2b6e4386c5334b5b8358273f2bae93;hp=a3e784c9a17de1b1eee964b5172c5be7e28cb1f2;hpb=f73fa16ed5abdce272ac77f8b8b9ef2b9922c266;p=senf.git diff --git a/Packets/VectorParser.hh b/Packets/VectorParser.hh index a3e784c..db9e0de 100644 --- a/Packets/VectorParser.hh +++ b/Packets/VectorParser.hh @@ -1,8 +1,8 @@ // $Id$ // // Copyright (C) 2006 -// Fraunhofer Institute for Open Communication Systems (FOKUS) -// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify @@ -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 @@ -33,14 +33,14 @@ #include #include "PacketParser.hh" #include "ArrayParser.hh" // for ArrayParser_iterator +#include "AuxParser.hh" // for the AuxPolicies //#include "VectorParser.mpp" -#include "VectorParser.ih" ///////////////////////////////hh.p//////////////////////////////////////// namespace senf { - template class VectorParser_Container; + template class VectorParser_Container; /** \brief Collection of fixed-size elements @@ -51,21 +51,28 @@ 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 - struct VectorParser : public PacketParserBase + template + struct VectorParser + : public PacketParserBase, + private AuxPolicy { VectorParser(data_iterator i, state_type s); - VectorParser(Sizer sizer, data_iterator i, state_type s); + VectorParser(AuxPolicy policy, data_iterator i, state_type s); ///< Additional sizer specific constructor /**< This constructor may be used, if the sizer needs additional parameters. */ @@ -73,7 +80,7 @@ namespace senf { size_type bytes() const; void init() const; - static const size_type init_bytes = Sizer::init_bytes; + static const size_type init_bytes = AuxPolicy::aux_bytes; /////////////////////////////////////////////////////////////////////////// // Container interface @@ -81,7 +88,7 @@ namespace senf { typedef ElementParser value_type; typedef detail::ArrayParser_iterator iterator; typedef iterator const_iterator; - typedef VectorParser_Container container; + typedef VectorParser_Container container; size_type size() const; bool empty() const; @@ -107,65 +114,10 @@ namespace senf { template void resize (size_type n, Value value) const; private: - Sizer sizer_; - friend class VectorParser_Container; + friend class VectorParser_Container; }; - /** \brief Vector with prefix sizing - - This is a 'template typedef'. It defines a vector with a directly preceding size - field holding the number of vector elements. The size field is considered part of the - vector. - \code - // Define MyVector as a vector of 16bit unsigned elements with a directly preceding - // 8bit unsigned size field - typedef senf::VectorNParser::parser MyVector; - \endcode - - \param ElementParser \e fixed-size parser for parsing the vector elements - \param SizeParser parser for parsing the vector size (number of elements) - - \see VectorParser - \ingroup parsecollection - */ - template - struct VectorNParser - { - typedef VectorParser< ElementParser, - detail::VectorNParser_Sizer > parser; - }; - - /** \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) - /** \brief VectorParser container wrapper This is the container wrapper used for vector parsers. The container wrapper will stay valid @@ -184,14 +136,15 @@ namespace senf { \see VectorParser */ - template + template class VectorParser_Container + : private AuxPolicy::WrapperPolicy { public: /////////////////////////////////////////////////////////////////////////// // Types - typedef VectorParser parser_type; + typedef VectorParser parser_type; typedef PacketParserBase::data_iterator data_iterator; typedef PacketParserBase::size_type size_type; typedef PacketParserBase::difference_type difference_type; @@ -276,17 +229,88 @@ namespace senf { private: void setSize(size_type value); - Sizer sizer_; state_type state_; 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"