ListParser.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 ListParser internal header */
16 
17 #ifndef IH_SENF_Packets_ListParser_
18 #define IH_SENF_Packets_ListParser_ 1
19 
20 // Custom includes
21 #include <boost/iterator/iterator_facade.hpp>
22 
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 
25 namespace senf {
26 namespace detail {
27 
28  /** \brief Internal: Iterator used by ListParser
29 
30  \internal
31  */
32  template <class Container>
33  class ListParser_Iterator
34  : public boost::iterator_facade< ListParser_Iterator<Container>,
35  typename Container::value_type,
36  boost::forward_traversal_tag,
37  typename Container::value_type >,
38 #ifndef DOXYGEN
39  private Container::policy::iterator_data
40 #endif
41  {
42  public:
43  typedef typename Container::value_type value_type;
44 
45  ListParser_Iterator();
46  explicit ListParser_Iterator(Container const & c);
47 
48  PacketParserBase::data_iterator raw() const;
49  PacketParserBase::data_iterator i() const;
50 
51  static ListParser_Iterator & get(typename Container::policy::iterator_data & d);
52  static ListParser_Iterator const & get(typename Container::policy::iterator_data const & d);
53 
54  private:
55  friend class boost::iterator_core_access;
56  friend class ListParser_Container<typename Container::policy>;
57 
58  value_type dereference() const;
59  bool equal(ListParser_Iterator const & other) const;
60  void increment();
61 
62  PacketParserBase::data_iterator i_;
63  Container const * c_;
64  };
65 
66 #ifndef DOXYGEN
67 
68  template <class ElementParser, class AuxPolicy, class AuxTag>
69  struct ListParserPolicy
70  {};
71 
72  template <class ElementParser, typename Enable=void>
73  struct ListParserTraits
74  {
75  template <class AuxPolicy, class AuxTag>
76  struct parser {
77  typedef senf::ListParser<
78  typename ListParserPolicy<ElementParser, AuxPolicy, AuxTag>::type> type;
79  };
80  };
81 
82 # define SENF_PARSER_LIST_I(access, name, size, elt_type) \
83  SENF_PARSER_REQUIRE_VAR(list) \
84  SENF_PARSER_COLLECTION_I( access, \
85  name, \
86  size, \
87  senf::detail::ListParserTraits<elt_type> )
88 
89 #endif
90 
91 }}
92 
93 //-/////////////////////////////////////////////////////////////////////////////////////////////////
94 #endif
95 
96 
97 // Local Variables:
98 // mode: c++
99 // fill-column: 100
100 // comment-column: 40
101 // c-file-style: "senf"
102 // indent-tabs-mode: nil
103 // ispell-local-dictionary: "american"
104 // compile-command: "scons -u test"
105 // End: