switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / ListNParser.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 ListNParser inline template implementation */
30
31 #include "ListNParser.ih"
32
33 // Custom includes
34
35 #define prefix_ inline
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
37
38 template <class ElementParser, class AuxPolicy>
39 prefix_ senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::ListNParser_Policy()
40 {}
41
42 template <class ElementParser, class AuxPolicy>
43 prefix_ senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::
44 ListNParser_Policy(parser_policy const & policy)
45   : AuxPolicy(policy)
46 {}
47
48 template <class ElementParser, class AuxPolicy>
49 template <class Arg>
50 prefix_
51 senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::ListNParser_Policy(Arg const & aux)
52     : AuxPolicy (aux)
53 {}
54
55 template <class ElementParser, class AuxPolicy>
56 prefix_ typename senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::size_type
57 senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::bytes(data_iterator i, state_type s)
58     const
59 {
60     container_type c (parser_type(*this, i, s));
61     return std::distance(i,c.end().raw());
62 }
63
64 template <class ElementParser, class AuxPolicy>
65 prefix_ typename senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::size_type
66 senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::size(data_iterator i, state_type s)
67     const
68 {
69     return AuxPolicy::aux(i,s);
70 }
71
72 template <class ElementParser, class AuxPolicy>
73 prefix_ void senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::init(data_iterator i,
74                                                                              state_type s)
75     const
76 {
77     AuxPolicy::aux(0,i,s);
78 }
79
80 template <class ElementParser, class AuxPolicy>
81 prefix_ void
82 senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::construct(container_type & c)
83     const
84 {}
85
86 template <class ElementParser, class AuxPolicy>
87 prefix_ void
88 senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::destruct(container_type & c)
89     const
90 {}
91
92 template <class ElementParser, class AuxPolicy>
93 prefix_ void
94 senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::erase(container_type & c,
95                                                                  data_iterator p)
96     const
97 {
98     this->aux(this->aux(c.i(),c.state())-1,c.i(),c.state());
99 }
100
101 template <class ElementParser, class AuxPolicy>
102 prefix_ void
103 senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::insert(container_type & c,
104                                                                   data_iterator p)
105     const
106 {
107     this->aux(this->aux(c.i(),c.state())+1,c.i(),c.state());
108 }
109
110 template <class ElementParser, class AuxPolicy>
111 prefix_ void
112 senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::update(container_type const & c)
113     const
114 {}
115
116 template <class ElementParser, class AuxPolicy>
117 prefix_ typename senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::data_iterator
118 senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::setBegin(container_type const & c,
119                                                                     iterator_data & d)
120     const
121 {
122     d.n_ = this->aux(c.i(),c.state());
123     return d.n_ ? this->adjust(c.i(),c.state()) : c.data().end();
124 }
125
126 template <class ElementParser, class AuxPolicy>
127 prefix_ typename senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::data_iterator
128 senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::setEnd(container_type const & c,
129                                                                   iterator_data & d)
130     const
131 {
132     d.n_ = 0;
133     return c.data().end();
134 }
135
136 template <class ElementParser, class AuxPolicy>
137 prefix_ typename senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::data_iterator
138 senf::detail::ListNParser_Policy<ElementParser,AuxPolicy>::next(container_type const & c,
139                                                                 iterator_data & d)
140     const
141 {
142     --d.n_;
143     return d.n_ ? boost::next( container_type::iterator::get(d).i(),
144                                senf::bytes(* container_type::iterator::get(d)) )
145         : c.data().end();
146 }
147
148 //-/////////////////////////////////////////////////////////////////////////////////////////////////
149 #undef prefix_
150
151 \f
152 // Local Variables:
153 // mode: c++
154 // fill-column: 100
155 // comment-column: 40
156 // c-file-style: "senf"
157 // indent-tabs-mode: nil
158 // ispell-local-dictionary: "american"
159 // compile-command: "scons -u test"
160 // End: