added first (prototype) handle for the DVB frontend device
[senf.git] / Packets / ParseVec.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
7 //
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.
12 //
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.
17 //
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.
22
23 #ifndef HH_ParseVec_
24 #define HH_ParseVec_ 1
25
26 // Custom includes
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
33
34 //#include "ParseVec.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
36
37 namespace senf {
38
39     template <class ElementParser, class Sizer> class Parse_Vector_Container;
40
41     /** \brief
42         
43         \todo Make the sizer a private baseclass to profit from the empty-base-class optimization
44      */
45     template <class ElementParser, class Sizer>
46     struct Parse_Vector : public PacketParserBase
47     {
48         Parse_Vector(data_iterator i, state_type s);
49         Parse_Vector(Sizer sizer, data_iterator i, state_type s);
50
51         size_type bytes() const;
52         void init() const;
53
54         static const size_type init_bytes = Sizer::init_bytes;
55
56         ///////////////////////////////////////////////////////////////////////////
57         // Container interface
58
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;
63
64         size_type size() const;
65         bool empty() const;
66
67         iterator begin() const;
68         iterator end() const;
69
70         value_type operator[](difference_type i) const;
71         value_type front() const;
72         value_type back() const;
73
74         // Mutators
75         
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
79                    
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;
86
87      private:
88         Sizer sizer_;
89
90         friend class Parse_Vector_Container<ElementParser,Sizer>;
91     };
92
93     namespace detail { template <class SizeParser> class Parse_VectorN_Sizer; }
94
95     template <class ElementParser, class SizeParser>
96     struct Parse_VectorN
97     {
98         typedef Parse_Vector< ElementParser,
99                               detail::Parse_VectorN_Sizer<SizeParser> > parser;
100     };
101
102     /** \brief
103
104         Holds a reference to the container !
105       */
106     template <class ElementParser, class Sizer>
107     class Parse_Vector_Container
108     {
109     public:
110         ///////////////////////////////////////////////////////////////////////////
111         // Types
112
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;
121
122         ///////////////////////////////////////////////////////////////////////////
123         ///\name Structors and default members
124         ///@{
125
126         // no default constructor
127         // default copy
128         // default destructor
129         // conversion constructors
130
131         Parse_Vector_Container(parser_type const & vector);
132
133         ///@}
134         ///////////////////////////////////////////////////////////////////////////
135
136         ///\name Accessors
137         ///@{
138
139         size_type size() const;
140         bool empty() const;
141
142         iterator begin() const;
143         iterator end() const;
144
145         value_type operator[](difference_type i) const;
146         value_type front() const;
147         value_type back() const;
148
149         ///@}
150         ///\name Mutators
151         ///@{
152
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);
161
162         void erase(iterator pos, size_type n=1);
163         void erase(iterator f, iterator l);
164         void clear();
165
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);
172
173         ///@}
174
175         ///\name Parser interface
176         ///@{
177
178         parser_type parser() const;
179         data_iterator i() const;
180         state_type state() const;
181         PacketData & data() const;
182
183         size_type bytes() const;
184         void init() const;
185         
186         ///@}
187
188     protected:
189
190     private:
191         void setSize(size_type value);
192
193         Sizer sizer_;
194         state_type state_;
195         size_type i_;
196     };
197
198 }
199
200 ///////////////////////////////hh.e////////////////////////////////////////
201 #endif
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"
207 #endif
208
209 \f
210 // Local Variables:
211 // mode: c++
212 // fill-column: 100
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
218 // End: