SafeIterator.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 SafeIterator internal header */
16 
17 #ifndef IH_SENF_SafeIterator_
18 #define IH_SENF_SafeIterator_ 1
19 
20 // Custom includes
21 
22 ///////////////////////////////ih.p////////////////////////////////////////
23 
24 namespace senf {
25 namespace detail {
26 namespace packet {
27 
28  template <class DataIteratorType>
29  class safe_data_iterator_base
30  : public comparable_safe_bool< safe_data_iterator_base<DataIteratorType> >
31  {
32  public:
33  typedef PacketData::size_type size_type;
34 
35  bool boolean_test() const
36  {
37  return data_;
38  }
39 
40  operator DataIteratorType () const
41  {
42  SENF_ASSERT(data_, "Use/dereferencing of empty safe_data_iterator");
43  return boost::next(data_->begin(),i_);
44  }
45 
46 
47  protected:
48  safe_data_iterator_base(PacketData * data = nullptr, size_type i = 0)
49  : data_ (data), i_ (i) {}
50 
51  PacketData * data_;
52  size_type i_;
53  };
54 
55 #ifndef DOXYGEN
56 
57  template <class ValueType>
58  class safe_data_iterator_base<ValueType *>
59  {
60  public:
61  typedef PacketData::size_type size_type;
62 
63  operator ValueType * () const
64  {
65  return data_ ? boost::next(data_->begin(), i_) : static_cast<ValueType *>(nullptr);
66  }
67 
68  protected:
69  safe_data_iterator_base(PacketData * data = nullptr, size_type i = 0)
70  : data_ (data), i_ (i) {}
71 
72  PacketData * data_;
73  size_type i_;
74  };
75 
76 #endif
77 
78 }}}
79 
80 ///////////////////////////////ih.e////////////////////////////////////////
81 #endif
82 
83 
84 // Local Variables:
85 // mode: c++
86 // fill-column: 100
87 // comment-column: 40
88 // c-file-style: "senf"
89 // indent-tabs-mode: nil
90 // ispell-local-dictionary: "american"
91 // compile-command: "scons -u test"
92 // End: