9df474ba76b5e627239fb337de0218ae8c24eca0
[senf.git] / senf / Packets / VectorParser.ct
1 // $Id$
2 //
3 // Copyright (C) 2006
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 VectorParser non-inline template implementation */
30
31 #include "VectorParser.ih"
32
33 // Custom includes
34
35 #define prefix_
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
37
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 // senf::VectorParser<ElementParser,AuxPolicy>
40
41 template <class ElementParser, class AuxPolicy>
42 prefix_ void senf::VectorParser<ElementParser,AuxPolicy>::init()
43     const
44 {
45     aux(0, i(), state());
46     iterator i (begin());
47     iterator const e (end());
48     for (; i!=e; ++i)
49         i->init();
50 }
51
52 //-/////////////////////////////////////////////////////////////////////////////////////////////////
53 // senf::VectorParser_Container<ElementParser,AuxPolicy>
54
55 template <class ElementParser, class AuxPolicy>
56 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::init()
57     const
58 {
59     iterator i (begin());
60     iterator const e (end());
61     for (; i!=e; ++i)
62         i->init();
63 }
64
65 // Mutators
66
67 template <class ElementParser, class AuxPolicy>
68 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::iterator
69 senf::VectorParser_Container<ElementParser,AuxPolicy>::shift(iterator pos, size_type n)
70 {
71     size_type ix (std::distance(data().begin(),pos.raw()));
72     setSize(size()+n);
73     data().insert(pos.raw(),n*ElementParser::fixed_bytes,0);
74     return iterator(boost::next(data().begin(),ix),state());
75 }
76
77 template <class ElementParser, class AuxPolicy>
78 template <class Value>
79 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::insert(iterator pos,
80                                                                        size_type n,
81                                                                        Value const & t)
82 {
83     for (iterator j (shift(pos,n)); n; --n, ++j)
84         *j << t;
85 }
86
87 #ifndef DOXYGEN
88 template <class ElementParser, class AuxPolicy>
89 template <class ForwardIterator>
90 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::
91 insert(iterator pos, ForwardIterator f, ForwardIterator l,
92        typename boost::disable_if< boost::is_convertible<ForwardIterator,size_type> >::type *)
93 {
94     for (iterator j (shift(pos,std::distance(f,l))); f!=l; ++f,++j)
95         *j << *f;
96 }
97 #else
98 template <class ElementParser, class AuxPolicy>
99 template <class ForwardIterator>
100 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::
101 insert(iterator pos, ForwardIterator f, ForwardIterator l)
102 {}
103 #endif
104
105 template <class ElementParser, class AuxPolicy>
106 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::resize(size_type n)
107 {
108     if (size()>=n)
109         erase(boost::next(begin(),n),end());
110     else
111         push_back_space(n-size());
112 }
113
114 template <class ElementParser, class AuxPolicy>
115 template <class Value>
116 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::resize(size_type n,
117                                                                            Value value)
118 {
119     if (size()>=n)
120         erase(boost::next(begin(),n),end());
121     else
122         push_back(value,n-size());
123 }
124
125 //-/////////////////////////////////////////////////////////////////////////////////////////////////
126 #undef prefix_
127
128 \f
129 // Local Variables:
130 // mode: c++
131 // fill-column: 100
132 // c-file-style: "senf"
133 // indent-tabs-mode: nil
134 // ispell-local-dictionary: "american"
135 // compile-command: "scons -u test"
136 // comment-column: 40
137 // End: