Fixed whitespace in all files (no tabs)
[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 <utility> // for std::pair
28 #include <boost/iterator/iterator_facade.hpp>
29 #include <boost/utility.hpp> // for boost::noncopyable
30 #include "ParserBase.hh"
31 #include "ParseArray.hh" // for Parse_Array_iterator
32
33 //#include "ParseVec.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
35
36 namespace senf {
37
38
39     template <class Parser, class SizeParser, class Container> class Parse_Vector_wrapper;
40
41     template <class Parser, class SizeParser, class Iterator=nil, class IPacket=nil>
42     struct Parse_Vector : public ParserBase<Iterator,IPacket>
43     {
44         typedef typename SizeParser::template rebind<Iterator>::parser size_parser;
45
46         ///////////////////////////////////////////////////////////////////////////
47         // Parser interface
48
49         template <class I=nil, class P=nil>
50         struct rebind { typedef Parse_Vector<Parser,SizeParser,I,P> parser; };
51         typedef Iterator byte_iterator;
52
53         explicit Parse_Vector(SizeParser const & size);
54         Parse_Vector(size_parser const & size, Iterator const & i);
55
56         unsigned bytes() const;
57         void check(Iterator const & e) const;
58         void init() const;
59
60         ///////////////////////////////////////////////////////////////////////////
61         // Container interface
62
63         typedef typename Parser::template rebind<Iterator>::parser value_type;
64         typedef impl::Parse_Array_iterator<value_type,Iterator> iterator;
65         typedef unsigned size_type;
66         typedef int difference_type;
67         typedef std::pair<iterator,iterator> range_type;
68
69         template <class Container>
70         struct wrapper { typedef Parse_Vector_wrapper<value_type, size_parser, Container> t; };
71
72         size_type size() const;
73         bool empty() const;
74
75         iterator begin() const;
76         iterator end() const;
77         range_type range() const;
78         range_type value() const;
79
80         value_type operator[](difference_type i) const;
81
82      private:
83         size_parser size_;
84
85         template <class P, class SP, class C> friend class Parse_Vector_wrapper;
86     };
87
88     /** \brief
89
90         Holds a reference to the container !
91       */
92     template <class Parser, class SizeParser, class Container>
93     class Parse_Vector_wrapper
94         : public boost::noncopyable
95     {
96     public:
97         ///////////////////////////////////////////////////////////////////////////
98         // Types
99
100         typedef Container container;
101         typedef SizeParser size_parser;
102         typedef typename Parser::byte_iterator byte_iterator;
103         typedef Parser value_type;
104         typedef impl::Parse_Array_iterator<value_type,byte_iterator> iterator;
105         typedef unsigned size_type;
106         typedef int difference_type;
107         typedef std::pair<iterator,iterator> range_type;
108
109         ///////////////////////////////////////////////////////////////////////////
110         ///\name Structors and default members
111         ///@{
112
113         template <class P, class SP, class I, class IP>
114         Parse_Vector_wrapper(Parse_Vector<P,SP,I,IP> const & vector, Container & container);
115
116         // no default constructor
117         // no copy
118         // default destructor
119         // no conversion constructors
120
121         ///@}
122         ///////////////////////////////////////////////////////////////////////////
123         ///\name APacketRegistry.essors
124         ///@{
125
126         size_type size() const;
127         bool empty() const;
128
129         iterator begin() const;
130         iterator end() const;
131         range_type range() const;
132
133         value_type operator[](difference_type i) const;
134
135         ///@}
136         ///////////////////////////////////////////////////////////////////////////
137         ///\name Mutators
138         ///@{
139
140         void shift(iterator pos, size_type n=1);
141         template <class Value>
142         void insert(iterator pos, Value const & t);
143         template <class Value>
144         void insert(iterator pos, size_type n, Value const & t);
145         template <class InputIterator>
146         void insert(iterator pos, InputIterator f, InputIterator l);
147
148         void erase(iterator pos, size_type n=1);
149         void erase(iterator f, iterator l);
150         void clear();
151
152         ///@}
153
154     protected:
155
156     private:
157
158         size_type i_;
159         size_type size_i_;
160         Container & container_;
161     };
162
163 }
164
165 ///////////////////////////////hh.e////////////////////////////////////////
166 //#include "ParseVec.cci"
167 #include "ParseVec.ct"
168 #include "ParseVec.cti"
169 #endif
170
171 \f
172 // Local Variables:
173 // mode: c++
174 // fill-column: 100
175 // c-file-style: "senf"
176 // indent-tabs-mode: nil
177 // ispell-local-dictionary: "american"
178 // End: