VariantParser.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_VariantParser_
18 #define HH_SENF_Packets_VariantParser_ 1
19 
20 #ifndef HH_SENF_Packets_Packets_
21 #error "Don't include 'VariantParser.hh' directly, include 'Packets.hh'"
22 #endif
23 
24 // Custom includes
25 #include <boost/mpl/vector.hpp>
26 #include <boost/mpl/at.hpp>
27 #include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
28 #include <boost/preprocessor/repetition/enum_params.hpp>
29 #include <boost/preprocessor/seq/for_each.hpp>
30 #include "PacketParser.hh"
31 
32 //#include "VariantParser.mpp"
33 //-/////////////////////////////////////////////////////////////////////////////////////////////////
34 
35 namespace senf {
36 
37 # ifndef SENF_LIMIT_PARSE_VARIANT
38 
42 # define SENF_LIMIT_PARSE_VARIANT 6
43 # endif
44 
70  template <class AuxPolicy, class Parsers>
72  : public PacketParserBase, private AuxPolicy
73  {
74  typedef Parsers parsers;
75 
76  public:
78  //\{
79 
81  VariantParser(AuxPolicy policy, data_iterator i, state_type s);
82 
83  size_type bytes() const;
84  void init();
85 
87  typename boost::mpl::at<parsers, boost::mpl::int_<0> >::type>::value
88  + AuxPolicy::aux_bytes;
89 
90  //\}
91  //-////////////////////////////////////////////////////////////////////////
92 
93  unsigned variant() const;
94 
100  template <unsigned N>
101  typename boost::mpl::at< parsers, boost::mpl::int_<N> >::type get() const;
103 
109  template <unsigned N>
110  void init();
111 
115  };
116 
236 # define SENF_PARSER_VARIANT(name, chooser, types) \
237  SENF_PARSER_VARIANT_I(public, name, chooser, types)
238 
245 # define SENF_PARSER_PRIVATE_VARIANT(name, chooser, types) \
246  SENF_PARSER_VARIANT_I(protected, name, chooser, types)
247 }
248 
249 //-/////////////////////////////////////////////////////////////////////////////////////////////////
250 #endif
251 #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_VariantParser_i_)
252 #define HH_SENF_Packets_VariantParser_i_
253 //#include "VariantParser.cci"
254 #include "VariantParser.ct"
255 #include "VariantParser.cti"
256 #endif
257 
258 
259 // Local Variables:
260 // mode: c++
261 // fill-column: 100
262 // comment-column: 40
263 // c-file-style: "senf"
264 // indent-tabs-mode: nil
265 // ispell-local-dictionary: "american"
266 // compile-command: "scons -u test"
267 // End:
size_type bytes() const
unsigned variant() const
Get current variant.
PacketParser public header.
Variant parser.
Return number of bytes to allocate to new object of given type.
VariantParser(data_iterator i, state_type s)
Packet data STL-sequence view.
Definition: PacketData.hh:61
data_iterator i() const
Return beginning of data to parse.
detail::packet::size_type size_type
Unsigned integral type.
Parser Base class.
detail::packet::iterator data_iterator
Raw data iterator type.