2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FIoDirEnumerator.h
20 * @brief This is the header file for the %DirEnumerator class.
22 * This header file contains the declarations of the %DirEnumerator class.
25 #ifndef _FIO_DIR_ENUMERATOR_H_
26 #define _FIO_DIR_ENUMERATOR_H_
28 #include <FBaseObject.h>
29 #include <FBaseColIEnumerator.h>
31 namespace Tizen { namespace Io
37 * @class DirEnumerator
38 * @brief This class provides methods to access the collection of a specific directory entry list.
42 * @final This class is not intended for extension.
44 * The %DirEnumerator class provides methods to access the collection of a specific directory entry list.
45 * Generally, %DirEnumerator is instantiated by the Directory::ReadN() method,
46 * and used to get the %DirEntry instances that have information pertaining to the directory.
48 * For more information on the class features,
49 * see <a href="../org.tizen.native.appprogramming/html/guide/io/io_namespace.htm">Io Guide</a>.
51 * @see Tizen::Io::Directory
52 * @see Tizen::Io::DirEntry
53 * @see Tizen::Io::File
55 * The following example demonstrates how to use the %DirEnumerator class.
61 using namespace Tizen::Base;
62 using namespace Tizen::Io;
66 String dirName(L"data/test");
68 DirEnumerator *pDirEnum = null;
72 r = dir.Construct(Tizen::App::App::GetInstance()->GetAppRootPath() + dirName);
78 // Read all the directory entries
79 pDirEnum = dir.ReadN();
85 // Loop through all the directory entries
86 while (pDirEnum->MoveNext() == E_SUCCESS)
88 DirEntry dirEntry = pDirEnum->GetCurrentDirEntry();
93 // Delete the enumerator
98 // The opened directory is closed automatically when the destructor of the Directory class is invoked.
112 class _OSP_EXPORT_ DirEnumerator
113 : public Tizen::Base::Object
114 , public Tizen::Base::Collection::IEnumerator
119 * This destructor overrides Tizen::Base::Object::~Object().
123 virtual ~DirEnumerator(void);
126 * Gets the value of the DirEntry instance in the currently accessed directory.
130 * @return A reference to the DirEntry instance
131 * @exception E_SUCCESS The method is successful.
132 * @exception E_INVALID_STATE The current position of the collection is not valid.
133 * @remarks Use the MoveNext() method to get information from another file or directory to the currently accessed directory. @n
134 * The specific error code can be accessed using the GetLastResult() method.
136 DirEntry GetCurrentDirEntry(void) const;
139 * Gets the pointer to the object at the current position of a directory entry collection.
143 * @return A pointer to the DirEntry instance, @n
144 * else @c null if the current position of the collection is invalid
145 * @remarks Use the MoveNext() method to get information of another file or directory in the currently accessed directory.
147 virtual Tizen::Base::Object* GetCurrent(void) const;
150 * Moves the current position of the collection to the next position in the currently accessed directory. @n
151 * When %DirEnumerator is instantiated, its initial position is set to @c -1. @n
152 * Therefore, calling the GetCurrentDirEntry() method without a call to MoveNext() throws an E_INVALID_STATE exception,
153 * and returns a reference to an empty DirEntry instance. @n
154 * Similarly, calling the GetCurrent() method without a call to MoveNext() returns a @c null pointer to indicate an error condition.
158 * @return An error code
159 * @exception E_SUCCESS The method is successful.
160 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
161 * - The length of the specified path is @c 0 or exceeds
162 * system limitations. @n
163 * - The specified path is invalid. @n
164 * - The file handle is invalid (either the file is closed by
165 * another method, or the memory is corrupted).
166 * @exception E_FILE_NOT_FOUND An entry for the specified file or path cannot be found.
167 * @exception E_MAX_EXCEEDED The number of opened files has exceeded the maximum limit.
168 * @exception E_END_OF_FILE There are no more directory entries to read.
169 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
170 * @exception E_IO Either of the following conditions has occurred: @n
171 * - An unexpected device failure has occurred as the media ejected suddenly. @n
172 * - %File corruption is detected.
174 virtual result MoveNext(void);
177 * Resets the current position of the collection to @c -1.
181 * @return An error code
182 * @exception E_SUCCESS The method is successful.
183 * @exception E_INVALID_ARG The file handle is invalid (either the file is closed by another method, or the memory is corrupted).
185 virtual result Reset(void);
189 * This default constructor is intentionally declared as private so that only the platform can create an instance.
196 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
200 DirEnumerator(const DirEnumerator& source);
203 * This is the copy constructor for this class.
207 DirEnumerator(const Tizen::Base::String& dirPath);
210 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
214 DirEnumerator& operator =(const DirEnumerator& source);
216 DirEntry* __pCurDirEntry;
217 class _DirEnumeratorImpl* __pDirEnumeratorImpl;
219 friend class _DirEnumeratorImpl;
225 #endif // _FIO_DIR_ENUMERATOR_H_