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