cgma
CubitDirIterator Class Reference

#include <CubitDirIterator.hpp>

List of all members.

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

HelpermHelper
CubitString mPattern
bool mDirs
bool atEnd

Detailed Description

Definition at line 11 of file CubitDirIterator.hpp.


Constructor & Destructor Documentation

CubitDirIterator::CubitDirIterator ( const CubitString path,
const CubitString pattern_match = "" 
)

Definition at line 46 of file CubitDirIterator.cpp.

{
  this->mHelper = new Helper;
  open(path, pattern);
}

Definition at line 52 of file CubitDirIterator.cpp.

{
  cleanup();
  delete this->mHelper;
}

Member Function Documentation

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
}

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
}

Member Data Documentation

bool CubitDirIterator::atEnd [protected]

Definition at line 26 of file CubitDirIterator.hpp.

bool CubitDirIterator::mDirs [protected]

Definition at line 25 of file CubitDirIterator.hpp.

Definition at line 22 of file CubitDirIterator.hpp.

Definition at line 24 of file CubitDirIterator.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines