1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Directory iterator.
22 *//*--------------------------------------------------------------------*/
24 #include "deDirectoryIterator.hpp"
27 #if (DE_DIRITER == DE_DIRITER_WIN32)
28 # include <direct.h> /* _chdir() */
29 # include <io.h> /* _findfirst(), _findnext() */
35 #if (DE_DIRITER == DE_DIRITER_WIN32)
37 DirectoryIterator::DirectoryIterator (const FilePath& path)
38 : m_path(FilePath::normalize(path))
40 DE_CHECK_RUNTIME_ERR(m_path.exists());
41 DE_CHECK_RUNTIME_ERR(m_path.getType() == FilePath::TYPE_DIRECTORY);
43 m_handle = _findfirst32((std::string(m_path.getPath()) + "/*").c_str(), &m_fileInfo);
44 m_hasItem = m_handle != -1;
49 DirectoryIterator::~DirectoryIterator (void)
55 bool DirectoryIterator::hasItem (void) const
60 FilePath DirectoryIterator::getItem (void) const
63 return FilePath::join(m_path, m_fileInfo.name);
66 void DirectoryIterator::next (void)
68 m_hasItem = (_findnext32(m_handle, &m_fileInfo) == 0);
72 void DirectoryIterator::skipCurAndParent (void)
74 while (m_hasItem && (deStringEqual(m_fileInfo.name, "..") || deStringEqual(m_fileInfo.name, ".")))
75 m_hasItem = (_findnext32(m_handle, &m_fileInfo) == 0);
78 #elif (DE_DIRITER == DE_DIRITER_POSIX)
80 DirectoryIterator::DirectoryIterator (const FilePath& path)
81 : m_path (FilePath::normalize(path))
85 DE_CHECK_RUNTIME_ERR(m_path.exists());
86 DE_CHECK_RUNTIME_ERR(m_path.getType() == FilePath::TYPE_DIRECTORY);
88 m_handle = opendir(m_path.getPath());
89 DE_CHECK_RUNTIME_ERR(m_handle);
95 DirectoryIterator::~DirectoryIterator (void)
100 bool DirectoryIterator::hasItem (void) const
102 return (m_curEntry != DE_NULL);
105 FilePath DirectoryIterator::getItem (void) const
107 DE_ASSERT(hasItem());
108 return FilePath::join(m_path, m_curEntry->d_name);
111 void DirectoryIterator::next (void)
115 m_curEntry = readdir(m_handle);
116 } while (m_curEntry && (deStringEqual(m_curEntry->d_name, "..") || deStringEqual(m_curEntry->d_name, ".")));