root / Community Core Vision / Linux / libs / poco / include / Poco / DirectoryIterator.h @ 9

View | Annotate | Download (4.5 KB)

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