Program: gdcm
Module: $RCSfile: gdcmDocument.cxx,v $
Language: C++
- Date: $Date: 2004/10/25 03:35:20 $
- Version: $Revision: 1.113 $
+ Date: $Date: 2004/11/05 20:23:14 $
+ Version: $Revision: 1.117 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
if (filetype == ImplicitVR)
{
- std::string ts = TransferSyntaxStrings[ImplicitVRLittleEndian];
+ std::string ts =
+ Util::DicomString( TransferSyntaxStrings[ImplicitVRLittleEndian] );
ReplaceOrCreateByNumber(ts, 0x0002, 0x0010);
/// \todo Refer to standards on page 21, chapter 6.2
if (filetype == ExplicitVR)
{
- std::string ts = TransferSyntaxStrings[ExplicitVRLittleEndian];
+ std::string ts =
+ Util::DicomString( TransferSyntaxStrings[ExplicitVRLittleEndian] );
ReplaceOrCreateByNumber(ts, 0x0002, 0x0010);
/// \todo Refer to standards on page 21, chapter 6.2
bool Document::CheckIfEntryExistByNumber(uint16_t group, uint16_t element )
{
const std::string &key = DictEntry::TranslateToKey(group, element );
- return TagHT.count(key);
+ return TagHT.count(key) != 0;
}
/**
return false;
}
// Non even content must be padded with a space (020H)...
- std::string finalContent = content;
- if( finalContent.length() % 2 )
- {
- finalContent += '\0'; // ... therefore we padd with (000H) .!?!
- }
+ std::string finalContent = Util::DicomString( content.c_str() );
+ assert( !(finalContent.size() % 2) );
valEntry->SetValue(finalContent);
-
+
// Integers have a special treatement for their length:
l = finalContent.length();
}
// to be sure we are at the end of the value ...
- Fp->seekg((long)entry->GetOffset()+(long)entry->GetLength(),std::ios_base::beg);
+ Fp->seekg((long)entry->GetOffset()+(long)entry->GetLength(),
+ std::ios_base::beg);
return;
}
return;
}
- // We need an additional byte for storing \0 that is not on disk
+ // FIXME: We need an additional byte for storing \0 that is not on disk
char *str = new char[length+1];
Fp->read(str, (size_t)length);
- str[length] = '\0';
- std::string newValue = str;
+ str[length] = '\0'; //this is only useful when length is odd
+ // Special DicomString call to properly handle \0 and even length
+ std::string newValue;
+ if( length % 2 )
+ {
+ newValue = Util::DicomString(str, length+1);
+ //dbg.Verbose(0, "Warning: bad length: ", length );
+ dbg.Verbose(0, "For string :", newValue.c_str());
+ // Since we change the length of string update it length
+ entry->SetReadLength(length+1);
+ }
+ else
+ {
+ newValue = Util::DicomString(str, length);
+ }
delete[] str;
if ( ValEntry* valEntry = dynamic_cast<ValEntry* >(entry) )
- {
+ {
if ( Fp->fail() || Fp->eof())//Fp->gcount() == 1
{
dbg.Verbose(1, "Document::LoadDocEntry",
{
uint16_t element = entry->GetElement();
uint16_t group = entry->GetGroup();
- std::string vr = entry->GetVR();
+ const std::string & vr = entry->GetVR();
uint32_t length = entry->GetLength();
// When we have some semantics on the element we just read, and if we
Fp->read ((char*)&g, (size_t)2);
if ( Fp->fail() )
{
- throw FormatError( "Document::ReadInt16()", " file error." );
+ throw FormatError( "Document::ReadInt16()", " file error." );
}
if( Fp->eof() )
{
//// Read the Item Tag group and element, and make
// sure they are what we expected:
- uint16_t itemTagGroup = ReadInt16();
- uint16_t itemTagElement = ReadInt16();
+ uint16_t itemTagGroup;
+ uint16_t itemTagElement;
+ try
+ {
+ itemTagGroup = ReadInt16();
+ itemTagElement = ReadInt16();
+ }
+ catch ( FormatError e )
+ {
+ //std::cerr << e << std::endl;
+ return false;
+ }
if ( itemTagGroup != testGroup || itemTagElement != testElement )
{
std::ostringstream s;
{
if (ElementSet* elementSet = dynamic_cast< ElementSet* > ( set ) )
{
- TagDocEntryHT* currentHT = elementSet->GetTagHT();
- for( TagDocEntryHT::const_iterator i = currentHT->begin();
- i != currentHT->end();
+ TagDocEntryHT const & currentHT = elementSet->GetTagHT();
+ for( TagDocEntryHT::const_iterator i = currentHT.begin();
+ i != currentHT.end();
++i)
{
DocEntry* entry = i->second;