2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___FILESYSTEM_PATH_ITERATOR_H
11 #define _LIBCPP___FILESYSTEM_PATH_ITERATOR_H
14 #include <__availability>
16 #include <__filesystem/path.h>
17 #include <__iterator/iterator_traits.h>
20 #include <string_view>
22 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23 # pragma GCC system_header
26 #ifndef _LIBCPP_CXX03_LANG
28 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
30 class _LIBCPP_EXPORTED_FROM_ABI
path::iterator
{
32 enum _ParserState
: unsigned char {
43 typedef input_iterator_tag iterator_category
;
44 typedef bidirectional_iterator_tag iterator_concept
;
46 typedef path value_type
;
47 typedef ptrdiff_t difference_type
;
48 typedef const path
* pointer
;
49 typedef path reference
;
52 _LIBCPP_INLINE_VISIBILITY
54 : __stashed_elem_(), __path_ptr_(nullptr), __entry_(),
55 __state_(_Singular
) {}
57 _LIBCPP_HIDE_FROM_ABI
iterator(const iterator
&) = default;
58 _LIBCPP_HIDE_FROM_ABI
~iterator() = default;
60 _LIBCPP_HIDE_FROM_ABI iterator
& operator=(const iterator
&) = default;
62 _LIBCPP_INLINE_VISIBILITY
63 reference
operator*() const { return __stashed_elem_
; }
65 _LIBCPP_INLINE_VISIBILITY
66 pointer
operator->() const { return &__stashed_elem_
; }
68 _LIBCPP_INLINE_VISIBILITY
69 iterator
& operator++() {
70 _LIBCPP_ASSERT_UNCATEGORIZED(__state_
!= _Singular
,
71 "attempting to increment a singular iterator");
72 _LIBCPP_ASSERT_UNCATEGORIZED(__state_
!= _AtEnd
,
73 "attempting to increment the end iterator");
77 _LIBCPP_INLINE_VISIBILITY
78 iterator
operator++(int) {
84 _LIBCPP_INLINE_VISIBILITY
85 iterator
& operator--() {
86 _LIBCPP_ASSERT_UNCATEGORIZED(__state_
!= _Singular
,
87 "attempting to decrement a singular iterator");
88 _LIBCPP_ASSERT_UNCATEGORIZED(__entry_
.data() != __path_ptr_
->native().data(),
89 "attempting to decrement the begin iterator");
93 _LIBCPP_INLINE_VISIBILITY
94 iterator
operator--(int) {
103 inline _LIBCPP_INLINE_VISIBILITY
friend bool operator==(const iterator
&,
106 iterator
& __increment();
107 iterator
& __decrement();
109 path __stashed_elem_
;
110 const path
* __path_ptr_
;
111 path::__string_view __entry_
;
112 _ParserState __state_
;
115 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY
116 inline _LIBCPP_INLINE_VISIBILITY
bool operator==(const path::iterator
& __lhs
,
117 const path::iterator
& __rhs
) {
118 return __lhs
.__path_ptr_
== __rhs
.__path_ptr_
&&
119 __lhs
.__entry_
.data() == __rhs
.__entry_
.data();
122 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY
123 inline _LIBCPP_INLINE_VISIBILITY
bool operator!=(const path::iterator
& __lhs
,
124 const path::iterator
& __rhs
) {
125 return !(__lhs
== __rhs
);
128 _LIBCPP_END_NAMESPACE_FILESYSTEM
130 #endif // _LIBCPP_CXX03_LANG
132 #endif // _LIBCPP___FILESYSTEM_PATH_ITERATOR_H