aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/libcxx/include/__filesystem/path_iterator.h
blob: 62f8dc6fd357e43bcb18b002fd3f34d71bb84a55 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___FILESYSTEM_PATH_ITERATOR_H
#define _LIBCPP___FILESYSTEM_PATH_ITERATOR_H

#include <__availability>
#include <__config>
#include <__filesystem/path.h>
#include <__iterator/iterator_traits.h>
#include <__debug>
#include <cstddef>
#include <string>
#include <string_view>

#ifndef _LIBCPP_CXX03_LANG

_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM

_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH

class _LIBCPP_TYPE_VIS path::iterator {
public:
  enum _ParserState : unsigned char {
    _Singular,
    _BeforeBegin,
    _InRootName,
    _InRootDir,
    _InFilenames,
    _InTrailingSep,
    _AtEnd
  };

public:
  typedef bidirectional_iterator_tag iterator_category;

  typedef path value_type;
  typedef ptrdiff_t difference_type;
  typedef const path* pointer;
  typedef const path& reference;

  typedef void
      __stashing_iterator_tag; // See reverse_iterator and __is_stashing_iterator

public:
  _LIBCPP_INLINE_VISIBILITY
  iterator()
      : __stashed_elem_(), __path_ptr_(nullptr), __entry_(),
        __state_(_Singular) {}

  iterator(const iterator&) = default;
  ~iterator() = default;

  iterator& operator=(const iterator&) = default;

  _LIBCPP_INLINE_VISIBILITY
  reference operator*() const { return __stashed_elem_; }

  _LIBCPP_INLINE_VISIBILITY
  pointer operator->() const { return &__stashed_elem_; }

  _LIBCPP_INLINE_VISIBILITY
  iterator& operator++() {
    _LIBCPP_ASSERT(__state_ != _Singular,
                   "attempting to increment a singular iterator");
    _LIBCPP_ASSERT(__state_ != _AtEnd,
                   "attempting to increment the end iterator");
    return __increment();
  }

  _LIBCPP_INLINE_VISIBILITY
  iterator operator++(int) {
    iterator __it(*this);
    this->operator++();
    return __it;
  }

  _LIBCPP_INLINE_VISIBILITY
  iterator& operator--() {
    _LIBCPP_ASSERT(__state_ != _Singular,
                   "attempting to decrement a singular iterator");
    _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(),
                   "attempting to decrement the begin iterator");
    return __decrement();
  }

  _LIBCPP_INLINE_VISIBILITY
  iterator operator--(int) {
    iterator __it(*this);
    this->operator--();
    return __it;
  }

private:
  friend class path;

  inline _LIBCPP_INLINE_VISIBILITY friend bool operator==(const iterator&,
                                                          const iterator&);

  iterator& __increment();
  iterator& __decrement();

  path __stashed_elem_;
  const path* __path_ptr_;
  path::__string_view __entry_;
  _ParserState __state_;
};

inline _LIBCPP_INLINE_VISIBILITY bool operator==(const path::iterator& __lhs,
                                                 const path::iterator& __rhs) {
  return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
         __lhs.__entry_.data() == __rhs.__entry_.data();
}

inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const path::iterator& __lhs,
                                                 const path::iterator& __rhs) {
  return !(__lhs == __rhs);
}

_LIBCPP_AVAILABILITY_FILESYSTEM_POP

_LIBCPP_END_NAMESPACE_FILESYSTEM

#endif // _LIBCPP_CXX03_LANG

#endif // _LIBCPP___FILESYSTEM_PATH_ITERATOR_H