X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmValEntry.cxx;h=6c10af843efc49b02aa7abf87c35f407a9df0b8e;hb=0bbf3772212391cff69ed451c0a089279ee0c27c;hp=aaf16de4d076b6fd718fe6352df86048d173a7f6;hpb=1d69b92978803204089d270599133917d944c651;p=gdcm.git diff --git a/src/gdcmValEntry.cxx b/src/gdcmValEntry.cxx index aaf16de4..6c10af84 100644 --- a/src/gdcmValEntry.cxx +++ b/src/gdcmValEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmValEntry.cxx,v $ Language: C++ - Date: $Date: 2004/10/12 04:35:48 $ - Version: $Revision: 1.30 $ + Date: $Date: 2004/12/16 13:46:38 $ + Version: $Revision: 1.41 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,10 +17,13 @@ =========================================================================*/ #include "gdcmValEntry.h" +#include "gdcmVR.h" #include "gdcmTS.h" #include "gdcmGlobal.h" #include "gdcmUtil.h" +#include + namespace gdcm { @@ -48,7 +51,6 @@ ValEntry::ValEntry(DocEntry* e) ReadLength = e->GetReadLength(); ImplicitVR = e->IsImplicitVR(); Offset = e->GetOffset(); - PrintLevel = e->GetPrintLevel(); } @@ -74,6 +76,7 @@ void ValEntry::Print(std::ostream & os) TSKey v; std::string d2; + os << "V "; DocEntry::Print(os); if (g == 0xfffe) @@ -106,7 +109,7 @@ void ValEntry::Print(std::ostream & os) { if ( v.length() != 0 ) // for brain damaged headers { - if ( ! isdigit(v[v.length()-1]) ) + if ( ! isdigit((unsigned char)v[v.length()-1]) ) { v.erase(v.length()-1, 1); } @@ -122,7 +125,7 @@ void ValEntry::Print(std::ostream & os) { if ( v.length() != 0 ) // for brain damaged headers { - if ( ! isdigit(v[v.length()-1]) ) + if ( ! isdigit((unsigned char)v[v.length()-1]) ) { v.erase(v.length()-1, 1); } @@ -138,7 +141,7 @@ void ValEntry::Print(std::ostream & os) { if ( v.length() != 0 ) // for brain damaged headers { - if ( ! isdigit(v[v.length()-1]) ) + if ( ! isdigit((unsigned char)v[v.length()-1]) ) { v.erase(v.length()-1, 1); } @@ -171,22 +174,62 @@ void ValEntry::Print(std::ostream & os) os << s.str(); } +//----------------------------------------------------------------------------- +// Public +void ValEntry::SetValue(std::string const & val) +{ + // Integers have a special treatement for their length: + int l = val.length(); + if ( l != 0) // To avoid to be cheated by 'zero length' integers + { + VRKey vr = GetVR(); + if( vr == "US" || vr == "SS" ) + { + // for multivaluated items + l = (Util::CountSubstring(val, "\\") + 1) * 2; + SetValueOnly(val); + } + else if( vr == "UL" || vr == "SL" ) + { + // for multivaluated items + l = (Util::CountSubstring(val, "\\") + 1) * 4;; + SetValueOnly(val); + } + else + { + std::string finalVal = Util::DicomString( val.c_str() ); + assert( !(finalVal.size() % 2) ); + + l = finalVal.length(); + SetValueOnly(finalVal); + } + } + else + { + std::string finalVal = Util::DicomString( val.c_str() ); + assert( !(finalVal.size() % 2) ); + + l = finalVal.length(); + SetValueOnly(finalVal); + } + + SetLength(l); +} + /* * \brief canonical Writer */ -void ValEntry::Write(FILE* fp, FileType filetype) +void ValEntry::WriteContent(std::ofstream* fp, FileType filetype) { - DocEntry::Write(fp, filetype); + DocEntry::WriteContent(fp, filetype); - //std::cout << "=====================================" << GetVR() << std::endl; - if ( GetGroup() == 0xfffe ) { return; //delimitors have NO value } std::string vr = GetVR(); - int lgr = GetReadLength(); + unsigned int lgr = GetReadLength(); if (vr == "US" || vr == "SS") { // some 'Short integer' fields may be mulivaluated @@ -198,8 +241,7 @@ void ValEntry::Write(FILE* fp, FileType filetype) for (unsigned int i=0; i