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/07 17:28:50 $
+ Version: $Revision: 1.40 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
=========================================================================*/
#include "gdcmValEntry.h"
+#include "gdcmVR.h"
#include "gdcmTS.h"
#include "gdcmGlobal.h"
#include "gdcmUtil.h"
+#include <fstream>
+
namespace gdcm
{
TSKey v;
std::string d2;
+ os << "V ";
DocEntry::Print(os);
if (g == 0xfffe)
{
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);
}
{
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);
}
{
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);
}
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
for (unsigned int i=0; i<tokens.size();i++)
{
uint16_t val_uint16 = atoi(tokens[i].c_str());
- void* ptr = &val_uint16;
- fwrite ( ptr,(size_t)2 ,(size_t)1 ,fp);
+ binary_write( *fp, val_uint16);
}
tokens.clear();
return;
for (unsigned int i=0; i<tokens.size();i++)
{
uint32_t val_uint32 = atoi(tokens[i].c_str());
- void* ptr = &val_uint32;
- fwrite ( ptr,(size_t)4 ,(size_t)1 ,fp);
+ binary_write( *fp, val_uint32);
}
tokens.clear();
return;
}
-
- fwrite (GetValue().c_str(), (size_t)lgr ,(size_t)1, fp); // Elem value
-}
-//-----------------------------------------------------------------------------
-// Public
+ assert( lgr == GetValue().length() );
+ binary_write(*fp, GetValue());
+}
//-----------------------------------------------------------------------------
// Protected