3a8a3e006507dbc6f5d6e96f82a7e2c2a0e6c5b6
[senf.git] / Packets / ParseListS.cti
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 // Definition of inline template functions
24
25 #include "ParseListS.ih"
26
27 // Custom includes
28 #include <boost/assert.hpp>
29
30 #define prefix_ inline
31 ///////////////////////////////cti.p///////////////////////////////////////
32
33 template <class Parser, class Sentinel, class Iterator, class IPacket>
34 prefix_ senf::Parse_ListS<Parser,Sentinel,Iterator,IPacket>::Parse_ListS()
35 {}
36
37 template <class Parser, class Sentinel, class Iterator, class IPacket>
38 prefix_
39 senf::Parse_ListS<Parser,Sentinel,Iterator,IPacket>::Parse_ListS(Iterator const & i)
40     : ParserBase<Iterator,IPacket>(i)
41 {}
42
43 template <class Parser, class Sentinel, class Iterator, class IPacket>
44 prefix_ typename senf::Parse_ListS<Parser,Sentinel,Iterator,IPacket>::size_type
45 senf::Parse_ListS<Parser,Sentinel,Iterator,IPacket>::size()
46     const
47 {
48     return std::distance(begin(),end());
49 }
50
51 template <class Parser, class Sentinel, class Iterator, class IPacket>
52 prefix_ bool senf::Parse_ListS<Parser,Sentinel,Iterator,IPacket>::empty()
53     const
54 {
55     return begin()==end();
56 }
57
58 template <class Parser, class Sentinel, class Iterator, class IPacket>
59 prefix_ typename senf::Parse_ListS<Parser,Sentinel,Iterator,IPacket>::iterator
60 senf::Parse_ListS<Parser,Sentinel,Iterator,IPacket>::begin()
61     const
62 {
63     return iterator(this->i());
64 }
65
66 template <class Parser, class Sentinel, class Iterator, class IPacket>
67 prefix_ typename senf::Parse_ListS<Parser,Sentinel,Iterator,IPacket>::iterator
68 senf::Parse_ListS<Parser,Sentinel,Iterator,IPacket>::end()
69     const
70 {
71     return iterator();
72 }
73
74 template <class Parser, class Sentinel, class Iterator, class IPacket>
75 prefix_ typename senf::Parse_ListS<Parser,Sentinel,Iterator,IPacket>::range_type
76 senf::Parse_ListS<Parser,Sentinel,Iterator,IPacket>::range()
77     const
78 {
79     return std::make_pair(begin(),end());
80 }
81
82 template <class Parser, class Sentinel, class Iterator, class IPacket>
83 prefix_ typename senf::Parse_ListS<Parser,Sentinel,Iterator,IPacket>::range_type
84 senf::Parse_ListS<Parser,Sentinel,Iterator,IPacket>::value()
85     const
86 {
87     return range();
88 }
89
90 ///////////////////////////////////////////////////////////////////////////
91 // senf::impl::Parse_ListS_iterator<Parser,Sentinel,Iterator>
92
93 template <class Parser, class Sentinel, class Iterator>
94 prefix_
95 senf::impl::Parse_ListS_iterator<Parser,Sentinel,Iterator>::Parse_ListS_iterator()
96     : i_(), atEnd_(true)
97 {}
98
99 template <class Parser, class Sentinel, class Iterator>
100 prefix_ 
101 senf::impl::Parse_ListS_iterator<Parser,Sentinel,Iterator>::
102 Parse_ListS_iterator(Iterator const & i)
103     : i_(i), atEnd_(false)
104 {
105     atEnd_ = Sentinel::check(dereference());
106 }
107
108 template <class Parser, class Sentinel, class Iterator>
109 prefix_ Iterator senf::impl::Parse_ListS_iterator<Parser,Sentinel,Iterator>::raw()
110     const
111 {
112     return i_;
113 }
114
115 template <class Parser, class Sentinel, class Iterator>
116 prefix_ Parser
117 senf::impl::Parse_ListS_iterator<Parser,Sentinel,Iterator>::dereference()
118     const
119 {
120     return Parser(i_);
121 }
122
123 template <class Parser, class Sentinel, class Iterator>
124 prefix_ bool senf::impl::Parse_ListS_iterator<Parser,Sentinel,Iterator>::
125 equal(Parse_ListS_iterator const & other)
126     const
127 {
128     // !! We cannot compare the to iterators if either
129     // !! Iterator is atEnd_, since one of the iterators
130     // !! might be a default-constructed iterator and
131     // !! iterators can only be compared with each other
132     // !! if both point to the *same* valid container
133     if (atEnd_ || other.atEnd_) return atEnd_ == other.atEnd_;
134     return i_ == other.i_;
135 }
136
137 template <class Parser, class Sentinel, class Iterator>
138 prefix_ void senf::impl::Parse_ListS_iterator<Parser,Sentinel,Iterator>::increment()
139 {
140     BOOST_ASSERT( !atEnd_ );
141     i_ += dereference().bytes();
142     atEnd_ = Sentinel::check(dereference());
143 }
144
145 ///////////////////////////////////////////////////////////////////////////
146 // senf::Parse_ListS_wrapper<Parser,Sentinel,Container>
147
148 template <class Parser, class Sentinel, class Container>
149 template <class P, class S, class I, class IP>
150 prefix_ senf::Parse_ListS_wrapper<Parser,Sentinel,Container>::
151 Parse_ListS_wrapper(Parse_ListS<P,S,I,IP> const & list, Container & container)
152     : i_(list.i()-container.begin()), container_(container)
153 {}
154
155 template <class Parser, class Sentinel, class Container>
156 prefix_ typename senf::Parse_ListS_wrapper<Parser,Sentinel,Container>::size_type
157 senf::Parse_ListS_wrapper<Parser,Sentinel,Container>::size()
158     const
159 {
160     return std::distance(begin(),end());
161 }
162
163 template <class Parser, class Sentinel, class Container>
164 prefix_ bool senf::Parse_ListS_wrapper<Parser,Sentinel,Container>::empty()
165     const
166 {
167     return begin()==end();
168 }
169
170 template <class Parser, class Sentinel, class Container>
171 prefix_ typename senf::Parse_ListS_wrapper<Parser,Sentinel,Container>::iterator
172 senf::Parse_ListS_wrapper<Parser,Sentinel,Container>::begin()
173     const
174 {
175     return iterator(container_.begin()+i_);
176 }
177
178 template <class Parser, class Sentinel, class Container>
179 prefix_ typename senf::Parse_ListS_wrapper<Parser,Sentinel,Container>::iterator
180 senf::Parse_ListS_wrapper<Parser,Sentinel,Container>::end()
181     const
182 {
183     return iterator();
184 }
185
186 template <class Parser, class Sentinel, class Container>
187 prefix_ typename senf::Parse_ListS_wrapper<Parser,Sentinel,Container>::range_type
188 senf::Parse_ListS_wrapper<Parser,Sentinel,Container>::range()
189     const
190 {
191     return std::make_pair(begin(),end());
192 }
193
194 ///////////////////////////////cti.e///////////////////////////////////////
195 #undef prefix_
196
197 \f
198 // Local Variables:
199 // mode: c++
200 // c-file-style: "senf"
201 // End: