added first structure for Transport-Stream Packets
[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 /** \file
24     \brief ParseVec non-inline template implementation */
25
26 #include "ParseVec.ih"
27
28 // Custom includes
29
30 #define prefix_
31 ///////////////////////////////ct.p////////////////////////////////////////
32
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::Parse_Vector<ElementParser,Sizer>
35
36 template <class ElementParser, class Sizer>
37 prefix_ void senf::Parse_Vector<ElementParser,Sizer>::init()
38     const
39 {
40     sizer_.init(i(),state());
41     iterator i (begin());
42     iterator const e (end());
43     for (; i!=e; ++i)
44         i->init();
45 }
46
47 ///////////////////////////////////////////////////////////////////////////
48 // senf::Parse_Vector_Container<ElementParser,Sizer>
49
50 template <class ElementParser, class Sizer>
51 prefix_ void senf::Parse_Vector_Container<ElementParser,Sizer>::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 Sizer>
63 prefix_ typename senf::Parse_Vector_Container<ElementParser,Sizer>::iterator
64 senf::Parse_Vector_Container<ElementParser,Sizer>::shift(iterator pos, size_type n)
65 {
66     size_type ix (std::distance(data().begin(),pos.raw()));
67     data().insert(pos.raw(),n*ElementParser::fixed_bytes,0);
68     setSize(size()+n);
69     return iterator(boost::next(data().begin(),ix),state());
70 }
71
72 template <class ElementParser, class Sizer>
73 template <class Value>
74 prefix_ void senf::Parse_Vector_Container<ElementParser,Sizer>::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 template <class ElementParser, class Sizer>
83 template <class ForwardIterator>
84 prefix_ void senf::Parse_Vector_Container<ElementParser,Sizer>::
85 insert(iterator pos, ForwardIterator f, ForwardIterator l,
86        typename boost::disable_if< boost::is_convertible<ForwardIterator,size_type> >::type *)
87 {
88     for (iterator j (shift(pos,std::distance(f,l))); f!=l; ++f,++j)
89         *j << *f;
90 }
91
92 template <class ElementParser, class Sizer>
93 prefix_ void senf::Parse_Vector_Container<ElementParser,Sizer>::resize(size_type n)
94 {
95     if (size()>=n)
96         erase(boost::next(begin(),n),end());
97     else
98         push_back_space(n-size());
99 }
100
101 template <class ElementParser, class Sizer>
102 template <class Value>
103 prefix_ void senf::Parse_Vector_Container<ElementParser,Sizer>::resize(size_type n, Value value)
104 {
105     if (size()>=n)
106         erase(boost::next(begin(),n),end());
107     else
108         push_back(value,n-size());
109 }
110
111 ///////////////////////////////ct.e////////////////////////////////////////
112 #undef prefix_
113
114 \f
115 // Local Variables:
116 // mode: c++
117 // fill-column: 100
118 // c-file-style: "senf"
119 // indent-tabs-mode: nil
120 // ispell-local-dictionary: "american"
121 // compile-command: "scons -u test"
122 // comment-column: 40
123 // End: