]> 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 1bfa211..f775d21 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 690799e..81ba432 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 8632bfa..2809fde 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 e1824d7..bdb7884 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 dc7e5c0..f15a753 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 c825df1..a44e8fd 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 769c781..e43177e 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;
 }
 
 //-----------------------------------------------------------------------------