]> Creatis software - gdcm.git/commitdiff
Avoid troubles while parsing source dictionaries
authorjpr <jpr>
Wed, 12 Apr 2006 10:55:49 +0000 (10:55 +0000)
committerjpr <jpr>
Wed, 12 Apr 2006 10:55:49 +0000 (10:55 +0000)
src/gdcmCommon.h
src/gdcmDict.cxx

index 76d2dc4d791725d52384576ec8ea8d065b31083c..95d8978cda6f69dcd021236521dfd23219e731bc 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmCommon.h,v $
   Language:  C++
-  Date:      $Date: 2006/04/11 16:03:26 $
-  Version:   $Revision: 1.109 $
+  Date:      $Date: 2006/04/12 10:55:49 $
+  Version:   $Revision: 1.110 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -45,7 +45,10 @@ namespace gdcm
 #ifndef PUB_DICT_PATH
 #  define PUB_DICT_PATH   "../Dicts/"
 #endif
-#define PUB_DICT_NAME     "DicomV3Dict"
+#define PUB_DICT_NAME     "dicomV3Dict"
+// dicomV3.dic replaced by the generated gdcm.dic/
+// if gdcm.dic not found, method FillDefaultDataDict() is invoked
+//#define PUB_DICT_FILENAME "dicomV3.dic"
 #define PUB_DICT_FILENAME "gdcm.dic"
 #define DICT_ELEM         "DicomDir.dic"
 #define DICT_TS           "dicomTS.dic"
index 6d20d5eb0ac5ed39b0fe8d6ff9ebaaf8f98c0ade..ac25a041290ecc7fa307ad743b571c9084d0ab0f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDict.cxx,v $
   Language:  C++
-  Date:      $Date: 2006/04/11 16:03:26 $
-  Version:   $Revision: 1.84 $
+  Date:      $Date: 2006/04/12 10:55:49 $
+  Version:   $Revision: 1.85 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -56,7 +56,7 @@ Dict::Dict(std::string const &filename)
       FillDefaultDataDict( this );
    }
    else
-   {
+   { 
       gdcmDebugMacro( "in Dict::Dict, DoTheLoadingJob filename =[" 
                     << filename << "]" );
       DoTheLoadingJob(from);
@@ -82,7 +82,6 @@ Dict::~Dict()
  */
 bool Dict::AddDict(std::string const &filename)
 {
-
    std::ifstream from( filename.c_str() );
    if ( !from )
    {
@@ -96,7 +95,6 @@ bool Dict::AddDict(std::string const &filename)
    }
 }
 
-
 /**
  * \brief   Removes from the current Dicom Dict all the entries held in a source dictionary
  * \note it concerns only Private Dictionnary
@@ -118,10 +116,14 @@ bool Dict::RemoveDict(std::string const &filename)
       TagName vm;
       TagName name;
 
-      while (!from.eof() && from)
+      while ( true )
       {
          from >> std::hex;
          from >> group;
+
+         if (from.eof())
+            break;
+
          from >> elem;
          from >> vr;
          from >> vm;
@@ -157,10 +159,10 @@ bool Dict::AddEntry(DictEntry *newEntry)
    }
 }
 
-/**
- * \brief  replaces an already existing Dicom Element by a new one
- * @param   newEntry new entry (overwrites any previous one with same tag)
- * @return  false if Dicom Element doesn't exist
+/*
+ * \ brief  replaces an already existing Dicom Element by a new one
+ * @ param   newEntry new entry (overwrites any previous one with same tag)
+ * @ return  false if Dicom Element doesn't exist
  */
  
  /* seems to be useless
@@ -177,6 +179,7 @@ bool Dict::ReplaceEntry(DictEntry *newEntry) // seems to be useless
    return false;
 }
 */
+
 /**
  * \brief  removes an already existing Dicom Dictionary Entry,
  *         identified by its Tag
@@ -296,6 +299,9 @@ DictEntry *Dict::GetNextEntry()
  */
 void Dict::DoTheLoadingJob(std::ifstream &from)
 {
+   if (!from)
+      return;
+      
    uint16_t group;
    uint16_t elem;
    VRKey vr;
@@ -303,16 +309,20 @@ void Dict::DoTheLoadingJob(std::ifstream &from)
    TagName name;
 
    DictEntry *newEntry;
-   while (!from.eof() && from)
+   while ( true )
    {
       from >> std::hex;
-      from >> group;
+      from >> group;      
       from >> elem;
       from >> vr;
       from >> vm;
       from >> std::ws;  //remove white space
       std::getline(from, name);
-
+      
+      if(from.eof()) {
+         break;
+      }
+      
       newEntry = DictEntry::New(group, elem, vr, vm, name);
       AddEntry(newEntry);
       newEntry->Delete();