ListParser.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_ListParser_
18 #define HH_SENF_Packets_ListParser_ 1
19 
20 // Custom includes
21 #include <boost/utility/enable_if.hpp>
22 #include "PacketParser.hh"
23 
24 //#include "ListParser.mpp"
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 
27 namespace senf {
28 
29  namespace detail { template <class Container> class ListParser_Iterator; }
30 
31  template <class ListPolicy>
33 
64  template <class ListPolicy>
65  class ListParser
66  : public PacketParserBase,
67  private ListPolicy
68  {
69  public:
70  typedef ListPolicy policy;
71 
73  ListParser(ListPolicy policy, data_iterator i, state_type s);
75 
78  size_type bytes() const;
79  void init() const;
80 
81  static const size_type init_bytes = ListPolicy::init_bytes;
82 
83  //-////////////////////////////////////////////////////////////////////////
84  // Container interface
85 
86  typedef typename ListPolicy::element_type value_type;
87  typedef typename ListPolicy::container_type container_type;
88 
89  container_type container() const;
90 
91  size_type size() const;
92  bool empty() const;
93 
94  value_type front() const;
95  value_type back() const;
96 
97  template <class InputIterator>
98  void assign(InputIterator first, InputIterator last);
99  template <class Range>
100  void assign(Range const & range);
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  static ListParser & get(ListPolicy & p);
110  static ListParser const & get(ListPolicy const & p);
111 
112  private:
113  template <class Policy> friend class ListParser_Container;
114  };
115 
134  template <class ListPolicy>
136  : private ListPolicy
137  {
138  public:
139  //-////////////////////////////////////////////////////////////////////////
140  // Types
141 
142  typedef ListPolicy policy;
143  typedef typename ListPolicy::parser_type parser_type;
147  typedef typename ListPolicy::element_type value_type;
149  typedef iterator const_iterator;
151 
152  //-////////////////////////////////////////////////////////////////////////
154  //\{
155 
156  // no default constructor
157  // default copy
158  // default destructor
159  // conversion constructors
160 
161  ListParser_Container(parser_type const & list);
163 
164  //\}
165  //-////////////////////////////////////////////////////////////////////////
166 
168  //\{
169 
170  size_type size() const;
171  bool empty() const;
172 
173  iterator begin() const;
174  iterator end() const;
175 
176  value_type front() const;
177  value_type back() const;
178 
179  //\}
181  //\{
182 
183  // All these operations can be quite inefficient depending on the list type
184  value_type shift(iterator pos, size_type n=1);
185  template <class Value>
186  void insert(iterator pos, Value const & t);
187  template <class Value>
188  void insert(iterator pos, size_type n, Value const & t);
189  template <class ForwardIterator>
190 # ifndef DOXYGEN
191  void insert(iterator pos, ForwardIterator f, ForwardIterator l,
192  typename boost::disable_if< boost::is_convertible<ForwardIterator,size_type> >::type * = 0);
193 # else
194  void insert(iterator pos, ForwardIterator f, ForwardIterator l);
195 # endif
196 
197  void erase(iterator pos, size_type n=1);
198  void erase(iterator f, iterator l);
199  void clear();
200 
201  template <class Value> void push_back (Value const & value, size_type n=1);
202  value_type push_back_space (size_type n=1);
203  template <class Value> void push_front (Value const & value, size_type n=1);
204  value_type push_front_space (size_type n=1);
205  void resize (size_type n);
206  template <class Value> void resize (size_type n, Value value);
207 
208  //\}
209 
211  //\{
212 
213  parser_type parser() const;
214  data_iterator i() const;
215  state_type state() const;
216  PacketData & data() const;
217 
218  size_type bytes() const;
219  void init() const;
220 
221  //\}
222 
223  private:
225 
226  state_type state_;
227  size_type i_;
228  };
229 
306 # define SENF_PARSER_LIST(name, size, elt_type) \
307  SENF_PARSER_LIST_I(public, name, size, elt_type)
308 
316 # define SENF_PARSER_PRIVATE_LIST(name, size, elt_type) \
317  SENF_PARSER_LIST_I(protected, name, size, elt_type)
318 
319 
320  template <class ListPolicy, class OutputIterator>
321  void copy(ListParser_Container<ListPolicy> container, OutputIterator result);
322 
323 }
324 
325 //-/////////////////////////////////////////////////////////////////////////////////////////////////
326 #endif
327 #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_ListParser_i_)
328 #define HH_SENF_Packets_ListParser_i_
329 //#include "ListParser.cci"
330 #include "ListParser.ct"
331 #include "ListParser.cti"
332 #endif
333 
334 
335 // Local Variables:
336 // mode: c++
337 // fill-column: 100
338 // c-file-style: "senf"
339 // indent-tabs-mode: nil
340 // ispell-local-dictionary: "american"
341 // compile-command: "scons -u test"
342 // comment-column: 40
343 // End:
ListPolicy::element_type value_type
Definition: ListParser.hh:147
PacketParser public header.
ListPolicy::container_type container_type
Definition: ListParser.hh:87
void init()
PacketParserBase::state_type state_type
Definition: ListParser.hh:150
bool empty()
void copy(ListParser< ListPolicy > const &listParser, OutputIterator result)
Definition: algorithms.hh:58
detail::ListParser_Iterator< ListParser_Container > iterator
Definition: ListParser.hh:148
unspecified_keyword_type parser
u8 data[SPECTRAL_HT20_NUM_BINS]
Return number of bytes to allocate to new object of given type.
PacketParserBase::size_type bytes(Parser const &p)
Return raw size parsed by the given parser object.
PacketParserBase::size_type size_type
Definition: ListParser.hh:145
PacketParserBase::data_iterator data_iterator
Definition: ListParser.hh:144
Packet data STL-sequence view.
Definition: PacketData.hh:61
detail::packet::difference_type difference_type
Signed integral type.
ListPolicy::element_type value_type
Definition: ListParser.hh:86
::phoenix::function< detail::push_back > const push_back
PacketParserBase::difference_type difference_type
Definition: ListParser.hh:146
detail::packet::size_type size_type
Unsigned integral type.
ListPolicy::parser_type parser_type
Definition: ListParser.hh:143
Parser Base class.
Arbitrary sequential element collection.
Definition: ListParser.hh:65
::phoenix::function< detail::clear > const clear
ListParser container wrapper.
Definition: ListParser.hh:32
ListPolicy policy
Definition: ListParser.hh:70
detail::packet::iterator data_iterator
Raw data iterator type.