SafeIterator.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_SafeIterator_
18 #define HH_SENF_Packets_SafeIterator_ 1
19 
20 #ifndef HH_SENF_Packets_Packets_
21 #error "Don't include 'SafeIterator.hh' directly, include 'Packets.hh'"
22 #endif
23 
24 // Custom includes
25 #include <boost/iterator/iterator_facade.hpp>
26 #include <senf/Utils/safe_bool.hh>
27 
28 #include "SafeIterator.ih"
29 //-/////////////////////////////////////////////////////////////////////////////////////////////////
30 
31 namespace senf {
32 
33  class PacketParserBase;
34 
35 
48  : public boost::iterator_facade< safe_data_iterator,
49  PacketData::value_type,
50  boost::random_access_traversal_tag >,
51  public senf::detail::packet::safe_data_iterator_base<PacketData::iterator>
52  {
53  typedef senf::detail::packet::safe_data_iterator_base<PacketData::iterator> Base;
54  public:
56 
62  explicit safe_data_iterator(PacketParserBase const & parser);
64 
68 
72 
75  PacketData & data() const;
76 
77  private:
78  friend class boost::iterator_core_access;
79 
80  // iterator_facade interface
81 
82  value_type & dereference() const;
83  bool equal(safe_data_iterator const & other) const;
84  difference_type distance_to(safe_data_iterator const & other) const;
85  void increment();
86  void decrement();
87  void advance(difference_type n);
88  };
89 
107  template <class Parser>
109  : public safe_bool< SafePacketParserWrapper<Parser> >
110  {
111  public:
112  //-////////////////////////////////////////////////////////////////////////
113  // Types
114 
115  //-////////////////////////////////////////////////////////////////////////
117  //\{
118 
119  // default copy constructor
120  // default copy assignment
121  // default destructor
123 
124  // conversion constructors
126 
127  SafePacketParserWrapper & operator=(Parser parser);
128 
129  //\}
130  //-////////////////////////////////////////////////////////////////////////
131 
132  Parser & operator*() const;
133 
135  Parser * operator->() const;
136 
138  bool boolean_test() const;
139 
140  protected:
141 
142  private:
143  mutable boost::optional<Parser> parser_;
145  };
146 
147 }
148 
149 //-/////////////////////////////////////////////////////////////////////////////////////////////////
150 #endif
151 #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_SafeIterator_i_)
152 #define HH_SENF_Packets_SafeIterator_i_
153 #include "SafeIterator.cci"
154 //#include "SafeIterator.ct"
155 #include "SafeIterator.cti"
156 #endif
157 
158 
159 // Local Variables:
160 // mode: c++
161 // fill-column: 100
162 // comment-column: 40
163 // c-file-style: "senf"
164 // indent-tabs-mode: nil
165 // ispell-local-dictionary: "american"
166 // compile-command: "scons -u test"
167 // End:
safe_data_iterator & operator=(PacketData::iterator i)
Assign iterator.
unspecified_keyword_type parser
senf::detail::packet::iterator iterator
Definition: PacketData.hh:68
RestrictedInt< Base, Tag > operator*(OtherType a, RestrictedInt< Base, Tag > b)
Packet data STL-sequence view.
Definition: PacketData.hh:61
PacketData::size_type size_type
Definition: SafeIterator.hh:55
Re-validating data iterator.
Definition: SafeIterator.hh:47
PacketData & data() const
Access data container.
senf::detail::packet::size_type size_type
Definition: PacketData.hh:70
raw_container::difference_type difference_type
Definition: PacketTypes.hh:67
Parser Base class.
safe_data_iterator()
Make uninitialized iterator.
Iterator re-validating Parser wrapper.