1 #ifndef _DEDIRECTORYITERATOR_HPP 2 #define _DEDIRECTORYITERATOR_HPP 3 /*------------------------------------------------------------------------- 4 * drawElements Quality Program Tester Core 5 * ---------------------------------------- 6 * 7 * Copyright 2014 The Android Open Source Project 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 *//*! 22 * \file 23 * \brief Directory iterator. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "deDefs.hpp" 27 #include "deFilePath.hpp" 28 29 #define DE_DIRITER_WIN32 0 30 #define DE_DIRITER_POSIX 1 31 32 #if (DE_OS == DE_OS_WIN32 && DE_COMPILER == DE_COMPILER_MSC) 33 #define DE_DIRITER DE_DIRITER_WIN32 34 #elif (DE_OS == DE_OS_UNIX) || (DE_OS == DE_OS_OSX) || (DE_OS == DE_OS_ANDROID) || (DE_OS == DE_OS_SYMBIAN) || \ 35 (DE_OS == DE_OS_IOS) || (DE_OS == DE_OS_QNX) || \ 36 (DE_OS == DE_OS_WIN32 && (DE_COMPILER == DE_COMPILER_CLANG || DE_COMPILER == DE_COMPILER_GCC)) || \ 37 (DE_OS == DE_OS_FUCHSIA) 38 #define DE_DIRITER DE_DIRITER_POSIX 39 #endif 40 41 #if !defined(DE_DIRITER) 42 #error Implement tcu::DirectoryIterator for your platform. 43 #endif 44 45 #if (DE_DIRITER == DE_DIRITER_WIN32) 46 #include <io.h> /* _finddata32_t */ 47 #elif (DE_DIRITER == DE_DIRITER_POSIX) 48 #include <sys/types.h> 49 #include <dirent.h> 50 #endif 51 52 namespace de 53 { 54 55 class DirectoryIterator 56 { 57 public: 58 DirectoryIterator(const FilePath &path); 59 ~DirectoryIterator(void); 60 61 FilePath getItem(void) const; 62 bool hasItem(void) const; 63 void next(void); 64 65 private: 66 DirectoryIterator(const DirectoryIterator &other); 67 DirectoryIterator &operator=(const DirectoryIterator &other); 68 69 FilePath m_path; 70 71 #if (DE_DIRITER == DE_DIRITER_WIN32) 72 void skipCurAndParent(void); 73 74 bool m_hasItem; 75 intptr_t m_handle; 76 struct _finddata32_t m_fileInfo; 77 78 #elif (DE_DIRITER == DE_DIRITER_POSIX) 79 DIR *m_handle; 80 struct dirent *m_curEntry; 81 #endif 82 }; 83 84 } // namespace de 85 86 #endif // _DEDIRECTORYITERATOR_HPP 87