1 | // |
---|---|
2 | // DirectoryIterator.cpp |
3 | // |
4 | // Library: Foundation |
5 | // Package: Filesystem |
6 | // Module: DirectoryIterator |
7 | // |
8 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
9 | // and Contributors. |
10 | // |
11 | // SPDX-License-Identifier: BSL-1.0 |
12 | // |
13 | |
14 | |
15 | #include "Poco/DirectoryIterator.h" |
16 | |
17 | |
18 | #if defined(POCO_OS_FAMILY_WINDOWS) |
19 | #include "DirectoryIterator_WIN32.cpp" |
20 | #elif defined(POCO_OS_FAMILY_UNIX) |
21 | #include "DirectoryIterator_UNIX.cpp" |
22 | #else |
23 | #include "DirectoryIterator_VMS.cpp" |
24 | #endif |
25 | |
26 | |
27 | namespace Poco { |
28 | |
29 | |
30 | DirectoryIterator::DirectoryIterator(): _pImpl(0) |
31 | { |
32 | } |
33 | |
34 | |
35 | DirectoryIterator::DirectoryIterator(const std::string& pathString): _path(pathString), _pImpl(new DirectoryIteratorImpl(pathString)) |
36 | { |
37 | _path.makeDirectory(); |
38 | _path.setFileName(_pImpl->get()); |
39 | _file = _path; |
40 | } |
41 | |
42 | |
43 | DirectoryIterator::DirectoryIterator(const DirectoryIterator& iterator): _path(iterator._path), _pImpl(iterator._pImpl) |
44 | { |
45 | if (_pImpl) |
46 | { |
47 | _pImpl->duplicate(); |
48 | _file = _path; |
49 | } |
50 | } |
51 | |
52 | |
53 | DirectoryIterator::DirectoryIterator(const File& file): _path(file.path()), _pImpl(new DirectoryIteratorImpl(file.path())) |
54 | { |
55 | _path.makeDirectory(); |
56 | _path.setFileName(_pImpl->get()); |
57 | _file = _path; |
58 | } |
59 | |
60 | |
61 | DirectoryIterator::DirectoryIterator(const Path& otherPath): _path(otherPath), _pImpl(new DirectoryIteratorImpl(otherPath.toString())) |
62 | { |
63 | _path.makeDirectory(); |
64 | _path.setFileName(_pImpl->get()); |
65 | _file = _path; |
66 | } |
67 | |
68 | |
69 | DirectoryIterator::~DirectoryIterator() |
70 | { |
71 | if (_pImpl) _pImpl->release(); |
72 | } |
73 | |
74 | |
75 | DirectoryIterator& DirectoryIterator::operator = (const DirectoryIterator& it) |
76 | { |
77 | if (_pImpl) _pImpl->release(); |
78 | _pImpl = it._pImpl; |
79 | if (_pImpl) |
80 | { |
81 | _pImpl->duplicate(); |
82 | _path = it._path; |
83 | _file = _path; |
84 | } |
85 | return *this; |
86 | } |
87 | |
88 | |
89 | DirectoryIterator& DirectoryIterator::operator = (const File& file) |
90 | { |
91 | if (_pImpl) _pImpl->release(); |
92 | _pImpl = new DirectoryIteratorImpl(file.path()); |
93 | _path.parseDirectory(file.path()); |
94 | _path.setFileName(_pImpl->get()); |
95 | _file = _path; |
96 | return *this; |
97 | } |
98 | |
99 | |
100 | DirectoryIterator& DirectoryIterator::operator = (const Path& otherPath) |
101 | { |
102 | if (_pImpl) _pImpl->release(); |
103 | _pImpl = new DirectoryIteratorImpl(otherPath.toString()); |
104 | _path = otherPath; |
105 | _path.makeDirectory(); |
106 | _path.setFileName(_pImpl->get()); |
107 | _file = _path; |
108 | return *this; |
109 | } |
110 | |
111 | |
112 | DirectoryIterator& DirectoryIterator::operator = (const std::string& pathString) |
113 | { |
114 | if (_pImpl) _pImpl->release(); |
115 | _pImpl = new DirectoryIteratorImpl(pathString); |
116 | _path.parseDirectory(pathString); |
117 | _path.setFileName(_pImpl->get()); |
118 | _file = _path; |
119 | return *this; |
120 | } |
121 | |
122 | |
123 | DirectoryIterator& DirectoryIterator::operator ++ () |
124 | { |
125 | if (_pImpl) |
126 | { |
127 | _path.setFileName(_pImpl->next()); |
128 | _file = _path; |
129 | } |
130 | return *this; |
131 | } |
132 | |
133 | |
134 | DirectoryIterator DirectoryIterator::operator ++ (int dummy) |
135 | { |
136 | if (_pImpl) |
137 | { |
138 | _path.setFileName(_pImpl->next()); |
139 | _file = _path; |
140 | } |
141 | return *this; |
142 | } |
143 | |
144 | |
145 | } // namespace Poco |
146 |