VectorParser.hh
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 
17 #ifndef HH_SENF_Packets_VectorParser_
18 #define HH_SENF_Packets_VectorParser_ 1
19 
20 // Custom includes
21 #include <boost/type_traits/is_convertible.hpp>
22 #include "PacketParser.hh"
23 #include "ArrayParser.hh" // for ArrayParser_iterator
24 #include "AuxParser.hh" // for the AuxPolicies
25 
26 //#include "VectorParser.mpp"
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
28 
29 namespace senf {
30 
31  template <class ElementParser, class AuxPolicy> class VectorParser_Container;
32 
57  template <class ElementParser, class AuxPolicy>
58  struct VectorParser
59  : public PacketParserBase,
60  private AuxPolicy
61  {
63  VectorParser(AuxPolicy policy, data_iterator i, state_type s);
65 
68  size_type bytes() const;
69  void init() const;
70 
71  static const size_type init_bytes = AuxPolicy::aux_bytes;
72 
73  //-////////////////////////////////////////////////////////////////////////
74  // Container interface
75 
76  typedef ElementParser value_type;
78  typedef iterator const_iterator;
80 
81  container_type container() const;
82 
83  size_type size() const;
84  bool empty() const;
85 
86  iterator begin() const;
87  iterator end() const;
88 
89  value_type operator[](difference_type i) const;
90  value_type front() const;
91  value_type back() const;
92 
93  // Mutators
94 
95  // The mutators provided here are those which don't take an iterator argument.
96  // If you need to pass an iterator it is much simpler and cleaner to use the
97  // 'container' wrapper
98 
99  template <class InputIterator>
100  void assign(InputIterator first, InputIterator last);
101 
102  template <class Value> void push_back (Value const & value, size_type n=1) const;
103  value_type push_back_space (size_type n=1) const;
104  template <class Value> void push_front (Value const & value, size_type n=1) const;
105  value_type push_front_space (size_type n=1) const;
106  void resize (size_type n) const;
107  template <class Value> void resize (size_type n, Value value) const;
108 
109  private:
110 
111  friend class VectorParser_Container<ElementParser,AuxPolicy>;
112  };
113 
132  template <class ElementParser, class AuxPolicy>
134  : private AuxPolicy::WrapperPolicy
135  {
136  public:
137  //-////////////////////////////////////////////////////////////////////////
138  // Types
139 
144  typedef ElementParser value_type;
146  typedef iterator const_iterator;
148 
149  //-////////////////////////////////////////////////////////////////////////
151  //\{
152 
153  // no default constructor
154  // default copy
155  // default destructor
156  // conversion constructors
157 
158  VectorParser_Container(parser_type const & vector);
159 
160  //\}
161  //-////////////////////////////////////////////////////////////////////////
162 
164  //\{
165 
166  size_type size() const;
167  bool empty() const;
168 
169  iterator begin() const;
170  iterator end() const;
171 
172  value_type operator[](difference_type i) const;
173  value_type front() const;
174  value_type back() const;
175 
176  //\}
178  //\{
179 
180  iterator shift(iterator pos, size_type n=1);
181  template <class Value>
182  void insert(iterator pos, Value const & t);
183  template <class Value>
184  void insert(iterator pos, size_type n, Value const & t);
185 # ifndef DOXYGEN
186  template <class ForwardIterator>
187  void insert(iterator pos, ForwardIterator f, ForwardIterator l,
188  typename boost::disable_if< boost::is_convertible<ForwardIterator,size_type> >::type * = 0);
189 # else
190  template <class ForwardIterator>
191  void insert(iterator pos, ForwardIterator f, ForwardIterator l);
192 # endif
193 
194  void erase(iterator pos, size_type n=1);
195  void erase(iterator f, iterator l);
196  void clear();
197 
198  template <class Value> void push_back (Value const & value, size_type n=1);
199  value_type push_back_space (size_type n=1);
200  template <class Value> void push_front (Value const & value, size_type n=1);
201  value_type push_front_space (size_type n=1);
202  void resize (size_type n);
203  template <class Value> void resize (size_type n, Value value);
204 
205  //\}
206 
208  //\{
209 
210  parser_type parser() const;
211  data_iterator i() const;
212  state_type state() const;
213  PacketData & data() const;
214 
215  size_type bytes() const;
216  void init() const;
217 
218  //\}
219 
220  protected:
221 
222  private:
223  void setSize(size_type value);
224 
225  state_type state_;
226  size_type i_;
227  };
228 
289 # define SENF_PARSER_VECTOR(name, size, elt_type) \
290  SENF_PARSER_VECTOR_I(public, name, size, elt_type)
291 
299 # define SENF_PARSER_PRIVATE_VECTOR(name, size, elt_type) \
300  SENF_PARSER_VECTOR_I(protected, name, size, elt_type)
301 }
302 
303 //-/////////////////////////////////////////////////////////////////////////////////////////////////
304 #endif
305 #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_VectorParser_i_)
306 #define HH_SENF_Packets_VectorParser_i_
307 //#include "VectorParser.cci"
308 #include "VectorParser.ct"
309 #include "VectorParser.cti"
310 #endif
311 
312 
313 // Local Variables:
314 // mode: c++
315 // fill-column: 100
316 // c-file-style: "senf"
317 // indent-tabs-mode: nil
318 // ispell-local-dictionary: "american"
319 // compile-command: "scons -u test"
320 // comment-column: 40
321 // End:
void push_front(Value const &value, size_type n=1) const
PacketParserBase::difference_type difference_type
PacketParser public header.
container_type container() const
PacketParserBase::size_type size_type
detail::ArrayParser_iterator< value_type > iterator
Definition: VectorParser.hh:77
VectorParser_Container< ElementParser, AuxPolicy > container_type
Definition: VectorParser.hh:79
value_type push_back_space(size_type n=1) const
unspecified_keyword_type parser
size_type size() const
void init() const
Return number of bytes to allocate to new object of given type.
iterator end() const
void push_back(Value const &value, size_type n=1) const
value_type operator[](difference_type i) const
PacketParserBase::state_type state_type
Packet data STL-sequence view.
Definition: PacketData.hh:61
detail::packet::difference_type difference_type
Signed integral type.
data_iterator i() const
Return beginning of data to parse.
bool empty() const
value_type back() const
value_type push_front_space(size_type n=1) const
size_type bytes() const
AuxParser public header.
detail::packet::size_type size_type
Unsigned integral type.
PacketParserBase::data_iterator data_iterator
iterator const_iterator
Definition: VectorParser.hh:78
void assign(InputIterator first, InputIterator last)
ElementParser value_type
Definition: VectorParser.hh:76
iterator begin() const
VectorParser container wrapper.
Definition: VectorParser.hh:31
VectorParser< ElementParser, AuxPolicy > parser_type
ArrayParser public header.
Collection of fixed-size elements.
Definition: VectorParser.hh:58
detail::ArrayParser_iterator< value_type > iterator
VectorParser(data_iterator i, state_type s)
Parser Base class.
PacketData & data() const
Access the packets raw data container.
state_type state() const
Return state of this parser.
::phoenix::function< detail::clear > const clear
detail::packet::iterator data_iterator
Raw data iterator type.
void resize(size_type n) const
value_type front() const