]> Creatis software - gdcm.git/blobdiff - src/gdcmDirList.cxx
* src/gdcmDocument.cxx: for broken (non DICOM V3 conformal) images
[gdcm.git] / src / gdcmDirList.cxx
index 096209fabb5c1f870b2a74a11c87a178b7565953..efdc939369ee3cf2ad6a3c1f54ca4728631fa8a0 100644 (file)
@@ -1,49 +1,54 @@
-// gdcmDirList.cxx
-//-----------------------------------------------------------------------------
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: gdcmDirList.cxx,v $
+  Language:  C++
+  Date:      $Date: 2004/06/28 09:30:58 $
+  Version:   $Revision: 1.17 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/Gdcm/License.htm for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*/
+
 #include "gdcmDirList.h"
+#include "gdcmUtil.h"
 
 #include <iostream>
 #include <algorithm>
 
-#ifdef GDCM_NO_ANSI_STRING_STREAM
-   #include <strstream>
-   #define  ostringstream ostrstream
-#else
-   #include <sstream>
-#endif
-
-#ifdef _MSC_VER 
+#if defined(_MSC_VER) || defined (__CYGWIN__)
    #include <windows.h> 
+#ifdef _MSC_VER
    #include <direct.h>
+#endif //_MSC_VER
 #else
    #include <dirent.h>   
    #include <unistd.h>
 #endif
 
-//-----------------------------------------------------------------------------
-const char gdcmDirList::SEPARATOR_X      = '/';
-const char gdcmDirList::SEPARATOR_WIN    = '\\';
-const std::string gdcmDirList::SEPARATOR = "/";
-
-//-----------------------------------------------------------------------------
 // Constructor / Destructor
-/*
+/**
  * \ingroup gdcmDirList
- * \brief   
- * @param   
+ * \brief Constructor  
+ * @param  dirName root directory name
+ * @param  recursive whether we want to explore recursively or not 
  */
 gdcmDirList::gdcmDirList(std::string dirName,bool recursive)
 {
    name=dirName;
-
    NormalizePath(name);
    Explore(name,recursive);
 }
 
-/*
+/**
  * \ingroup gdcmDirList
- * \brief   
- * @param   
+ * \brief  Destructor
  */
 gdcmDirList::~gdcmDirList(void)
 {
@@ -54,10 +59,10 @@ gdcmDirList::~gdcmDirList(void)
 
 //-----------------------------------------------------------------------------
 // Public
-/*
+/**
  * \ingroup gdcmDirList
  * \brief   Get the directory name
- * @param   
+ * @return the directory name 
  */
 std::string gdcmDirList::GetDirName(void)
 {
@@ -69,32 +74,18 @@ std::string gdcmDirList::GetDirName(void)
 
 //-----------------------------------------------------------------------------
 // Private
-/*
- * \ingroup gdcmDirList
- * \brief   Add a SEPARATOR to the end of the directory name is necessary
- * @param   
- */
-void gdcmDirList::NormalizePath(std::string &dirName)
-{
-   int size=dirName.size();
-   if((dirName[size-1]!=SEPARATOR_X)&&(dirName[size-1]!=SEPARATOR_WIN))
-   {
-      dirName+=SEPARATOR;
-   }
-}
 
-/*
+/**
  * \ingroup gdcmDirList
  * \brief   Explore a directory with possibility of recursion
- * @param   
+ * @param  dirName directory to explore
+ * @param  recursive whether we want recursion or not
  */
 void gdcmDirList::Explore(std::string dirName,bool recursive)
 {
    std::string fileName;
-
    NormalizePath(dirName);
-
-#ifdef _MSC_VER 
+#if defined(_MSC_VER) || (__CYGWIN__)
    WIN32_FIND_DATA fileData; 
    HANDLE hFile=FindFirstFile((dirName+"*").c_str(),&fileData);
    int found=true;
@@ -105,7 +96,7 @@ void gdcmDirList::Explore(std::string dirName,bool recursive)
       if(fileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
       {
          if( (fileName!=".") && (fileName!="..") && (recursive) )
-            Explore(dirName+fileName);
+            Explore(dirName+fileName,recursive);
       }
       else
       {
@@ -121,11 +112,11 @@ void gdcmDirList::Explore(std::string dirName,bool recursive)
 
    for (int i= 0;i < n; i++) 
    {
-      fileName=namelist[i]->d_name;
+      fileName=namelist[i]->d_name;     
       if(namelist[i]->d_type==DT_DIR)
       {
          if( (fileName!=".") && (fileName!="..") && (recursive) )
-            Explore(dirName+fileName);
+            Explore(dirName+fileName,recursive);
       }
       else
       {