cgma
|
#include <CubitDirIterator.hpp>
Classes | |
struct | Helper |
Public Member Functions | |
CubitDirIterator (const CubitString &path, const CubitString &pattern_match="") | |
virtual | ~CubitDirIterator () |
void | open (const CubitString &path, const CubitString &pattern_match="") |
bool | has_next () |
CubitString | next () |
Protected Member Functions | |
void | cleanup () |
Protected Attributes | |
Helper * | mHelper |
CubitString | mPattern |
bool | mDirs |
bool | atEnd |
Definition at line 11 of file CubitDirIterator.hpp.
CubitDirIterator::CubitDirIterator | ( | const CubitString & | path, |
const CubitString & | pattern_match = "" |
||
) |
Definition at line 46 of file CubitDirIterator.cpp.
CubitDirIterator::~CubitDirIterator | ( | ) | [virtual] |
Definition at line 52 of file CubitDirIterator.cpp.
void CubitDirIterator::cleanup | ( | ) | [protected] |
Definition at line 93 of file CubitDirIterator.cpp.
{ #ifdef _WIN32 if(this->mHelper->mFileHandle != 0) FindClose(this->mHelper->mFileHandle); this->mHelper->mFileHandle = 0; #else if(this->mHelper->mDirHandle) closedir(this->mHelper->mDirHandle); this->mHelper->mFileHandle = 0; this->mHelper->mDirHandle = 0; #endif }
bool CubitDirIterator::has_next | ( | ) |
Definition at line 107 of file CubitDirIterator.cpp.
{ return !this->atEnd; }
Definition at line 112 of file CubitDirIterator.cpp.
{ CubitString file; if(this->atEnd) return file; #ifdef _WIN32 file = CubitString::toUtf8(this->mHelper->mDirHandle.cFileName); BOOL result = FindNextFileW(this->mHelper->mFileHandle, &this->mHelper->mDirHandle); if(result == 0) this->atEnd = true; #else file = this->mHelper->mFileHandle->d_name; do { this->mHelper->mFileHandle = readdir(this->mHelper->mDirHandle); } while (this->mHelper->mFileHandle && (mPattern.length() != 0 && fnmatch(mPattern.c_str(), this->mHelper->mFileHandle->d_name, 0)) ); if(this->mHelper->mFileHandle == 0) this->atEnd = true; #endif return file; }
void CubitDirIterator::open | ( | const CubitString & | path, |
const CubitString & | pattern_match = "" |
||
) |
Definition at line 58 of file CubitDirIterator.cpp.
{ cleanup(); if(pattern.length()) mPattern = pattern; else mPattern = ""; this->atEnd = false; #ifdef _WIN32 CubitString p = path; if (p.get_at(p.length()-1) != '\\') p += "\\"; p += mPattern.length() == 0 ? "*" : mPattern; this->mHelper->mFileHandle = FindFirstFileW(CubitString::toUtf16(p).c_str(), &this->mHelper->mDirHandle); if(this->mHelper->mFileHandle == INVALID_HANDLE_VALUE) this->atEnd = true; #else this->mHelper->mDirHandle = opendir(path.c_str()); if(this->mHelper->mDirHandle) { do { this->mHelper->mFileHandle = readdir(this->mHelper->mDirHandle); } while (this->mHelper->mFileHandle && (mPattern.length() != 0 && fnmatch(mPattern.c_str(), this->mHelper->mFileHandle->d_name, 0)) ); } if(!this->mHelper->mDirHandle || !this->mHelper->mFileHandle) this->atEnd = true; #endif }
bool CubitDirIterator::atEnd [protected] |
Definition at line 26 of file CubitDirIterator.hpp.
bool CubitDirIterator::mDirs [protected] |
Definition at line 25 of file CubitDirIterator.hpp.
Helper* CubitDirIterator::mHelper [protected] |
Definition at line 22 of file CubitDirIterator.hpp.
CubitString CubitDirIterator::mPattern [protected] |
Definition at line 24 of file CubitDirIterator.hpp.