[80] | 1 | // |
---|
| 2 | // DirectoryIterator.h |
---|
| 3 | // |
---|
| 4 | // $Id: //poco/1.3/Foundation/include/Poco/DirectoryIterator.h#2 $ |
---|
| 5 | // |
---|
| 6 | // Library: Foundation |
---|
| 7 | // Package: Filesystem |
---|
| 8 | // Module: DirectoryIterator |
---|
| 9 | // |
---|
| 10 | // Definition of the DirectoryIterator class. |
---|
| 11 | // |
---|
| 12 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
---|
| 13 | // and Contributors. |
---|
| 14 | // |
---|
| 15 | // Permission is hereby granted, free of charge, to any person or organization |
---|
| 16 | // obtaining a copy of the software and accompanying documentation covered by |
---|
| 17 | // this license (the "Software") to use, reproduce, display, distribute, |
---|
| 18 | // execute, and transmit the Software, and to prepare derivative works of the |
---|
| 19 | // Software, and to permit third-parties to whom the Software is furnished to |
---|
| 20 | // do so, all subject to the following: |
---|
| 21 | // |
---|
| 22 | // The copyright notices in the Software and this entire statement, including |
---|
| 23 | // the above license grant, this restriction and the following disclaimer, |
---|
| 24 | // must be included in all copies of the Software, in whole or in part, and |
---|
| 25 | // all derivative works of the Software, unless such copies or derivative |
---|
| 26 | // works are solely in the form of machine-executable object code generated by |
---|
| 27 | // a source language processor. |
---|
| 28 | // |
---|
| 29 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 30 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 31 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
---|
| 32 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
---|
| 33 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
---|
| 34 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
| 35 | // DEALINGS IN THE SOFTWARE. |
---|
| 36 | // |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | #ifndef Foundation_DirectoryIterator_INCLUDED |
---|
| 40 | #define Foundation_DirectoryIterator_INCLUDED |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | #include "Poco/Foundation.h" |
---|
| 44 | #include "Poco/File.h" |
---|
| 45 | #include "Poco/Path.h" |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | namespace Poco { |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | class DirectoryIteratorImpl; |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | class Foundation_API DirectoryIterator |
---|
| 55 | /// The DirectoryIterator class is used to enumerate |
---|
| 56 | /// all files in a directory. |
---|
| 57 | /// |
---|
| 58 | /// DirectoryIterator has some limitations: |
---|
| 59 | /// * only forward iteration (++) is supported |
---|
| 60 | /// * an iterator copied from another one will always |
---|
| 61 | /// point to the same file as the original iterator, |
---|
| 62 | /// even is the original iterator has been advanced |
---|
| 63 | /// (all copies of an iterator share their state with |
---|
| 64 | /// the original iterator) |
---|
| 65 | /// * because of this you should only use the prefix |
---|
| 66 | /// increment operator |
---|
| 67 | { |
---|
| 68 | public: |
---|
| 69 | DirectoryIterator(); |
---|
| 70 | /// Creates the end iterator. |
---|
| 71 | |
---|
| 72 | DirectoryIterator(const std::string& path); |
---|
| 73 | /// Creates a directory iterator for the given path. |
---|
| 74 | |
---|
| 75 | DirectoryIterator(const DirectoryIterator& iterator); |
---|
| 76 | /// Creates a directory iterator for the given path. |
---|
| 77 | |
---|
| 78 | DirectoryIterator(const File& file); |
---|
| 79 | /// Creates a directory iterator for the given file. |
---|
| 80 | |
---|
| 81 | DirectoryIterator(const Path& path); |
---|
| 82 | /// Creates a directory iterator for the given path. |
---|
| 83 | |
---|
| 84 | ~DirectoryIterator(); |
---|
| 85 | /// Destroys the DirectoryIterator. |
---|
| 86 | |
---|
| 87 | const std::string& name() const; |
---|
| 88 | /// Returns the current filename. |
---|
| 89 | |
---|
| 90 | const Path& path() const; |
---|
| 91 | /// Returns the current path. |
---|
| 92 | |
---|
| 93 | DirectoryIterator& operator = (const DirectoryIterator& it); |
---|
| 94 | DirectoryIterator& operator = (const File& file); |
---|
| 95 | DirectoryIterator& operator = (const Path& path); |
---|
| 96 | DirectoryIterator& operator = (const std::string& path); |
---|
| 97 | |
---|
| 98 | DirectoryIterator& operator ++ (); // prefix |
---|
| 99 | |
---|
| 100 | //@ deprecated |
---|
| 101 | DirectoryIterator operator ++ (int); // postfix |
---|
| 102 | /// Please use the prefix increment operator instead. |
---|
| 103 | |
---|
| 104 | const File& operator * () const; |
---|
| 105 | File& operator * (); |
---|
| 106 | const File* operator -> () const; |
---|
| 107 | File* operator -> (); |
---|
| 108 | |
---|
| 109 | bool operator == (const DirectoryIterator& iterator) const; |
---|
| 110 | bool operator != (const DirectoryIterator& iterator) const; |
---|
| 111 | |
---|
| 112 | private: |
---|
| 113 | Path _path; |
---|
| 114 | File _file; |
---|
| 115 | DirectoryIteratorImpl* _pImpl; |
---|
| 116 | }; |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | // |
---|
| 120 | // inlines |
---|
| 121 | // |
---|
| 122 | inline const std::string& DirectoryIterator::name() const |
---|
| 123 | { |
---|
| 124 | return _path.getFileName(); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | inline const Path& DirectoryIterator::path() const |
---|
| 129 | { |
---|
| 130 | return _path; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | inline const File& DirectoryIterator::operator * () const |
---|
| 135 | { |
---|
| 136 | return _file; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | inline File& DirectoryIterator::operator * () |
---|
| 141 | { |
---|
| 142 | return _file; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | inline const File* DirectoryIterator::operator -> () const |
---|
| 147 | { |
---|
| 148 | return &_file; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | inline File* DirectoryIterator::operator -> () |
---|
| 153 | { |
---|
| 154 | return &_file; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | |
---|
| 158 | inline bool DirectoryIterator::operator == (const DirectoryIterator& iterator) const |
---|
| 159 | { |
---|
| 160 | return name() == iterator.name(); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | inline bool DirectoryIterator::operator != (const DirectoryIterator& iterator) const |
---|
| 165 | { |
---|
| 166 | return name() != iterator.name(); |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | } // namespace Poco |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | #endif // Foundation_DirectoryIterator_INCLUDED |
---|