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
26namespace Poco {
27
28
29class DirectoryIteratorImpl;
30
31
32class 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{
46public:
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 //@ 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
90protected:
91 Path _path;
92 File _file;
93
94private:
95 DirectoryIteratorImpl* _pImpl;
96};
97
98
99//
100// inlines
101//
102inline const std::string& DirectoryIterator::name() const
103{
104 return _path.getFileName();
105}
106
107
108inline const Path& DirectoryIterator::path() const
109{
110 return _path;
111}
112
113
114inline const File& DirectoryIterator::operator * () const
115{
116 return _file;
117}
118
119
120inline File& DirectoryIterator::operator * ()
121{
122 return _file;
123}
124
125
126inline const File* DirectoryIterator::operator -> () const
127{
128 return &_file;
129}
130
131
132inline File* DirectoryIterator::operator -> ()
133{
134 return &_file;
135}
136
137
138inline bool DirectoryIterator::operator == (const DirectoryIterator& iterator) const
139{
140 return name() == iterator.name();
141}
142
143
144inline bool DirectoryIterator::operator != (const DirectoryIterator& iterator) const
145{
146 return name() != iterator.name();
147}
148
149
150} // namespace Poco
151
152
153#endif // Foundation_DirectoryIterator_INCLUDED
154