VectorParser.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 VectorParser internal header */
16 
17 #ifndef IH_SENF_Packets_VectorParser_
18 #define IH_SENF_Packets_VectorParser_ 1
19 
20 // Custom includes
21 
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 namespace senf {
25 namespace detail {
26 
27 #ifndef DOXYGEN
28 
29  template <class ElementParser, class AuxPolicy, class AuxTag>
30  struct VectorParserPolicy
31  {};
32 
33  template <class ElementParser, class AuxPolicy>
34  struct VectorParserPolicy<ElementParser, AuxPolicy, senf::detail::auxtag::none>
35  {
36  typedef AuxPolicy type;
37  };
38 
39  template <class ElementParser, class AuxPolicy, class Transform>
40  struct VectorParserPolicy<ElementParser, AuxPolicy,
41  senf::detail::auxtag::transform<Transform,
42  senf::detail::auxtag::none> >
43  {
44  typedef senf::detail::TransformAuxParserPolicy<AuxPolicy, Transform> type;
45  };
46 
47  template <unsigned fixedSize>
48  struct VectorParserBytesTransform
49  {
50  typedef PacketParserBase::size_type value_type;
51  static value_type get(value_type v) { return v/fixedSize; }
52  static value_type set(value_type v) { return v*fixedSize; }
53  };
54 
55  template <class ElementParser, class AuxPolicy>
56  struct VectorParserPolicy<ElementParser, AuxPolicy, senf::detail::auxtag::bytes>
57  {
58  typedef senf::detail::TransformAuxParserPolicy<
59  AuxPolicy,
60  VectorParserBytesTransform<ElementParser::fixed_bytes> > type;
61  };
62 
63  template <class ElementParser>
64  struct VectorParserTraits
65  {
66  template <class AuxPolicy, class AuxTag>
67  struct parser {
68  typedef senf::VectorParser<
69  ElementParser,
70  typename VectorParserPolicy<ElementParser, AuxPolicy, AuxTag>::type > type;
71  };
72  };
73 
74 
75 # define SENF_PARSER_VECTOR_I(access, name, size, elt_type) \
76  SENF_PARSER_REQUIRE_VAR(vector) \
77  SENF_PARSER_COLLECTION_I( access, \
78  name, \
79  size, \
80  senf::detail::VectorParserTraits<elt_type> )
81 
82 #endif
83 
84 }}
85 
86 //-/////////////////////////////////////////////////////////////////////////////////////////////////
87 #endif
88 
89 
90 // Local Variables:
91 // mode: c++
92 // fill-column: 100
93 // comment-column: 40
94 // c-file-style: "senf"
95 // indent-tabs-mode: nil
96 // ispell-local-dictionary: "american"
97 // compile-command: "scons -u test"
98 // End: