• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/core/program_options/include/hpx/program_options/eof_iterator.hpp
1
//  Copyright Vladimir Prus 2004.
2
//
3
//  SPDX-License-Identifier: BSL-1.0
4
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
5
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
#pragma once
8

9
#include <hpx/program_options/config.hpp>
10
#include <hpx/modules/iterator_support.hpp>
11

12
#include <iterator>
13

14
namespace hpx::program_options {
15

16
    /** The 'eof_iterator' class is useful for constructing forward iterators
17
        in cases where iterator extract data from some source, and it's easy
18
        to detect 'eof' \-- i.e. the situation where there's no data. One
19
        apparent example is reading lines from a file.
20

21
        Implementing such iterators using 'iterator_facade' directly would
22
        require to create class with three core operation, a couple of
23
        constructors. When using 'eof_iterator', the derived class should define
24
        only one method to get new value, plus a couple of constructors.
25

26
        The basic idea is that iterator has 'eof' bit. Two iterators are equal
27
        only if both have their 'eof' bits set. The 'get' method either obtains
28
        the new value or sets the 'eof' bit.
29

30
        Specifically, derived class should define:
31

32
        1. A default constructor, which creates iterator with 'eof' bit set. The
33
        constructor body should call 'found_eof' method defined here.
34
        2. Some other constructor. It should initialize some 'data pointer' used
35
        in iterator operation and then call 'get'.
36
        3. The 'get' method. It should operate this way:
37
            - look at some 'data pointer' to see if new element is available;
38
              if not, it should call 'found_eof'.
39
            - extract new element and store it at location returned by the 'value'
40
               method.
41
            - advance the data pointer.
42

43
        Essentially, the 'get' method has the functionality of both 'increment'
44
        and 'dereference'. It's very good for the cases where data extraction
45
        implicitly moves data pointer, like for stream operation.
46
    */
47
    HPX_CXX_EXPORT template <class Derived, class ValueType>
48
    class eof_iterator
×
49
      : public util::iterator_facade<Derived, ValueType const,
50
            std::forward_iterator_tag>
51
    {
52
    public:
53
        // NOLINTNEXTLINE(bugprone-crtp-constructor-accessibility)
×
54
        eof_iterator() = default;
55

56
    protected:    // interface for derived
57
        /** Returns the reference which should be used by derived
58
            class to store the next value. */
59
        ValueType& value() noexcept
60
        {
61
            return m_value;
62
        }
63

64
        /** Should be called by derived class to indicate that it can't
65
            produce next element. */
66
        void found_eof() noexcept
67
        {
×
68
            m_at_eof = true;
×
69
        }
70

71
    private:    // iterator core operations
72
        friend class hpx::util::iterator_core_access;
73

×
74
        void increment()
75
        {
×
76
            static_cast<Derived&>(*this).get();
×
77
        }
78

×
79
        [[nodiscard]] bool equal(eof_iterator const& other) const noexcept
80
        {
×
81
            return m_at_eof && other.m_at_eof;
82
        }
83

×
84
        ValueType const& dereference() const noexcept
85
        {
×
86
            return m_value;
87
        }
88

89
        bool m_at_eof = false;
90
        ValueType m_value;
91
    };
92
}    // namespace hpx::program_options
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc