80a49147219cfc70fd0ac5a09ff2c9693376e8ec
[senf.git] / senf / Packets / ListBParser.cti
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.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 /** \file
24     \brief ListBParser inline template implementation */
25
26 #include "ListBParser.ih"
27
28 // Custom includes
29
30 #define prefix_ inline
31 ///////////////////////////////cti.p///////////////////////////////////////
32
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>
35
36 template <class ElementParser, class AuxPolicy>
37 prefix_ senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::ListBParser_Policy()
38 {}
39
40 template <class ElementParser, class AuxPolicy>
41 template <class Arg>
42 prefix_
43 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::ListBParser_Policy(Arg const & arg)
44     : AuxPolicy (arg)
45 {}
46
47 template <class ElementParser, class AuxPolicy>
48 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::size_type
49 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::bytes(data_iterator i, state_type s)
50     const
51 {
52     return AuxPolicy::aux(i,s) + AuxPolicy::aux_bytes;
53 }
54
55 template <class ElementParser, class AuxPolicy>
56 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::size_type
57 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::size(data_iterator i, state_type s)
58     const
59 {
60     parser_type p (*this, i, s);
61     container_type c (p);
62     return std::distance(c.begin(),c.end());
63 }
64
65 template <class ElementParser, class AuxPolicy>
66 prefix_ void senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::init(data_iterator i,
67                                                                              state_type s)
68     const
69 {
70     AuxPolicy::aux(0,i,s);
71 }
72
73 ///////////////////////////////////////////////////////////////////////////
74 // senf::detail::ListBParser_Policy<ElementParser,BytesParser>
75
76 template <class ElementParser, class AuxPolicy>
77 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::size_type
78 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::bytes(data_iterator i,
79                                                                                    state_type s)
80     const
81 {
82     return AuxPolicy::aux(i,s) + AuxPolicy::aux_bytes;
83 }
84
85 template <class ElementParser, class AuxPolicy>
86 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::size_type
87 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::size(data_iterator i,
88                                                                                   state_type s)
89     const
90 {
91     return n_;
92 }
93
94 template <class ElementParser, class AuxPolicy>
95 prefix_ void senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
96 init(data_iterator i, state_type s)
97 {
98     n_ = 0;
99     container_size_ = s->size();
100     AuxPolicy::aux(0,i,s);
101 }
102
103 template <class ElementParser, class AuxPolicy>
104 prefix_ void
105 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
106 construct(container_type & c)
107     const
108 {}
109
110 template <class ElementParser, class AuxPolicy>
111 prefix_ void
112 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
113 destruct(container_type & c)
114     const
115 {}
116
117 template <class ElementParser, class AuxPolicy>
118 prefix_ void senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
119 erase(container_type & c, data_iterator p)
120 {
121     size_type b (senf::bytes(ElementParser(p,c.state())));
122     AuxPolicy::aux( AuxPolicy::aux(c.i(), c.state())-b, c.i(), c.state());
123     --n_;
124     // The container will be reduced by b bytes directly after this call
125     container_size_ = c.data().size()-b;
126 }
127
128 template <class ElementParser, class AuxPolicy>
129 prefix_ void
130 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
131 insert(container_type & c, data_iterator p)
132 {
133     size_type b (senf::bytes(ElementParser(p,c.state())));
134     AuxPolicy::aux( AuxPolicy::aux(c.i(), c.state())+b, c.i(), c.state());
135     ++n_;
136     container_size_ = c.data().size();
137 }
138
139 template <class ElementParser, class AuxPolicy>
140 prefix_ void
141 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
142 update(container_type const & c)
143     const
144 {
145     if (container_size_ == c.data().size())
146         return;
147 #if 1
148     data_iterator i (AuxPolicy::adjust(c.i(), c.state()));
149     data_iterator j (i);
150     for (size_type n (n_); n; --n, std::advance(j,senf::bytes(ElementParser(j,c.state())))) ;
151     aux( std::distance(i,j), c.i(), c.state() );
152 #else
153     aux ( aux(c.i(),c.state()) + c.data().size() - container_size_, c.i(), c.state() );
154 #endif
155     container_size_ = c.data().size();
156 }
157
158 template <class ElementParser, class AuxPolicy>
159 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
160 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
161 setBegin(container_type const & c, iterator_data & d)
162     const
163 {
164     return AuxPolicy::adjust(c.i(), c.state());
165 }
166
167 template <class ElementParser, class AuxPolicy>
168 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
169 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
170 setEnd(container_type const & c, iterator_data & d)
171     const
172 {
173     return boost::next(AuxPolicy::adjust(c.i(), c.state()),aux(c.i(),c.state()));
174 }
175
176 template <class ElementParser, class AuxPolicy>
177 prefix_ void
178 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
179 setFromPosition(container_type const & c, iterator_data & d, data_iterator p)
180     const
181 {}
182
183 template <class ElementParser, class AuxPolicy>
184 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
185 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
186 next(container_type const & c, iterator_data & d)
187     const
188 {
189     return boost::next( container_type::iterator::get(d).i(),
190                         senf::bytes(ElementParser( container_type::iterator::get(d).i(), 
191                                                    c.state() )) );
192 }
193
194 template <class ElementParser, class AuxPolicy>
195 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
196 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
197 raw(container_type const & c, iterator_data const & d)
198     const
199 {
200     return container_type::iterator::get(d).i();
201 }
202
203 ///////////////////////////////cti.e///////////////////////////////////////
204 #undef prefix_
205
206 \f
207 // Local Variables:
208 // mode: c++
209 // fill-column: 100
210 // comment-column: 40
211 // c-file-style: "senf"
212 // indent-tabs-mode: nil
213 // ispell-local-dictionary: "american"
214 // compile-command: "scons -u test"
215 // End: