Packets: Update AuxParser interface
[senf.git] / Packets / ListParser.hh
index 0b6865e..c101b82 100644 (file)
@@ -1,8 +1,8 @@
 // $Id$
 //
-// Copyright (C) 2007 
-// Fraunhofer Institute for Open Communication Systems (FOKUS) 
-// Competence Center NETwork research (NET), St. Augustin, GERMANY 
+// 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
@@ -35,8 +35,7 @@
 
 namespace senf {
 
-    namespace detail { template <class ElementParser, class IteratorPolicy> 
-                       class ListParser_Iterator; }
+    namespace detail { template <class Container> class ListParser_Iterator; }
 
     template <class ListPolicy>
     class ListParser_Container;
@@ -45,7 +44,7 @@ namespace senf {
 
         A List is a sequential collection of elements. The element type is given as an arbitrary
         parser. The list is more flexible than a vector: It is not limited to fixed-size elements
-        and it might not have direct access to the size of the collection. 
+        and it might not have direct access to the size of the collection.
 
         The cost is however, that a List is only a model of an STL forward sequence. The parser
         provides a reduced interface to this sequence, the container wrapper provides the complete
@@ -60,11 +59,13 @@ namespace senf {
         \ingroup parsecollection
       */
     template <class ListPolicy>
-    class ListParser 
+    class ListParser
         : public PacketParserBase,
           private ListPolicy
     {
     public:
+        typedef ListPolicy policy;
+
         ListParser(data_iterator i, state_type s);
         ListParser(ListPolicy policy, data_iterator i, state_type s);
                                         ///< Additional policy specific constructor
@@ -80,20 +81,14 @@ namespace senf {
         // Container interface
 
         typedef typename ListPolicy::element_type value_type;
-        typedef detail::ListParser_Iterator< 
-            value_type, typename ListPolicy::iterator_policy > iterator;
-        typedef iterator const_iterator;
         typedef typename ListPolicy::container_type container;
 
         size_type size() const;
         bool empty() const;
-        
-        iterator begin() const;
-        iterator end() const;
 
         value_type front() const;
         value_type back() const;
-        
+
         template <class Value> void push_back        (Value value, size_type n=1) const;
                                void push_back_space  (size_type n=1) const;
         template <class Value> void push_front       (Value value, size_type n=1) const;
@@ -101,6 +96,9 @@ namespace senf {
                                void resize           (size_type n) const;
         template <class Value> void resize           (size_type n, Value value) const;
 
+        static ListParser & get(ListPolicy & p);
+        static ListParser const & get(ListPolicy const & p);
+
     private:
         template <class Policy> friend class ListParser_Container;
     };
@@ -114,7 +112,7 @@ namespace senf {
         the vector in the packet data).
 
         The vector container wrapper provides a complete STL random-access sequence interface.
-        
+
         \code
         SomePacket p (...);
         SomePacket::aListCollection_t::container c (p->aListCollection());
@@ -131,16 +129,16 @@ namespace senf {
         ///////////////////////////////////////////////////////////////////////////
         // Types
 
+        typedef ListPolicy policy;
         typedef typename ListPolicy::parser_type parser_type;
         typedef PacketParserBase::data_iterator data_iterator;
         typedef PacketParserBase::size_type size_type;
         typedef PacketParserBase::difference_type difference_type;
         typedef typename ListPolicy::element_type value_type;
-        typedef detail::ListParser_Iterator<
-            value_type, typename ListPolicy::iterator_policy> iterator;
+        typedef detail::ListParser_Iterator<ListParser_Container> iterator;
         typedef iterator const_iterator;
         typedef PacketParserBase::state_type state_type;
-        
+
         ///////////////////////////////////////////////////////////////////////////
         ///\name Structors and default members
         ///@{
@@ -152,7 +150,7 @@ namespace senf {
 
         ListParser_Container(parser_type const & list);
         ~ListParser_Container();
-        
+
         ///@}
         ///////////////////////////////////////////////////////////////////////////
 
@@ -209,15 +207,22 @@ namespace senf {
 
         size_type bytes() const;
         void init() const;
-        
+
         ///@}
 
     private:
+        friend class detail::ListParser_Iterator<ListParser_Container>;
+
         state_type state_;
         size_type i_;
     };
 
-        
+#    define SENF_PARSER_LIST(name, size, elt_type) \
+         SENF_PARSER_LIST_I(public, name, size, elt_type)
+
+#    define SENF_PARSER_PRIVATE_LIST(name, size, elt_type) \
+        SENF_PARSER_LIST_I(private, name, size, elt_type)
+
 }
 
 ///////////////////////////////hh.e////////////////////////////////////////