X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmValEntry.cxx;h=671e6bd381f4d198301f51dfb4aae666beb25add;hb=b823b9aedd899f5bd07315943ea3cedc4637ee8a;hp=9a7d6538639aceaa38ef3ae85c5d304a9b76c544;hpb=3e82e8b67eddf5d4b95b6aa2a2e2615aced4c452;p=gdcm.git diff --git a/src/gdcmValEntry.cxx b/src/gdcmValEntry.cxx index 9a7d6538..671e6bd3 100644 --- a/src/gdcmValEntry.cxx +++ b/src/gdcmValEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmValEntry.cxx,v $ Language: C++ - Date: $Date: 2005/02/02 10:02:18 $ - Version: $Revision: 1.55 $ + Date: $Date: 2005/07/05 14:55:24 $ + Version: $Revision: 1.63 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -22,14 +22,17 @@ #include "gdcmGlobal.h" #include "gdcmUtil.h" #include "gdcmDebug.h" +#include "gdcmDocument.h" #include +#include // for isdigit +#include // for atoi namespace gdcm { //----------------------------------------------------------------------------- -#define MAX_SIZE_PRINT_ELEMENT_VALUE 128 - +#define MAX_SIZE_PRINT_ELEMENT_VALUE 0x7fffffff +uint32_t ValEntry::MaxSizePrintEntry = MAX_SIZE_PRINT_ELEMENT_VALUE; //----------------------------------------------------------------------------- // Constructor / Destructor /** @@ -60,50 +63,6 @@ ValEntry::~ValEntry () //----------------------------------------------------------------------------- // Public -/** - * \brief Sets the std::string representable' value of a ValEntry - * @param val value to set - */ -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 - { - const VRKey &vr = GetVR(); - if( vr == "US" || vr == "SS" ) - { - // for multivaluated items - l = (Util::CountSubstring(val, "\\") + 1) * 2; - ContentEntry::SetValue(val); - } - else if( vr == "UL" || vr == "SL" ) - { - // for multivaluated items - l = (Util::CountSubstring(val, "\\") + 1) * 4;; - ContentEntry::SetValue(val); - } - else - { - std::string finalVal = Util::DicomString( val.c_str() ); - gdcmAssertMacro( !(finalVal.size() % 2) ); - - l = finalVal.length(); - ContentEntry::SetValue(finalVal); - } - } - else - { - std::string finalVal = Util::DicomString( val.c_str() ); - gdcmAssertMacro( !(finalVal.size() % 2) ); - - l = finalVal.length(); - ContentEntry::SetValue(finalVal); - } - - SetLength(l); -} - /** * \brief Writes the std::string representable' value of a ValEntry * @param fp already open ofstream pointer @@ -119,7 +78,7 @@ void ValEntry::WriteContent(std::ofstream *fp, FileType filetype) } const VRKey &vr = GetVR(); - unsigned int lgr = GetLength(); + unsigned int lgth = GetLength(); if (vr == "US" || vr == "SS") { // some 'Short integer' fields may be multivaluated @@ -154,10 +113,74 @@ void ValEntry::WriteContent(std::ofstream *fp, FileType filetype) return; } - gdcmAssertMacro( lgr == GetValue().length() ); + gdcmAssertMacro( lgth == GetValue().length() ); binary_write(*fp, GetValue()); } + +/** + * \brief Header Elements too long will not be printed + * @param newSize new size + */ +void ValEntry::SetMaxSizePrintEntry(long newSize) +{ + if ( newSize < 0 ) + { + return; + } + if ((uint32_t)newSize >= (uint32_t)0xffffffff ) + { + ValEntry::MaxSizePrintEntry = 0xffffffff; + return; + } + ValEntry::MaxSizePrintEntry = newSize; +} + + +/** + * \brief Sets the std::string representable' value of a ValEntry + * @param val value to set + */ +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 + { + const VRKey &vr = GetVR(); + if ( vr == "US" || vr == "SS" ) + { + // for multivaluated items + l = (Util::CountSubstring(val, "\\") + 1) * 2; + ContentEntry::SetValue(val); + } + else if ( vr == "UL" || vr == "SL" ) + { + // for multivaluated items + l = (Util::CountSubstring(val, "\\") + 1) * 4;; + ContentEntry::SetValue(val); + } + else + { + std::string finalVal = Util::DicomString( val.c_str() ); + gdcmAssertMacro( !(finalVal.size() % 2) ); + + l = finalVal.length(); + ContentEntry::SetValue(finalVal); + } + } + else + { + std::string finalVal = Util::DicomString( val.c_str() ); + gdcmAssertMacro( !(finalVal.size() % 2) ); + + l = finalVal.length(); + ContentEntry::SetValue(finalVal); + } + + SetLength(l); +} + //----------------------------------------------------------------------------- // Protected @@ -191,9 +214,9 @@ void ValEntry::Print(std::ostream &os, std::string const &) TS *ts = Global::GetTS(); - TSAtr v = GetValue(); // not applicable for SQ ... + TSAtr v = GetValue(); d2 = Util::CreateCleanString(v); // replace non printable characters by '.' - if( GetLength() <= MAX_SIZE_PRINT_ELEMENT_VALUE + if ( (long)GetLength() <= ValEntry::GetMaxSizePrintEntry() || PrintLevel >= 3 || d2.find(GDCM_NOTLOADED) < d2.length() ) { @@ -260,7 +283,7 @@ void ValEntry::Print(std::ostream &os, std::string const &) { if (v == "4294967295") // to avoid troubles in convertion { - st = Util::Format(" x(ffffffff)"); + st = "ffffffff"; } else { @@ -270,7 +293,7 @@ void ValEntry::Print(std::ostream &os, std::string const &) } else { - st = Util::Format(" "); + st = " "; } } s << st;