VectorParser.ct
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief VectorParser non-inline template implementation */
16 
17 #include "VectorParser.ih"
18 
19 // Custom includes
20 
21 #define prefix_
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::VectorParser<ElementParser,AuxPolicy>
26 
27 template <class ElementParser, class AuxPolicy>
28 prefix_ void senf::VectorParser<ElementParser,AuxPolicy>::init()
29  const
30 {
31  AuxPolicy::aux(0, i(), state());
32  iterator i (begin());
33  iterator const e (end());
34  for (; i!=e; ++i)
35  i->init();
36 }
37 
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 // senf::VectorParser_Container<ElementParser,AuxPolicy>
40 
41 template <class ElementParser, class AuxPolicy>
42 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::init()
43  const
44 {
45  iterator i (begin());
46  iterator const e (end());
47  for (; i!=e; ++i)
48  i->init();
49 }
50 
51 // Mutators
52 
53 template <class ElementParser, class AuxPolicy>
54 prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::iterator
55 senf::VectorParser_Container<ElementParser,AuxPolicy>::shift(iterator pos, size_type n)
56 {
57  size_type ix (std::distance(data().begin(),pos.raw()));
58  setSize(size()+n);
59  data().insert(pos.raw(),n*ElementParser::fixed_bytes,0);
60  return iterator(boost::next(data().begin(),ix),state());
61 }
62 
63 template <class ElementParser, class AuxPolicy>
64 template <class Value>
65 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::insert(iterator pos,
66  size_type n,
67  Value const & t)
68 {
69  for (iterator j (shift(pos,n)); n; --n, ++j)
70  *j << t;
71 }
72 
73 #ifndef DOXYGEN
74 template <class ElementParser, class AuxPolicy>
75 template <class ForwardIterator>
76 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::
77 insert(iterator pos, ForwardIterator f, ForwardIterator l,
78  typename boost::disable_if< boost::is_convertible<ForwardIterator,size_type> >::type *)
79 {
80  for (iterator j (shift(pos,std::distance(f,l))); f!=l; ++f,++j)
81  *j << *f;
82 }
83 #else
84 template <class ElementParser, class AuxPolicy>
85 template <class ForwardIterator>
86 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::
87 insert(iterator pos, ForwardIterator f, ForwardIterator l)
88 {}
89 #endif
90 
91 template <class ElementParser, class AuxPolicy>
92 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::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 AuxPolicy>
101 template <class Value>
102 prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::resize(size_type n,
103  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 //-/////////////////////////////////////////////////////////////////////////////////////////////////
112 #undef prefix_
113 
114 
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: