2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FIoDirEnumerator.h
19 * @brief This is the header file for the %DirEnumerator class.
21 * This header file contains the declarations of the %DirEnumerator class.
24 #ifndef _FIO_DIR_ENUMERATOR_H_
25 #define _FIO_DIR_ENUMERATOR_H_
27 #include <FBaseObject.h>
28 #include <FBaseColIEnumerator.h>
30 namespace Tizen { namespace Io
36 * @class DirEnumerator
37 * @brief This class provides methods to access the collection of a specific directory entry list.
41 * @final This class is not intended for extension.
43 * The %DirEnumerator class provides methods to access the collection of a specific directory entry list.
44 * Generally, %DirEnumerator is instantiated by the Directory::ReadN() method,
45 * and used to get the %DirEntry instances that have information pertaining to the directory.
47 * For more information on the class features,
48 * see <a href="../org.tizen.native.appprogramming/html/guide/io/io_namespace.htm">Io Guide</a>.
50 * @see Tizen::Io::Directory
51 * @see Tizen::Io::DirEntry
52 * @see Tizen::Io::File
54 * The following example demonstrates how to use the %DirEnumerator class.
60 using namespace Tizen::Base;
61 using namespace Tizen::Io;
65 String dirName(L"data/test");
67 DirEnumerator *pDirEnum = null;
71 r = dir.Construct(Tizen::App::App::GetInstance()->GetAppRootPath() + dirName);
77 // Read all the directory entries
78 pDirEnum = dir.ReadN();
84 // Loop through all the directory entries
85 while (pDirEnum->MoveNext() == E_SUCCESS)
87 DirEntry dirEntry = pDirEnum->GetCurrentDirEntry();
92 // Delete the enumerator
97 // The opened directory is closed automatically when the destructor of the Directory class is invoked.
111 class _OSP_EXPORT_ DirEnumerator
112 : public Tizen::Base::Object
113 , public Tizen::Base::Collection::IEnumerator
118 * This destructor overrides Tizen::Base::Object::~Object().
122 virtual ~DirEnumerator(void);
125 * Gets the value of the DirEntry instance in the currently accessed directory.
129 * @return A reference to the DirEntry instance
130 * @exception E_SUCCESS The method is successful.
131 * @exception E_INVALID_STATE The current position of the collection is not valid.
132 * @remarks Use the MoveNext() method to get information from another file or directory to the currently accessed directory. @n
133 * The specific error code can be accessed using the GetLastResult() method.
135 DirEntry GetCurrentDirEntry(void) const;
138 * Gets the pointer to the object at the current position of a directory entry collection.
142 * @return A pointer to the DirEntry instance, @n
143 * else @c null if the current position of the collection is invalid
144 * @remarks Use the MoveNext() method to get information of another file or directory in the currently accessed directory.
146 virtual Tizen::Base::Object* GetCurrent(void) const;
149 * Moves the current position of the collection to the next position in the currently accessed directory. @n
150 * When %DirEnumerator is instantiated, its initial position is set to @c -1. @n
151 * Therefore, calling the GetCurrentDirEntry() method without a call to MoveNext() throws an E_INVALID_STATE exception,
152 * and returns a reference to an empty DirEntry instance. @n
153 * Similarly, calling the GetCurrent() method without a call to MoveNext() returns a @c null pointer to indicate an error condition.
157 * @return An error code
158 * @exception E_SUCCESS The method is successful.
159 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
160 * - The length of the specified path is @c 0 or exceeds
161 * system limitations. @n
162 * - The specified path is invalid. @n
163 * - The file handle is invalid (either the file is closed by
164 * another method, or the memory is corrupted).
165 * @exception E_FILE_NOT_FOUND An entry for the specified file or path cannot be found.
166 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
167 * @exception E_END_OF_FILE There are no more directory entries to read.
168 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
169 * @exception E_IO Either of the following conditions has occurred: @n
170 * - An unexpected device failure has occurred as the media ejected suddenly. @n
171 * - %File corruption is detected.
173 virtual result MoveNext(void);
176 * Resets the current position of the collection to @c -1.
180 * @return An error code
181 * @exception E_SUCCESS The method is successful.
182 * @exception E_INVALID_ARG The file handle is invalid (either the file is closed by another method, or the memory is corrupted).
184 virtual result Reset(void);
188 * This default constructor is intentionally declared as private so that only the platform can create an instance.
195 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
199 DirEnumerator(const DirEnumerator& source);
202 * This is the copy constructor for this class.
206 DirEnumerator(const Tizen::Base::String& dirPath);
209 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
213 DirEnumerator& operator =(const DirEnumerator& source);
215 DirEntry* __pCurDirEntry;
216 class _DirEnumeratorImpl* __pDirEnumeratorImpl;
218 friend class _DirEnumeratorImpl;
224 #endif // _FIO_DIR_ENUMERATOR_H_