1129e889965fcaad3c85e33ffba00f487275b753
[senf.git] / senf / Packets / ListBParser.cti
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief ListBParser inline template implementation */
30
31 #include "ListBParser.ih"
32
33 // Custom includes
34
35 #define prefix_ inline
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
37
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 // senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>
40
41 template <class ElementParser, class AuxPolicy>
42 prefix_ senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::ListBParser_Policy()
43 {}
44
45 template <class ElementParser, class AuxPolicy>
46 template <class Arg>
47 prefix_
48 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::ListBParser_Policy(Arg const & arg)
49     : AuxPolicy (arg)
50 {}
51
52 template <class ElementParser, class AuxPolicy>
53 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::size_type
54 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::bytes(data_iterator i, state_type s)
55     const
56 {
57     return AuxPolicy::aux(i,s) + AuxPolicy::aux_bytes;
58 }
59
60 template <class ElementParser, class AuxPolicy>
61 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::size_type
62 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::size(data_iterator i, state_type s)
63     const
64 {
65     parser_type p (*this, i, s);
66     container_type c (p);
67     return std::distance(c.begin(),c.end());
68 }
69
70 template <class ElementParser, class AuxPolicy>
71 prefix_ void senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::init(data_iterator i,
72                                                                              state_type s)
73     const
74 {
75     AuxPolicy::aux(0,i,s);
76 }
77
78 //-/////////////////////////////////////////////////////////////////////////////////////////////////
79 // senf::detail::ListBParser_Policy<ElementParser,BytesParser>
80
81 template <class ElementParser, class AuxPolicy>
82 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::size_type
83 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::bytes(data_iterator i,
84                                                                                    state_type s)
85     const
86 {
87     return AuxPolicy::WrapperPolicy::aux(i,s) + AuxPolicy::aux_bytes;
88 }
89
90 template <class ElementParser, class AuxPolicy>
91 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::size_type
92 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::size(data_iterator i,
93                                                                                   state_type s)
94     const
95 {
96     return n_;
97 }
98
99 template <class ElementParser, class AuxPolicy>
100 prefix_ void senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
101 init(data_iterator i, state_type s)
102 {
103     n_ = 0;
104     container_size_ = s->size();
105     AuxPolicy::WrapperPolicy::aux(0,i,s);
106 }
107
108 template <class ElementParser, class AuxPolicy>
109 prefix_ void
110 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
111 construct(container_type & c)
112     const
113 {}
114
115 template <class ElementParser, class AuxPolicy>
116 prefix_ void
117 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
118 destruct(container_type & c)
119     const
120 {}
121
122 template <class ElementParser, class AuxPolicy>
123 prefix_ void senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
124 erase(container_type & c, data_iterator p)
125 {
126     size_type b (senf::bytes(ElementParser(p,c.state())));
127     AuxPolicy::WrapperPolicy::aux(
128         AuxPolicy::WrapperPolicy::aux(c.i(), c.state())-b, c.i(), c.state());
129     --n_;
130     // The container will be reduced by b bytes directly after this call
131     container_size_ = c.data().size()-b;
132 }
133
134 template <class ElementParser, class AuxPolicy>
135 prefix_ void
136 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
137 insert(container_type & c, data_iterator p)
138 {
139     size_type b (senf::bytes(ElementParser(p,c.state())));
140     AuxPolicy::WrapperPolicy::aux(
141         AuxPolicy::WrapperPolicy::aux(c.i(), c.state())+b, c.i(), c.state());
142     ++n_;
143     container_size_ = c.data().size();
144 }
145
146 template <class ElementParser, class AuxPolicy>
147 prefix_ void
148 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
149 update(container_type const & c)
150     const
151 {
152     if (container_size_ == c.data().size())
153         return;
154 #if 1
155     data_iterator i (AuxPolicy::WrapperPolicy::adjust(c.i(), c.state()));
156     data_iterator j (i);
157     for (size_type n (n_); n; --n, std::advance(j,senf::bytes(ElementParser(j,c.state())))) ;
158     aux( std::distance(i,j), c.i(), c.state() );
159 #else
160     aux ( aux(c.i(),c.state()) + c.data().size() - container_size_, c.i(), c.state() );
161 #endif
162     container_size_ = c.data().size();
163 }
164
165 template <class ElementParser, class AuxPolicy>
166 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
167 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
168 setBegin(container_type const & c, iterator_data & d)
169     const
170 {
171     return AuxPolicy::WrapperPolicy::adjust(c.i(), c.state());
172 }
173
174 template <class ElementParser, class AuxPolicy>
175 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
176 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
177 setEnd(container_type const & c, iterator_data & d)
178     const
179 {
180     return boost::next(AuxPolicy::WrapperPolicy::adjust(c.i(), c.state()),aux(c.i(),c.state()));
181 }
182
183 template <class ElementParser, class AuxPolicy>
184 prefix_ void
185 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
186 setFromPosition(container_type const & c, iterator_data & d, data_iterator p)
187     const
188 {}
189
190 template <class ElementParser, class AuxPolicy>
191 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
192 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
193 next(container_type const & c, iterator_data & d)
194     const
195 {
196     return boost::next( container_type::iterator::get(d).i(),
197                         senf::bytes(ElementParser( container_type::iterator::get(d).i(),
198                                                    c.state() )) );
199 }
200
201 template <class ElementParser, class AuxPolicy>
202 prefix_ typename senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::data_iterator
203 senf::detail::ListBParser_Policy<ElementParser,AuxPolicy>::container_policy::
204 raw(container_type const & c, iterator_data const & d)
205     const
206 {
207     return container_type::iterator::get(d).i();
208 }
209
210 //-/////////////////////////////////////////////////////////////////////////////////////////////////
211 #undef prefix_
212
213 \f
214 // Local Variables:
215 // mode: c++
216 // fill-column: 100
217 // comment-column: 40
218 // c-file-style: "senf"
219 // indent-tabs-mode: nil
220 // ispell-local-dictionary: "american"
221 // compile-command: "scons -u test"
222 // End: