Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

gdcm::DirList Class Reference

List containing the file headers of all the gdcm readable files found by exploring recursively a root directory. More...

#include <gdcmDirList.h>

List of all members.

Public Member Functions

 DirList (std::string const &dirName, bool recursive=false)
 Constructor.

 ~DirList ()
 Destructor.

void Print (std::ostream &os=std::cout)
 Print method.

std::string const & GetDirName () const
 Return the name of the directory.

DirListType const & GetFilenames () const
 Return the file names.


Static Public Member Functions

bool IsDirectory (std::string const &dirName)
 Tells us if file name corresponds to a Directory.


Private Member Functions

int Explore (std::string const &dirName, bool recursive=false)
 Explore a directory with possibility of recursion return number of files read.


Private Attributes

DirListType Filenames
 List of file names.

std::string DirName
 name of the root directory to explore


Detailed Description

List containing the file headers of all the gdcm readable files found by exploring recursively a root directory.

Definition at line 42 of file gdcmDirList.h.


Constructor & Destructor Documentation

gdcm::DirList::DirList std::string const &  dirName,
bool  recursive = false
 

Constructor.

Parameters:
dirName root directory name
recursive whether we want to explore recursively or not

Definition at line 42 of file gdcmDirList.cxx.

References DirName, and Explore().

00043 {
00044    DirName = dirName;
00045    Explore(dirName, recursive);
00046 }

gdcm::DirList::~DirList  ) 
 

Destructor.

Definition at line 51 of file gdcmDirList.cxx.

00052 {
00053 }


Member Function Documentation

int gdcm::DirList::Explore std::string const &  dirpath,
bool  recursive = false
[private]
 

Explore a directory with possibility of recursion return number of files read.

Parameters:
dirpath directory to explore
recursive whether we want recursion or not

Definition at line 84 of file gdcmDirList.cxx.

References Filenames.

Referenced by DirList().

00085 {
00086    int numberOfFiles = 0;
00087    std::string fileName;
00088    std::string dirName = Util::NormalizePath(dirpath);
00089 #ifdef _MSC_VER
00090    WIN32_FIND_DATA fileData;
00091    HANDLE hFile = FindFirstFile((dirName+"*").c_str(), &fileData);
00092 
00093    for(BOOL b = (hFile != INVALID_HANDLE_VALUE); b;
00094        b = FindNextFile(hFile, &fileData))
00095    {
00096       fileName = fileData.cFileName;
00097       if( fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
00098       {
00099          // Need to check for . and .. to avoid infinite loop
00100          if( fileName != "." && fileName != ".." && recursive )
00101          {
00102             numberOfFiles += Explore(dirName+fileName,recursive);
00103          }
00104       }
00105       else
00106       {
00107          Filenames.push_back(dirName+fileName);
00108          numberOfFiles++;
00109       }
00110    }
00111    if (hFile != INVALID_HANDLE_VALUE) FindClose(hFile);
00112 
00113 #else
00114   // Real POSIX implementation: scandir is a BSD extension only, and doesn't 
00115   // work on debian for example
00116 
00117    DIR* dir = opendir(dirName.c_str());
00118    if (!dir)
00119    {
00120       return 0;
00121    }
00122 
00123    // According to POSIX, the dirent structure contains a field char d_name[]
00124    // of  unspecified  size, with at most NAME_MAX characters preceding the
00125    // terminating null character. Use of other fields will harm the  porta-
00126    // bility of your programs.
00127 
00128    struct stat buf;
00129    dirent *d = 0;
00130    for (d = readdir(dir); d; d = readdir(dir))
00131    {
00132       fileName = dirName + d->d_name;
00133       stat(fileName.c_str(), &buf); //really discard output ?
00134       if( S_ISREG(buf.st_mode) )    //is it a regular file?
00135       {
00136          Filenames.push_back( fileName );
00137          numberOfFiles++;
00138       }
00139       else if( S_ISDIR(buf.st_mode) ) //directory?
00140       {
00141          if( d->d_name[0] != '.' && recursive ) //we are also skipping hidden files
00142          {
00143             numberOfFiles += Explore( fileName, recursive);
00144          }
00145       }
00146       else
00147       {
00148          // we might need to do a different treament
00149          //abort();
00150       }
00151    }
00152   closedir(dir);
00153 #endif
00154 
00155   return numberOfFiles;
00156 }

std::string const& gdcm::DirList::GetDirName  )  const [inline]
 

Return the name of the directory.

Definition at line 51 of file gdcmDirList.h.

Referenced by gdcm::DicomDir::CreateDicomDirChainedList().

00051 { return DirName; }

DirListType const& gdcm::DirList::GetFilenames  )  const [inline]
 

Return the file names.

Definition at line 54 of file gdcmDirList.h.

References gdcm::DirListType.

Referenced by gdcm::DicomDir::CreateDicomDirChainedList(), and gdcm::SerieHelper::SetDirectory().

00054 { return Filenames; };

bool gdcm::DirList::IsDirectory std::string const &  dirName  )  [static]
 

Tells us if file name corresponds to a Directory.

Parameters:
dirName file name to check
Returns:
true if the file IS a Directory

Definition at line 62 of file gdcmDirList.cxx.

00063 {
00064 #ifndef _MSC_VER
00065    struct stat buf;
00066    stat(dirName.c_str(), &buf);
00067    return S_ISDIR(buf.st_mode);
00068 #else
00069    return (GetFileAttributes(dirName.c_str()) & FILE_ATTRIBUTE_DIRECTORY) != 0;
00070 #endif
00071 }

void gdcm::DirList::Print std::ostream &  os = std::cout  ) 
 

Print method.

Parameters:
os ostream to write to

Definition at line 164 of file gdcmDirList.cxx.

References Filenames.

00165 {
00166    std::copy(Filenames.begin(), Filenames.end(), 
00167              std::ostream_iterator<std::string>(os, "\n"));
00168 }


Member Data Documentation

std::string gdcm::DirList::DirName [private]
 

name of the root directory to explore

Definition at line 64 of file gdcmDirList.h.

Referenced by DirList().

DirListType gdcm::DirList::Filenames [private]
 

List of file names.

Definition at line 62 of file gdcmDirList.h.

Referenced by Explore(), and Print().


The documentation for this class was generated from the following files:
Generated on Thu Feb 10 22:18:08 2005 for gdcm by doxygen 1.3.6