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#endif
23
24
25namespace Poco {
26
27
28DirectoryIterator::DirectoryIterator(): _pImpl(0)
29{
30}
31
32
33DirectoryIterator::DirectoryIterator(const std::string& pathString): _path(pathString), _pImpl(new DirectoryIteratorImpl(pathString))
34{
35 _path.makeDirectory();
36 _path.setFileName(_pImpl->get());
37 _file = _path;
38}
39
40
41DirectoryIterator::DirectoryIterator(const DirectoryIterator& iterator): _path(iterator._path), _pImpl(iterator._pImpl)
42{
43 if (_pImpl)
44 {
45 _pImpl->duplicate();
46 _file = _path;
47 }
48}
49
50
51DirectoryIterator::DirectoryIterator(const File& file): _path(file.path()), _pImpl(new DirectoryIteratorImpl(file.path()))
52{
53 _path.makeDirectory();
54 _path.setFileName(_pImpl->get());
55 _file = _path;
56}
57
58
59DirectoryIterator::DirectoryIterator(const Path& otherPath): _path(otherPath), _pImpl(new DirectoryIteratorImpl(otherPath.toString()))
60{
61 _path.makeDirectory();
62 _path.setFileName(_pImpl->get());
63 _file = _path;
64}
65
66
67DirectoryIterator::~DirectoryIterator()
68{
69 if (_pImpl) _pImpl->release();
70}
71
72
73DirectoryIterator& DirectoryIterator::operator = (const DirectoryIterator& it)
74{
75 if (_pImpl) _pImpl->release();
76 _pImpl = it._pImpl;
77 if (_pImpl)
78 {
79 _pImpl->duplicate();
80 _path = it._path;
81 _file = _path;
82 }
83 return *this;
84}
85
86
87DirectoryIterator& DirectoryIterator::operator = (const File& file)
88{
89 if (_pImpl) _pImpl->release();
90 _pImpl = new DirectoryIteratorImpl(file.path());
91 _path.parseDirectory(file.path());
92 _path.setFileName(_pImpl->get());
93 _file = _path;
94 return *this;
95}
96
97
98DirectoryIterator& DirectoryIterator::operator = (const Path& otherPath)
99{
100 if (_pImpl) _pImpl->release();
101 _pImpl = new DirectoryIteratorImpl(otherPath.toString());
102 _path = otherPath;
103 _path.makeDirectory();
104 _path.setFileName(_pImpl->get());
105 _file = _path;
106 return *this;
107}
108
109
110DirectoryIterator& DirectoryIterator::operator = (const std::string& pathString)
111{
112 if (_pImpl) _pImpl->release();
113 _pImpl = new DirectoryIteratorImpl(pathString);
114 _path.parseDirectory(pathString);
115 _path.setFileName(_pImpl->get());
116 _file = _path;
117 return *this;
118}
119
120
121DirectoryIterator& DirectoryIterator::operator ++ ()
122{
123 if (_pImpl)
124 {
125 _path.setFileName(_pImpl->next());
126 _file = _path;
127 }
128 return *this;
129}
130
131
132DirectoryIterator DirectoryIterator::operator ++ (int /*dummy*/)
133{
134 if (_pImpl)
135 {
136 _path.setFileName(_pImpl->next());
137 _file = _path;
138 }
139 return *this;
140}
141
142
143} // namespace Poco
144