1 //
2 // DirectoryIterator_UNIX.h
3 //
4 // Library: Foundation
5 // Package: Filesystem
6 // Module:  DirectoryIterator
7 //
8 // Definition of the DirectoryIteratorImpl class for UNIX.
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_UNIX_INCLUDED
18 #define Foundation_DirectoryIterator_UNIX_INCLUDED
19 
20 
21 #include "Poco/Foundation.h"
22 #include <dirent.h>
23 
24 
25 namespace Poco {
26 
27 
28 class Foundation_API DirectoryIteratorImpl
29 {
30 public:
31 	DirectoryIteratorImpl(const std::string& path);
32 	~DirectoryIteratorImpl();
33 
34 	void duplicate();
35 	void release();
36 
37 	const std::string& get() const;
38 	const std::string& next();
39 
40 private:
41 	DIR*        _pDir;
42 	std::string _current;
43 	int _rc;
44 };
45 
46 
47 //
48 // inlines
49 //
get()50 const std::string& DirectoryIteratorImpl::get() const
51 {
52 	return _current;
53 }
54 
55 
duplicate()56 inline void DirectoryIteratorImpl::duplicate()
57 {
58 	++_rc;
59 }
60 
61 
release()62 inline void DirectoryIteratorImpl::release()
63 {
64 	if (--_rc == 0)
65 		delete this;
66 }
67 
68 
69 } // namespace Poco
70 
71 
72 #endif // Foundation_DirectoryIterator_UNIX_INCLUDED
73