]> Creatis software - gdcm.git/blobdiff - src/gdcmElValSet.cxx
* vtk subdir added. Contains vtkGdcmReader.[cxx|h] a vtk class
[gdcm.git] / src / gdcmElValSet.cxx
index b6dfbfb9ad3b3c72b5bd23db97058bb0b06079ee..5d33ab6474792e64eee66ef5addd2f7f60a91097 100644 (file)
@@ -4,6 +4,18 @@
 #include "gdcmUtil.h"
 #include "gdcmElValSet.h"
 
+gdcmElValSet::~gdcmElValSet() {
+   for (TagElValueHT::iterator tag = tagHt.begin(); tag != tagHt.end(); ++tag) {
+      gdcmElValue* EntryToDelete = tag->second;
+      if ( EntryToDelete )
+         delete EntryToDelete;
+   }
+   tagHt.clear();
+   // Since Add() adds symetrical in both tagHt and NameHt we can
+   // assume all the pointed gdcmElValues are allready cleaned-up when
+   // we cleaned tagHt.
+   NameHt.clear();
+}
 
 TagElValueHT & gdcmElValSet::GetTagHt(void) {
        return tagHt;
@@ -70,8 +82,18 @@ int gdcmElValSet::SetElValueByNumber(string content,
        TagKey key = gdcmDictEntry::TranslateToKey(group, element);
        if ( ! tagHt.count(key))
                return 0;
-       tagHt[key]->SetValue(content);
-       tagHt[key]->SetLength(content.length());         
+       tagHt[key]->SetValue(content);  
+       string vr = tagHt[key]->GetVR();
+       guint32 lgr;
+
+       if( (vr == "US") || (vr == "SS") ) 
+          lgr = 2;
+       else if( (vr == "UL") || (vr == "SL") )
+          lgr = 4;
+       else 
+          lgr = content.length();
+          
+       tagHt[key]->SetLength(lgr); 
        return 1;
 }
 
@@ -79,7 +101,17 @@ int gdcmElValSet::SetElValueByName(string content, string TagName) {
        if ( ! NameHt.count(TagName))
                return 0;
        NameHt[TagName]->SetValue(content);
-       NameHt[TagName]->SetLength(content.length());
+       string vr = NameHt[TagName]->GetVR();
+       guint32 lgr;
+
+       if( (vr == "US") || (vr == "SS") ) 
+          lgr = 2;
+       else if( (vr == "UL") || (vr == "SL") )
+          lgr = 4;
+       else 
+          lgr = content.length();
+          
+       NameHt[TagName]->SetLength(lgr);
        return 1;               
 }
 
@@ -195,9 +227,6 @@ void gdcmElValSet::UpdateGroupLength(bool SkipSequence, FileType type) {
       str_trash=trash;
       elemZ->SetValue(str_trash);
    }   
-   
-   // Liberer groupHt !
-   
 }
 
 void gdcmElValSet::WriteElements(FileType type, FILE * _fp) {
@@ -270,6 +299,7 @@ void gdcmElValSet::WriteElements(FileType type, FILE * _fp) {
          }
          continue;
       }
+      tokens.clear();
 
       // Les pixels ne sont pas chargés dans l'element !
       if ((gr == 0x7fe0) && (el == 0x0010) ) break;