• 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

95.0
/libs/core/string_util/include/hpx/string_util/token_iterator.hpp
1
//  Copyright (c) 2022-2025 Hartmut Kaiser
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
// Copyright John R. Bandela 2001
8

9
// See http://www.boost.org/libs/tokenizer for documentation.
10

11
// Revision History:
12
// 16 Jul 2003   John Bandela
13
//      Allowed conversions from convertible base iterators
14
// 03 Jul 2003   John Bandela
15
//      Converted to new iterator adapter
16

17
#pragma once
18

19
#include <hpx/config.hpp>
20
#include <hpx/assert.hpp>
21
#include <hpx/modules/iterator_support.hpp>
22
#include <hpx/string_util/token_functions.hpp>
23

24
#include <string>
25
#include <type_traits>
26
#include <utility>
27

28
namespace hpx::string_util {
29

30
    HPX_CXX_EXPORT template <typename TokenizerFunc, typename Iterator,
31
        typename Type>
32
    class token_iterator
84✔
33
      : public util::iterator_facade<
34
            token_iterator<TokenizerFunc, Iterator, Type>, Type,
35
            typename util::detail::minimum_category<std::forward_iterator_tag,
36
                typename std::iterator_traits<Iterator>::iterator_category>::
37
                type,
38
            Type const&>
39
    {
40
    private:
41
        friend class util::iterator_core_access;
42

43
        TokenizerFunc f_;
44
        Iterator begin_;
45
        Iterator end_;
46
        bool valid_ = false;
47
        Type tok_;
48

49
        void increment()
1,701✔
50
        {
51
            HPX_ASSERT(valid_);
52
            valid_ = f_(begin_, end_, tok_);
1,701✔
53
        }
1,701✔
54

55
        Type const& dereference() const noexcept
2,526✔
56
        {
57
            HPX_ASSERT(valid_);
58
            return tok_;
2,526✔
59
        }
60

61
        template <typename Other>
62
        [[nodiscard]] bool equal(Other const& a) const noexcept
4,709✔
63
        {
64
            return (a.valid_ && valid_) ?
4,709✔
65
                ((a.begin_ == begin_) && (a.end_ == end_)) :
×
66
                (a.valid_ == valid_);
4,709✔
67
        }
68

69
        void initialize()
6,208✔
70
        {
71
            if (valid_)
6,208✔
72
                return;
73

74
            f_.reset();
75
            valid_ = (begin_ != end_) ? f_(begin_, end_, tok_) : false;
11,222✔
76
        }
77

78
    public:
79
        token_iterator() = default;
80

81
        template <typename F>
82
        token_iterator(F&& f, Iterator begin, Iterator e = Iterator())
6,208✔
83
          : f_(HPX_FORWARD(F, f))
6,208✔
84
          , begin_(begin)
6,208✔
85
          , end_(e)
6,208✔
86
          , tok_()
6,208✔
87
        {
88
            initialize();
6,208✔
89
        }
6,208✔
90

91
        explicit token_iterator(Iterator begin, Iterator e = Iterator())
92
          : f_()
93
          , begin_(begin)
94
          , end_(e)
95
          , tok_()
96
        {
97
            initialize();
98
        }
99

100
        template <typename OtherIter,
101
            typename =
102
                std::enable_if_t<std::is_convertible_v<OtherIter, Iterator>>>
103
        explicit token_iterator(
104
            token_iterator<TokenizerFunc, OtherIter, Type> const& t)
105
          : f_(t.tokenizer_function())
106
          , begin_(t.base())
107
          , end_(t.end())
108
          , valid_(!t.at_end())
109
          , tok_(t.current_token())
110
        {
111
        }
112

113
        [[nodiscard]] Iterator base() const
114
        {
115
            return begin_;
116
        }
117

118
        [[nodiscard]] Iterator end() const
119
        {
120
            return end_;
121
        }
122

123
        [[nodiscard]] TokenizerFunc const& tokenizer_function() const noexcept
124
        {
125
            return f_;
126
        }
127

128
        [[nodiscard]] Type current_token() const
129
        {
130
            return tok_;
131
        }
132

133
        [[nodiscard]] bool at_end() const noexcept
134
        {
135
            return !valid_;
136
        }
137
    };
138

139
    HPX_CXX_EXPORT template <typename TokenizerFunc = char_separator<char>,
140
        typename Iterator = std::string::const_iterator,
141
        typename Type = std::string>
142
    struct token_iterator_generator
143
    {
144
        using type = token_iterator<TokenizerFunc, Iterator, Type>;
145
    };
146

147
    // Type has to be first because it needs to be explicitly specified as there
148
    // is no way the function can deduce it.
149
    HPX_CXX_EXPORT template <typename Type, typename Iterator,
150
        typename TokenizerFunc>
151
    typename token_iterator_generator<std::decay_t<TokenizerFunc>, Iterator,
152
        Type>::type
153
    make_token_iterator(Iterator begin, Iterator end, TokenizerFunc&& fun)
154
    {
155
        using iterator_type =
156
            typename token_iterator_generator<std::decay_t<TokenizerFunc>,
157
                Iterator, Type>::type;
158
        return iterator_type(HPX_FORWARD(TokenizerFunc, fun), begin, end);
159
    }
160
}    // namespace hpx::string_util
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