4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.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 #define HH_ParseVec_ 1
27 #include <boost/iterator/iterator_facade.hpp>
28 #include <boost/utility.hpp>
29 #include <boost/range.hpp>
30 #include <boost/type_traits.hpp>
31 #include "PacketParser.hh"
32 #include "ParseArray.hh" // for Parse_Array_iterator
34 //#include "ParseVec.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
39 template <class ElementParser, class Sizer> class Parse_Vector_Container;
43 \todo Make the sizer a private baseclass to profit from the empty-base-class optimization
45 template <class ElementParser, class Sizer>
46 struct Parse_Vector : public PacketParserBase
48 Parse_Vector(data_iterator i, state_type s);
49 Parse_Vector(Sizer sizer, data_iterator i, state_type s);
51 size_type bytes() const;
54 static const size_type init_bytes = Sizer::init_bytes;
56 ///////////////////////////////////////////////////////////////////////////
57 // Container interface
59 typedef ElementParser value_type;
60 typedef detail::Parse_Array_iterator<value_type> iterator;
61 typedef iterator const_iterator;
62 typedef Parse_Vector_Container<ElementParser,Sizer> container;
64 size_type size() const;
67 iterator begin() const;
70 value_type operator[](difference_type i) const;
71 value_type front() const;
72 value_type back() const;
76 // The mutators provided here are those which don't take an iterator argument.
77 // If you need to pass an iterator it is much simpler and cleaner to use the
78 // 'container' wrapper
80 template <class Value> void push_back (Value value, size_type n=1) const;
81 void push_back_space (size_type n=1) const;
82 template <class Value> void push_front (Value value, size_type n=1) const;
83 void push_front_space (size_type n=1) const;
84 void resize (size_type n) const;
85 template <class Value> void resize (size_type n, Value value) const;
90 friend class Parse_Vector_Container<ElementParser,Sizer>;
93 namespace detail { template <class SizeParser> class Parse_VectorN_Sizer; }
95 template <class ElementParser, class SizeParser>
98 typedef Parse_Vector< ElementParser,
99 detail::Parse_VectorN_Sizer<SizeParser> > parser;
104 Holds a reference to the container !
106 template <class ElementParser, class Sizer>
107 class Parse_Vector_Container
110 ///////////////////////////////////////////////////////////////////////////
113 typedef Parse_Vector<ElementParser,Sizer> parser_type;
114 typedef PacketParserBase::data_iterator data_iterator;
115 typedef PacketParserBase::size_type size_type;
116 typedef PacketParserBase::difference_type difference_type;
117 typedef ElementParser value_type;
118 typedef detail::Parse_Array_iterator<value_type> iterator;
119 typedef iterator const_iterator;
120 typedef PacketParserBase::state_type state_type;
122 ///////////////////////////////////////////////////////////////////////////
123 ///\name Structors and default members
126 // no default constructor
128 // default destructor
129 // conversion constructors
131 Parse_Vector_Container(parser_type const & vector);
134 ///////////////////////////////////////////////////////////////////////////
139 size_type size() const;
142 iterator begin() const;
143 iterator end() const;
145 value_type operator[](difference_type i) const;
146 value_type front() const;
147 value_type back() const;
153 iterator shift(iterator pos, size_type n=1);
154 template <class Value>
155 void insert(iterator pos, Value const & t);
156 template <class Value>
157 void insert(iterator pos, size_type n, Value const & t);
158 template <class ForwardIterator>
159 void insert(iterator pos, ForwardIterator f, ForwardIterator l,
160 typename boost::disable_if< boost::is_convertible<ForwardIterator,size_type> >::type * = 0);
162 void erase(iterator pos, size_type n=1);
163 void erase(iterator f, iterator l);
166 template <class Value> void push_back (Value value, size_type n=1);
167 void push_back_space (size_type n=1);
168 template <class Value> void push_front (Value value, size_type n=1);
169 void push_front_space (size_type n=1);
170 void resize (size_type n);
171 template <class Value> void resize (size_type n, Value value);
175 ///\name Parser interface
178 parser_type parser() const;
179 data_iterator i() const;
180 state_type state() const;
181 PacketData & data() const;
183 size_type bytes() const;
191 void setSize(size_type value);
200 ///////////////////////////////hh.e////////////////////////////////////////
202 #if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_ParseVec_i_)
203 #define HH_ParseVec_i_
204 //#include "ParseVec.cci"
205 #include "ParseVec.ct"
206 #include "ParseVec.cti"
213 // c-file-style: "senf"
214 // indent-tabs-mode: nil
215 // ispell-local-dictionary: "american"
216 // compile-command: "scons -u test"
217 // comment-column: 40