2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 // Stefan Bund <g0dil@berlios.de>
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 \brief ParseList public header */
25 #define HH_ParseList_ 1
28 #include <boost/utility.hpp>
29 #include "PacketParser.hh"
31 //#include "ParseList.mpp"
32 ///////////////////////////////hh.p////////////////////////////////////////
36 namespace detail { template <class ElementParser, class IteratorPolicy>
37 class Parse_List_Iterator; }
39 template <class ListPolicy>
40 class Parse_List_Container;
42 /** \brief Arbitrary sequential element collection
44 A List is a sequential collection of elements. The element type is given as an arbitrary
45 parser. The list is more flexible than a vector: It is not limited to fixed-size elements
46 and it might not have direct access to the size of the collection.
48 The cost is however, that a List is only a model of an STL forward sequence. The parser
49 provides a reduced interface to this sequence, the container wrapper provides the complete
52 Pare_List makes use of a policy template argument, \a ListPolicy, to customize the way the
53 list is laid out. This policy is given quite some freedom in the list
54 implementation. It is however important, that list elements <em>always follow each other
55 without padding</em> (if padding is needed, it needs to be part of the element parser).
57 \see ExampleListPolicy
58 \ingroup parsecollection
60 template <class ListPolicy>
62 : public PacketParserBase,
66 Parse_List(data_iterator i, state_type s);
67 Parse_List(ListPolicy policy, data_iterator i, state_type s);
68 ///< Additional policy specific constructor
69 /**< This constructor may be used, if the policy needs
70 additional parameters. */
72 size_type bytes() const;
75 static const size_type init_bytes = ListPolicy::init_bytes;
77 ///////////////////////////////////////////////////////////////////////////
78 // Container interface
80 typedef typename ListPolicy::element_type value_type;
81 typedef detail::Parse_List_Iterator<
82 value_type, typename ListPolicy::iterator_policy > iterator;
83 typedef iterator const_iterator;
84 typedef typename ListPolicy::container_type container;
86 size_type size() const;
89 iterator begin() const;
92 value_type front() const;
93 value_type back() const;
95 template <class Value> void push_back (Value value, size_type n=1) const;
96 void push_back_space (size_type n=1) const;
97 template <class Value> void push_front (Value value, size_type n=1) const;
98 void push_front_space (size_type n=1) const;
99 void resize (size_type n) const;
100 template <class Value> void resize (size_type n, Value value) const;
103 template <class Policy> friend class Parse_List_Container;
106 /** \brief Parse_List 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 Parse_List_Container
129 ///////////////////////////////////////////////////////////////////////////
132 typedef typename ListPolicy::parser_type parser_type;
133 typedef PacketParserBase::data_iterator data_iterator;
134 typedef PacketParserBase::size_type size_type;
135 typedef PacketParserBase::difference_type difference_type;
136 typedef typename ListPolicy::element_type value_type;
137 typedef detail::Parse_List_Iterator<
138 value_type, typename ListPolicy::iterator_policy> 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 Parse_List_Container(parser_type const & list);
152 ~Parse_List_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;
221 ///////////////////////////////hh.e////////////////////////////////////////
223 #if !defined(HH_Packets__decls_) && !defined(HH_ParseList_i_)
224 #define HH_ParseList_i_
225 //#include "ParseList.cci"
226 #include "ParseList.ct"
227 #include "ParseList.cti"
234 // c-file-style: "senf"
235 // indent-tabs-mode: nil
236 // ispell-local-dictionary: "american"
237 // compile-command: "scons -u test"
238 // comment-column: 40