set keyword-property
[senf.git] / Packets / ParseVec.hh
index b9ee51b..5d8d180 100644 (file)
@@ -20,6 +20,9 @@
 // Free Software Foundation, Inc.,
 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+/** \file
+    \brief ParseVec public header */
+
 #ifndef HH_ParseVec_
 #define HH_ParseVec_ 1
 
@@ -32,6 +35,7 @@
 #include "ParseArray.hh" // for Parse_Array_iterator
 
 //#include "ParseVec.mpp"
+#include "ParseVec.ih"
 ///////////////////////////////hh.p////////////////////////////////////////
 
 namespace senf {
@@ -47,7 +51,7 @@ 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.
 
-        Parse_Vector makes use of a policy template argument, \a Sizer to customize the way the
+        Parse_Vector 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.
@@ -108,8 +112,6 @@ namespace senf {
         friend class Parse_Vector_Container<ElementParser,Sizer>;
     };
 
-    namespace detail { template <class SizeParser> class Parse_VectorN_Sizer; }
-
     /** \brief Vector with prefix sizing
         
         This is a 'template typedef'. It defines a vector with a <em>directly preceding</em> size
@@ -127,66 +129,42 @@ namespace senf {
         \see Parse_Vector
         \ingroup parsecollection
      */
-    template <class ElementParser, class SizeParser>
+    template <class ElementParser, class SizeParser, unsigned Distance>
     struct Parse_VectorN
     {
         typedef Parse_Vector< ElementParser,
-                              detail::Parse_VectorN_Sizer<SizeParser> > parser;
+                              detail::Parse_VectorN_Sizer<SizeParser, Distance> > parser;
     };
 
-    /** \brief Example vector sizer. ONLY FOR EXPOSITION
+    /** \brief Define Parse_VectorN field
+        
+        This macro is a special helper to define a senf::Parse_VectorN type field, a vector of
+        elements of type \a elt_type (a parser) which size is given by the \a size field.
 
-        This class shows the interface which must be implemented by a vector sizer policy. It is not
-        a vector sizer, it is only a declaration of the interface:
         \code
-        struct ExampleVectorPolicy
-        {
-            // optional typedefs used to simplify all other declarations
-            typedef PacketParserBase::size_type size_type;
-            typedef PacketParserBase::data_iterator iterator;
-            typedef PacketParserBase::state_type state_type;
-
-            // mandatory members
-            static const size_type init_bytes = 0;
-            size_type  size  (iterator i, state_type s) const;
-            void       size  (iterator i, state_type s, size_type v) const;
-            iterator   begin (iterator i, state_type s) const;
-            size_type  bytes (iterator i, state_type s) const;
-            void       init  (iterator i, state_type s) const;
-        };
+        // The size field should be declared private (size is accessible via the vector)
+        SENF_PARSER_PRIVATE_FIELD ( vec_size_, senf::Parse_UInt16 );
+        // Define the vector, here it has 32bit unsigned integer elements
+        SENF_PARSER_VEC_N         ( vec,       _vec_size, senf::Parse_UInt32 );
         \endcode
-
-        A sizer may if needed define additional data members.
+        
+        \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
      */
-    struct ExampleVectorPolicy
-    {
-        typedef PacketParserBase::size_type size_type;
-        typedef PacketParserBase::data_iterator iterator;
-        typedef PacketParserBase::state_type state_type;
+#   define SENF_PARSER_VEC_N(name, size, elt_type)                                                \
+        SENF_PARSER_VEC_N_I(SENF_PARSER_FIELD, name, size, elt_type)
 
-        static const size_type init_bytes = 0; ///< Size of a new vector of this size
-                                        /**< Initial size which needs to be allocated to this type
-                                             of list */
-
-        size_type  size  (iterator i, state_type s) const; ///< Get current vector size
-                                        /**< Return the current number of elements in the 
-                                             vector. */
-        void       size  (iterator i, state_type s, size_type v) const; ///< Change vector size
-                                        /**< Set the size of the vector to \a v. */
-        iterator   begin (iterator i, state_type s) const; 
-                                        ///< Return data_iterator to first element
-                                        /**< The returned data_iterator must point to the beginning
-                                             of the first vector element. The last iterator can than
-                                             automatically be calculated from the fixed element size
-                                             and the number of vector elements. */
-        size_type  bytes (iterator i, state_type s) const; ///< Size of vector parser
-                                        /**< Return the size of the complete vector in bytes. This
-                                             is not necessarily the same as \c size() * \e
-                                             fixed_element_bytes. */
-        void       init  (iterator i, state_type s) const; ///< Initialize new vector
-                                        /** Called to initialize a new vector after allocating
-                                            init_bytes number of bytes for the vector. */
-    };
+    /** \brief Define Parse_VectorN 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 Parse_Vector container wrapper
 
@@ -203,6 +181,8 @@ namespace senf {
         SomePacket::aVectorCollection_t::container c (p->aVectorCollection());
         c.insert(c.begin(), ... );
         \endcode
+
+        \see Parse_Vector
       */
     template <class ElementParser, class Sizer>
     class Parse_Vector_Container
@@ -256,9 +236,14 @@ namespace senf {
         void insert(iterator pos, Value const & t);
         template <class Value>
         void insert(iterator pos, size_type n, Value const & t);
+#       ifndef DOXYGEN
         template <class ForwardIterator>
         void insert(iterator pos, ForwardIterator f, ForwardIterator l,
                     typename boost::disable_if< boost::is_convertible<ForwardIterator,size_type> >::type * = 0);
+#       else
+        template <class ForwardIterator>
+        void insert(iterator pos, ForwardIterator f, ForwardIterator l);
+#       endif
 
         void erase(iterator pos, size_type n=1);
         void erase(iterator f, iterator l);
@@ -300,7 +285,7 @@ namespace senf {
 
 ///////////////////////////////hh.e////////////////////////////////////////
 #endif
-#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_ParseVec_i_)
+#if !defined(HH_Packets__decls_) && !defined(HH_ParseVec_i_)
 #define HH_ParseVec_i_
 //#include "ParseVec.cci"
 #include "ParseVec.ct"