]> Creatis software - gdcm.git/commitdiff
Solve pb when structure (list, map, ...) is empty.
authorjpr <jpr>
Tue, 18 Jan 2005 11:39:59 +0000 (11:39 +0000)
committerjpr <jpr>
Tue, 18 Jan 2005 11:39:59 +0000 (11:39 +0000)
Thx to Benoit for reporting bug

src/gdcmDicomDir.cxx
src/gdcmDicomDirPatient.cxx
src/gdcmDicomDirSerie.cxx
src/gdcmDicomDirStudy.cxx
src/gdcmDict.cxx
src/gdcmDictSet.cxx
src/gdcmElementSet.cxx

index 1bfa211d9112c0fd2d07dc7f0fc2d3c49cd96198..f775d215aed10281da9eb3293b0b8ab084f7b307 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/18 07:53:41 $
-  Version:   $Revision: 1.104 $
+  Date:      $Date: 2005/01/18 11:39:59 $
+  Version:   $Revision: 1.105 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -974,7 +974,9 @@ bool DicomDir::HeaderLessThan(Document *header1, Document *header2)
 DicomDirPatient *DicomDir::GetFirstEntry()
 {
    ItDicomDirPatient = Patients.begin();
-   return *ItDicomDirPatient;
+   if ( ItDicomDirPatient != Patients.end() )
+      return *ItDicomDirPatient;
+   return NULL;
 }
 
 /**
@@ -984,16 +986,13 @@ DicomDirPatient *DicomDir::GetFirstEntry()
  */
 DicomDirPatient *DicomDir::GetNextEntry()
 {
-   if (ItDicomDirPatient != Patients.end())
+   gdcmAssertMacro (ItDicomDirPatient != Patients.end());
    {
-      DicomDirPatient *tmp = *ItDicomDirPatient;
       ++ItDicomDirPatient;
-      return tmp;
-   }
-   else
-   {
-      return NULL;
+      if ( ItDicomDirPatient != Patients.end() )
+         return *ItDicomDirPatient;
    }
+   return NULL;
 }
 
 
index 690799e29245723ecd5c84592471fedae7cd4bcf..81ba43275d4d6a13081d70e7e410944ad8a0e3ff 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirPatient.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/18 07:53:42 $
-  Version:   $Revision: 1.26 $
+  Date:      $Date: 2005/01/18 11:39:59 $
+  Version:   $Revision: 1.27 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -21,6 +21,7 @@
 #include "gdcmGlobal.h"
 #include "gdcmDicomDirStudy.h"
 #include "gdcmSQItem.h"
