GenericTLV.ih
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 GenericTLV internal header */
16 
17 #ifndef IH_SENF_Packets_GenericTLV_
18 #define IH_SENF_Packets_GenericTLV_ 1
19 
20 // Custom includes
21 
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 namespace senf {
25 
26  template <class Base>
27  class GenericTLVParserBase;
28 
29  template <class ListPolicy>
30  class TLVListParser;
31 
32 namespace detail {
33 
34  template <class BaseParser>
35  struct GenericTLVParserRegistry_EntryBase {
36  virtual ~GenericTLVParserRegistry_EntryBase() {}
37  virtual void dump(GenericTLVParserBase<BaseParser> const & parser, std::ostream & os) const = 0;
38  virtual PacketParserBase::size_type bytes(GenericTLVParserBase<BaseParser> const & parser) const = 0;
39  virtual std::string name() const = 0;
40  };
41 
42  template <class BaseParser, class Parser>
43  struct GenericTLVParserRegistry_Entry
44  : GenericTLVParserRegistry_EntryBase<BaseParser>
45  {
46  virtual void dump(GenericTLVParserBase<BaseParser> const & parser, std::ostream & os) const;
47  virtual PacketParserBase::size_type bytes(GenericTLVParserBase<BaseParser> const & parser) const;
48  virtual std::string name() const;
49  };
50 
51 
52  // Helper Functor for STL-compatible predicate (E.g. find_if, for_each ...)
53  template <class BaseParser, class Parser>
54  struct Predicate
55  {
56  bool operator() (BaseParser const & p) const {
57  return p.template is<Parser>();
58  }
59  };
60 
61  struct GenericTLVParserBaseTag {};
62 
63  template <class TLVParser>
64  struct ListParserTraits<TLVParser, typename boost::enable_if<boost::is_base_of<GenericTLVParserBaseTag, TLVParser> >::type>
65  {
66  template <class AuxPolicy, class AuxTag>
67  struct parser {
68  typedef senf::TLVListParser<
69  typename ListParserPolicy<TLVParser, AuxPolicy, AuxTag>::type> type;
70  };
71  };
72 
73 }}
74 
75 
76 //-/////////////////////////////////////////////////////////////////////////////////////////////////
77 #endif
78 
79 
80 // Local Variables:
81 // mode: c++
82 // fill-column: 100
83 // comment-column: 40
84 // c-file-style: "senf"
85 // indent-tabs-mode: nil
86 // ispell-local-dictionary: "american"
87 // compile-command: "scons -u test"
88 // End: