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