Coverage Report

Created: 2025-06-25 07:00

/src/poco/Foundation/include/Poco/DirectoryIterator.h
Line
Count
Source (jump to first uncovered line)
1
//
2
// DirectoryIterator.h
3
//
4
// Library: Foundation
5
// Package: Filesystem
6
// Module:  DirectoryIterator
7
//
8
// Definition of the DirectoryIterator class.
9
//
10
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
11
// and Contributors.
12
//
13
// SPDX-License-Identifier: BSL-1.0
14
//
15
16
17
#ifndef Foundation_DirectoryIterator_INCLUDED
18
#define Foundation_DirectoryIterator_INCLUDED
19
20
21
#include "Poco/Foundation.h"
22
#include "Poco/File.h"
23
#include "Poco/Path.h"
24
25
26
namespace Poco {
27
28
29
class DirectoryIteratorImpl;
30
31
32
class Foundation_API DirectoryIterator
33
  /// The DirectoryIterator class is used to enumerate
34
  /// all files in a directory.
35
  ///
36
  /// DirectoryIterator has some limitations:
37
  ///   * only forward iteration (++) is supported
38
  ///   * an iterator copied from another one will always
39
  ///     point to the same file as the original iterator,
40
  ///     even is the original iterator has been advanced
41
  ///     (all copies of an iterator share their state with
42
  ///     the original iterator)
43
  ///   * because of this you should only use the prefix
44
  ///     increment operator
45
{
46
public:
47
  DirectoryIterator();
48
    /// Creates the end iterator.
49
50
  DirectoryIterator(const std::string& path);
51
    /// Creates a directory iterator for the given path.
52
53
  DirectoryIterator(const DirectoryIterator& iterator);
54
    /// Creates a directory iterator for the given path.
55
56
  DirectoryIterator(const File& file);
57
    /// Creates a directory iterator for the given file.
58
59
  DirectoryIterator(const Path& path);
60
    /// Creates a directory iterator for the given path.
61
62
  virtual ~DirectoryIterator();
63
    /// Destroys the DirectoryIterator.
64
65
  const std::string& name() const;
66
    /// Returns the current filename.
67
68
  const Path& path() const;
69
    /// Returns the current path.
70
71
  DirectoryIterator& operator = (const DirectoryIterator& it);
72
  DirectoryIterator& operator = (const File& file);
73
  DirectoryIterator& operator = (const Path& path);
74
  DirectoryIterator& operator = (const std::string& path);
75
76
  virtual DirectoryIterator& operator ++ ();   // prefix
77
78
  POCO_DEPRECATED("")
79
  DirectoryIterator operator ++ (int); // postfix
80
    /// Please use the prefix increment operator instead.
81
82
  const File& operator * () const;
83
  File& operator * ();
84
  const File* operator -> () const;
85
  File* operator -> ();
86
87
  bool operator == (const DirectoryIterator& iterator) const;
88
  bool operator != (const DirectoryIterator& iterator) const;
89
90
protected:
91
  Path _path;
92
  File _file;
93
94
private:
95
  DirectoryIteratorImpl* _pImpl;
96
};
97
98
99
//
100
// inlines
101
//
102
inline const std::string& DirectoryIterator::name() const
103
0
{
104
0
  return _path.getFileName();
105
0
}
106
107
108
inline const Path& DirectoryIterator::path() const
109
0
{
110
0
  return _path;
111
0
}
112
113
114
inline const File& DirectoryIterator::operator * () const
115
0
{
116
0
  return _file;
117
0
}
118
119
120
inline File& DirectoryIterator::operator * ()
121
0
{
122
0
  return _file;
123
0
}
124
125
126
inline const File* DirectoryIterator::operator -> () const
127
0
{
128
0
  return &_file;
129
0
}
130
131
132
inline File* DirectoryIterator::operator -> ()
133
0
{
134
0
  return &_file;
135
0
}
136
137
138
inline bool DirectoryIterator::operator == (const DirectoryIterator& iterator) const
139
0
{
140
0
  return name() == iterator.name();
141
0
}
142
143
144
inline bool DirectoryIterator::operator != (const DirectoryIterator& iterator) const
145
0
{
146
0
  return name() != iterator.name();
147
0
}
148
149
150
} // namespace Poco
151
152
153
#endif // Foundation_DirectoryIterator_INCLUDED