From: jpr Date: Tue, 18 Jan 2005 11:39:59 +0000 (+0000) Subject: Solve pb when structure (list, map, ...) is empty. X-Git-Tag: Version1.0.bp~269 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=963480c814326423065a4a02fa1bf8bc1243ae4f;p=gdcm.git Solve pb when structure (list, map, ...) is empty. Thx to Benoit for reporting bug --- diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index 1bfa211d..f775d215 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -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; } diff --git a/src/gdcmDicomDirPatient.cxx b/src/gdcmDicomDirPatient.cxx index 690799e2..81ba4327 100644 --- a/src/gdcmDicomDirPatient.cxx +++ b/src/gdcmDicomDirPatient.cxx @@ -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 diff --git a/src/gdcmDicomDirSerie.cxx b/src/gdcmDicomDirSerie.cxx index 8632bfa2..2809fdea 100644 --- a/src/gdcmDicomDirSerie.cxx +++ b/src/gdcmDicomDirSerie.cxx @@ -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; } //----------------------------------------------------------------------------- diff --git a/src/gdcmDicomDirStudy.cxx b/src/gdcmDicomDirStudy.cxx index e1824d7f..bdb78840 100644 --- a/src/gdcmDicomDirStudy.cxx +++ b/src/gdcmDicomDirStudy.cxx @@ -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 diff --git a/src/gdcmDict.cxx b/src/gdcmDict.cxx index dc7e5c0c..f15a7536 100644 --- a/src/gdcmDict.cxx +++ b/src/gdcmDict.cxx @@ -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; } //----------------------------------------------------------------------------- diff --git a/src/gdcmDictSet.cxx b/src/gdcmDictSet.cxx index c825df10..a44e8fdc 100644 --- a/src/gdcmDictSet.cxx +++ b/src/gdcmDictSet.cxx @@ -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; } //----------------------------------------------------------------------------- diff --git a/src/gdcmElementSet.cxx b/src/gdcmElementSet.cxx index 769c7814..e43177e8 100644 --- a/src/gdcmElementSet.cxx +++ b/src/gdcmElementSet.cxx @@ -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; } //-----------------------------------------------------------------------------