4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief ListParser public header */
26 #ifndef HH_ListParser_
27 #define HH_ListParser_ 1
30 #include <boost/utility.hpp>
31 #include "PacketParser.hh"
33 //#include "ListParser.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
38 namespace detail { template <class Container> class ListParser_Iterator; }
40 template <class ListPolicy>
41 class ListParser_Container;
43 /** \brief Arbitrary sequential element collection
45 A List is a sequential collection of elements. The element type is given as an arbitrary
46 parser. The list is more flexible than a vector: It is not limited to fixed-size elements
47 and it might not have direct access to the size of the collection.
49 The cost is however, that a List is only a model of an STL forward sequence. The parser
50 provides a reduced interface to this sequence, the container wrapper provides the complete
53 Pare_List makes use of a policy template argument, \a ListPolicy, to customize the way the
54 list is laid out. This policy is given quite some freedom in the list
55 implementation. It is however important, that list elements <em>always follow each other
56 without padding</em> (if padding is needed, it needs to be part of the element parser).
58 \see ExampleListPolicy
59 \ingroup parsecollection
61 template <class ListPolicy>
63 : public PacketParserBase,
67 typedef ListPolicy policy;
69 ListParser(data_iterator i, state_type s);
70 ListParser(ListPolicy policy, data_iterator i, state_type s);
71 ///< Additional policy specific constructor
72 /**< This constructor may be used, if the policy needs
73 additional parameters. */
75 size_type bytes() const;
78 static const size_type init_bytes = ListPolicy::init_bytes;
80 ///////////////////////////////////////////////////////////////////////////
81 // Container interface
83 typedef typename ListPolicy::element_type value_type;
84 typedef typename ListPolicy::container_type container;
86 size_type size() const;
89 value_type front() const;
90 value_type back() const;
92 template <class Value> void push_back (Value value, size_type n=1) const;
93 void push_back_space (size_type n=1) const;
94 template <class Value> void push_front (Value value, size_type n=1) const;
95 void push_front_space (size_type n=1) const;
96 void resize (size_type n) const;
97 template <class Value> void resize (size_type n, Value value) const;
99 static ListParser & get(ListPolicy & p);
100 static ListParser const & get(ListPolicy const & p);
103 template <class Policy> friend class ListParser_Container;
106 /** \brief ListParser container wrapper
108 This is the container wrapper used for list parsers. The container wrapper will stay valid
109 after changing the collection. However the container still depends on the packet and will be
110 invalidated if the Packet is deallocated or if the packet size is changed from without the
111 container wrapper (more precisely, it is invalided if the insertion/deletion happens before
112 the vector in the packet data).
114 The vector container wrapper provides a complete STL random-access sequence interface.
118 SomePacket::aListCollection_t::container c (p->aListCollection());
119 c.insert(c.begin(), ... );
124 template <class ListPolicy>
125 class ListParser_Container
129 ///////////////////////////////////////////////////////////////////////////
132 typedef ListPolicy policy;
133 typedef typename ListPolicy::parser_type parser_type;
134 typedef PacketParserBase::data_iterator data_iterator;
135 typedef PacketParserBase::size_type size_type;
136 typedef PacketParserBase::difference_type difference_type;
137 typedef typename ListPolicy::element_type value_type;
138 typedef detail::ListParser_Iterator<ListParser_Container> iterator;
139 typedef iterator const_iterator;
140 typedef PacketParserBase::state_type state_type;
142 ///////////////////////////////////////////////////////////////////////////
143 ///\name Structors and default members
146 // no default constructor
148 // default destructor
149 // conversion constructors
151 ListParser_Container(parser_type const & list);
152 ~ListParser_Container();
155 ///////////////////////////////////////////////////////////////////////////
160 size_type size() const;
163 iterator begin() const;
164 iterator end() const;
166 value_type front() const;
167 value_type back() const;
173 // All these operations can be quite inefficient depending on the list type
174 void shift(iterator pos, size_type n=1);
175 template <class Value>
176 void insert(iterator pos, Value const & t);
177 template <class Value>
178 void insert(iterator pos, size_type n, Value const & t);
179 template <class ForwardIterator>
181 void insert(iterator pos, ForwardIterator f, ForwardIterator l,
182 typename boost::disable_if< boost::is_convertible<ForwardIterator,size_type> >::type * = 0);
184 void insert(iterator pos, ForwardIterator f, ForwardIterator l);
187 void erase(iterator pos, size_type n=1);
188 void erase(iterator f, iterator l);
191 template <class Value> void push_back (Value value, size_type n=1);
192 void push_back_space (size_type n=1);
193 template <class Value> void push_front (Value value, size_type n=1);
194 void push_front_space (size_type n=1);
195 void resize (size_type n);
196 template <class Value> void resize (size_type n, Value value);
200 ///\name Parser interface
203 parser_type parser() const;
204 data_iterator i() const;
205 state_type state() const;
206 PacketData & data() const;
208 size_type bytes() const;
214 friend class detail::ListParser_Iterator<ListParser_Container>;
220 # define SENF_PARSER_LIST(name, size, elt_type) \
221 SENF_PARSER_LIST_I(public, name, size, elt_type)
223 # define SENF_PARSER_PRIVATE_LIST(name, size, elt_type) \
224 SENF_PARSER_LIST_I(private, name, size, elt_type)
228 ///////////////////////////////hh.e////////////////////////////////////////
230 #if !defined(HH_Packets__decls_) && !defined(HH_ListParser_i_)
231 #define HH_ListParser_i_
232 //#include "ListParser.cci"
233 #include "ListParser.ct"
234 #include "ListParser.cti"
241 // c-file-style: "senf"
242 // indent-tabs-mode: nil
243 // ispell-local-dictionary: "american"
244 // compile-command: "scons -u test"
245 // comment-column: 40