GCC Code Coverage Report


Directory: libs/url/
File: boost/url/impl/segments_base.hpp
Date: 2024-03-13 19:32:03
Exec Total Coverage
Lines: 27 27 100.0%
Functions: 9 9 100.0%
Branches: 2 4 50.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3 // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
4 //
5 // Distributed under the Boost Software License, Version 1.0. (See accompanying
6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // Official repository: https://github.com/boostorg/url
9 //
10
11 #ifndef BOOST_URL_IMPL_SEGMENTS_BASE_HPP
12 #define BOOST_URL_IMPL_SEGMENTS_BASE_HPP
13
14 #include <boost/url/detail/segments_iter_impl.hpp>
15 #include <boost/assert.hpp>
16 #include <iterator>
17
18 namespace boost {
19 namespace urls {
20
21 class segments_base::iterator
22 {
23 detail::segments_iter_impl it_;
24
25 friend class segments_base;
26 friend class segments_ref;
27
28 iterator(detail::path_ref const&) noexcept;
29 iterator(detail::path_ref const&, int) noexcept;
30
31 156 iterator(
32 detail::segments_iter_impl const& it) noexcept
33 156 : it_(it)
34 {
35 156 }
36
37 public:
38 using value_type = segments_base::value_type;
39 using reference = segments_base::reference;
40 using pointer = reference;
41 using difference_type =
42 segments_base::difference_type;
43 using iterator_category =
44 std::bidirectional_iterator_tag;
45
46 iterator() = default;
47 iterator(iterator const&) = default;
48 iterator& operator=(
49 iterator const&) noexcept = default;
50
51 BOOST_URL_DECL
52 reference
53 operator*() const;
54
55 // the return value is too expensive
56 pointer operator->() const = delete;
57
58 iterator&
59 802 operator++() noexcept
60 {
61 802 it_.increment();
62 802 return *this;
63 }
64
65 iterator&
66 69 operator--() noexcept
67 {
68 69 it_.decrement();
69 69 return *this;
70 }
71
72 iterator
73 30 operator++(int) noexcept
74 {
75 30 auto tmp = *this;
76 30 ++*this;
77 30 return tmp;
78 }
79
80 iterator
81 21 operator--(int) noexcept
82 {
83 21 auto tmp = *this;
84 21 --*this;
85 21 return tmp;
86 }
87
88 bool
89 56 operator==(
90 iterator const& other) const noexcept
91 {
92 56 return it_.equal(other.it_);
93 }
94
95 bool
96 906 operator!=(
97 iterator const& other) const noexcept
98 {
99 906 return ! it_.equal(other.it_);
100 }
101 };
102
103 //------------------------------------------------
104
105 inline
106 std::string
107 27 segments_base::
108 front() const noexcept
109 {
110
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
27 BOOST_ASSERT(! empty());
111 27 return *begin();
112 }
113
114 inline
115 std::string
116 20 segments_base::
117 back() const noexcept
118 {
119
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
20 BOOST_ASSERT(! empty());
120 20 return *--end();
121 }
122
123 } // urls
124 } // boost
125
126 #endif
127