+#include "gdcmDebug.h"
 
 namespace gdcm 
 {
@@ -109,7 +110,9 @@ DicomDirStudy* DicomDirPatient::NewStudy()
 DicomDirStudy *DicomDirPatient::GetFirstEntry()
 {
    ItDicomDirStudy = Studies.begin();
-   return *ItDicomDirStudy;
+   if (ItDicomDirStudy != Studies.end())
+      return *ItDicomDirStudy;
+   return NULL;
 }
 
 /**
@@ -119,16 +122,13 @@ DicomDirStudy *DicomDirPatient::GetFirstEntry()
  */
 DicomDirStudy *DicomDirPatient::GetNextEntry()
 {
-   if (ItDicomDirStudy != Studies.end())
+   gdcmAssertMacro (ItDicomDirStudy != Studies.end())
    {
-      DicomDirStudy *tmp = *ItDicomDirStudy;
       ++ItDicomDirStudy;
-      return tmp;
-   }
-   else
-   {
-      return NULL;
+      if (ItDicomDirStudy != Studies.end())
+         return *ItDicomDirStudy;
    }
+   return NULL;
 }
 //-----------------------------------------------------------------------------
 // Protected
index 8632bfa21e99e2366632e79a11b623677bbd258b..2809fdea1dcf964d1847c7151977e85e9e77e19c 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirSerie.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/18 07:53:42 $
-  Version:   $Revision: 1.28 $
+  Date:      $Date: 2005/01/18 11:39:59 $
+  Version:   $Revision: 1.29 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -20,6 +20,7 @@
 #include "gdcmDicomDirElement.h"
 #include "gdcmDicomDirImage.h"
 #include "gdcmGlobal.h"
+#include "gdcmDebug.h"
 
 namespace gdcm 
 {
@@ -108,7 +109,9 @@ DicomDirImage *DicomDirSerie::NewImage()
 DicomDirImage *DicomDirSerie::GetFirstEntry()
 {
    ItDicomDirImage = Images.begin();
-   return *ItDicomDirImage;
+   if (ItDicomDirImage != Images.end())
+      return *ItDicomDirImage;
+   return NULL;
 }
 
 /**
@@ -118,16 +121,13 @@ DicomDirImage *DicomDirSerie::GetFirstEntry()
  */
 DicomDirImage *DicomDirSerie::GetNextEntry()
 {
-   if (ItDicomDirImage != Images.end())
+   gdcmAssertMacro (ItDicomDirImage != Images.end());
    {
-      DicomDirImage *tmp = *ItDicomDirImage;
       ++ItDicomDirImage;
-      return tmp;
-   }
-   else
-   {
-      return NULL;
+      if (ItDicomDirImage != Images.end())      
+         return *ItDicomDirImage;
    }
+   return NULL;
 }
  
 //-----------------------------------------------------------------------------
index e1824d7f4296db337171c0a3a90ed0e24c49885c..bdb788406b0d79e3dd90a2fbf02d74d81b3bf337 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirStudy.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/18 07:53:42 $
-  Version:   $Revision: 1.25 $
+  Date:      $Date: 2005/01/18 11:39:59 $
+  Version:   $Revision: 1.26 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -20,6 +20,7 @@
 #include "gdcmDicomDirElement.h"
 #include "gdcmGlobal.h"
 #include "gdcmDicomDirSerie.h"
+#include "gdcmDebug.h"
 
 namespace gdcm 
 {
@@ -110,7 +111,9 @@ DicomDirSerie *DicomDirStudy::NewSerie()
 DicomDirSerie *DicomDirStudy::GetFirstEntry()
 {
    ItDicomDirSerie = Series.begin();
-   return *ItDicomDirSerie;
+   if (ItDicomDirSerie != Series.end())
+      return *ItDicomDirSerie;
+   return NULL;
 }
 
 /**
@@ -120,16 +123,13 @@ DicomDirSerie *DicomDirStudy::GetFirstEntry()
  */
 DicomDirSerie *DicomDirStudy::GetNextEntry()
 {
-   if (ItDicomDirSerie != Series.end())
+   gdcmAssertMacro (ItDicomDirSerie != Series.end());
    {
-      DicomDirSerie *tmp = *ItDicomDirSerie;
       ++ItDicomDirSerie;
-      return tmp;
-   }
-   else
-   {
-      return NULL;
+      if (ItDicomDirSerie != Series.end())
+         return *ItDicomDirSerie;
    }
+   return NULL;
 }  
 //-----------------------------------------------------------------------------
 // Protected
index dc7e5c0c14f7be0ad3292fb974fe3469e2250d05..f15a753613325d9141bd471193d31acb00470b94 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDict.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/18 07:49:41 $
-  Version:   $Revision: 1.66 $
+  Date:      $Date: 2005/01/18 11:39:59 $
+  Version:   $Revision: 1.67 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -276,7 +276,9 @@ DictEntry *Dict::GetDictEntry(uint16_t group, uint16_t elem)
 DictEntry *Dict::GetFirstEntry()
 {
    ItKeyHt = KeyHt.begin();
-   return &(ItKeyHt->second);
+   if( ItKeyHt != KeyHt.end() )
+      return &(ItKeyHt->second);
+   return NULL;
 }
 
 /**
@@ -286,17 +288,14 @@ DictEntry *Dict::GetFirstEntry()
  */
 DictEntry *Dict::GetNextEntry()
 {
-   if (ItKeyHt != KeyHt.end())
-   {
-      DictEntry *tmp = &(ItKeyHt->second);
-      ++ItKeyHt;
+   gdcmAssertMacro (ItKeyHt != KeyHt.end());
 
-      return tmp;
-   }
-   else
    {
-      return NULL;
+      ++ItKeyHt;
+      if (ItKeyHt != KeyHt.end())
+         return &(ItKeyHt->second);
    }
+   return NULL;
 }
 
 //-----------------------------------------------------------------------------
index c825df10881e294f980218ac1443f29751f6dec0..a44e8fdc219f29ad24b236c64a881f55467d84bf 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDictSet.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/18 08:01:40 $
-  Version:   $Revision: 1.53 $
+  Date:      $Date: 2005/01/18 11:40:00 $
+  Version:   $Revision: 1.54 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -231,7 +231,9 @@ std::string DictSet::BuildDictPath()
 Dict *DictSet::GetFirstEntry()
 {
    ItDictHt = Dicts.begin();
-   return ItDictHt->second;
+   if( ItDictHt != Dicts.end() )
+      return ItDictHt->second;
+   return NULL;
 }
 
 /**
@@ -241,17 +243,12 @@ Dict *DictSet::GetFirstEntry()
  */
 Dict *DictSet::GetNextEntry()
 {
-   if (ItDictHt != Dicts.end())
-   {
-      Dict *tmp = ItDictHt->second;
-      ++ItDictHt;
-
-      return tmp;
-   }
-   else
-   {
-      return NULL;
-   }
+   gdcmAssertMacro (ItDictHt != Dicts.end());
+  
+   ++ItDictHt;
+   if ( ItDictHt != Dicts.end() )
+      return ItDictHt->second;
+   return NULL;
 }
 
 //-----------------------------------------------------------------------------
index 769c7814034f358ddfe93f54b0c6950b44179b9d..e43177e868e15fca3428882048a35f5f6dbbb8be 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmElementSet.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/18 08:01:41 $
-  Version:   $Revision: 1.43 $
+  Date:      $Date: 2005/01/18 11:40:00 $
+  Version:   $Revision: 1.44 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -167,7 +167,9 @@ bool ElementSet::RemoveEntryNoDestroy(DocEntry *entryToRemove)
 DocEntry *ElementSet::GetFirstEntry()
 {
    ItTagHT = TagHT.begin();
-   return ItTagHT->second;
+   if (ItTagHT != TagHT.end())
+      return  ItTagHT->second;
+   return NULL;
 }
 
 /**
@@ -177,17 +179,12 @@ DocEntry *ElementSet::GetFirstEntry()
  */
 DocEntry *ElementSet::GetNextEntry()
 {
-   if (ItTagHT != TagHT.end())
-   {
-      DocEntry *tmp = ItTagHT->second;
-      ++ItTagHT;
+   gdcmAssertMacro (ItTagHT != TagHT.end());
 
-      return tmp;
-   }
-   else
-   {
-      return NULL;
-   }
+   ++ItTagHT;
+   if (ItTagHT != TagHT.end())
+      return  ItTagHT->second;
+   return NULL;
 }
 
 //-----------------------------------------------------------------------------