X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmDocument.cxx;h=e5e627e436fe4b9390379491fc5f5c4a84e05339;hb=99ac30f10909a566e9506776d33dfacc300d4502;hp=e561603b8384e10910d82ac1dbbc06568944339c;hpb=ba0e5f31e5fc2a303e79c340f36bef25e4fb172d;p=gdcm.git diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index e561603b..e5e627e4 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2004/11/30 16:59:32 $ - Version: $Revision: 1.144 $ + Date: $Date: 2004/12/10 13:49:07 $ + Version: $Revision: 1.150 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -23,6 +23,13 @@ #include "gdcmGlobal.h" #include "gdcmUtil.h" #include "gdcmDebug.h" +#include "gdcmTS.h" +#include "gdcmException.h" +#include "gdcmDictSet.h" +#include "gdcmRLEFramesInfo.h" +#include "gdcmJPEGFragmentsInfo.h" +#include "gdcmDocEntrySet.h" +#include "gdcmSQItem.h" #include #include @@ -411,7 +418,11 @@ FileType Document::GetFileType() */ std::ifstream* Document::OpenFile() { - if (Filename.length() == 0) return 0; + if (Filename.length() == 0) + { + return 0; + } + if(Fp) { dbg.Verbose( 0, @@ -420,17 +431,23 @@ std::ifstream* Document::OpenFile() } Fp = new std::ifstream(Filename.c_str(), std::ios::in | std::ios::binary); - - if(!Fp) + if( ! *Fp ) { dbg.Verbose( 0, "Document::OpenFile cannot open file: ", Filename.c_str()); + delete Fp; + Fp = 0; return 0; } uint16_t zero; - Fp->read((char*)&zero, (size_t)2 ); + Fp->read((char*)&zero, (size_t)2); + if( Fp->eof() ) + { + CloseFile(); + return 0; + } //ACR -- or DICOM with no Preamble; may start with a Shadow Group -- if( @@ -446,6 +463,11 @@ std::ifstream* Document::OpenFile() Fp->seekg(126L, std::ios::cur); char dicm[4]; Fp->read(dicm, (size_t)4); + if( Fp->eof() ) + { + CloseFile(); + return 0; + } if( memcmp(dicm, "DICM", 4) == 0 ) { return Fp; @@ -649,6 +671,7 @@ BinEntry* Document::ReplaceOrCreateByNumber( dbg.Verbose(0, "Document::ReplaceOrCreateByNumber: AddEntry" " failed allthough this is a creation."); } + delete currentEntry; } else { @@ -816,7 +839,6 @@ std::string Document::GetEntryVRByName(TagName const& tagName) std::string Document::GetEntryByNumber(uint16_t group, uint16_t element) { TagKey key = DictEntry::TranslateToKey(group, element); - /// \todo use map methods, instead of multimap JPR if ( !TagHT.count(key)) { return GDCM_UNFOUND; @@ -896,9 +918,6 @@ bool Document::SetEntryByName( std::string const & content, bool Document::SetEntryByNumber(std::string const& content, uint16_t group, uint16_t element) { - int c; - int l; - ValEntry* valEntry = GetValEntryByNumber(group, element); if (!valEntry ) { @@ -907,30 +926,7 @@ bool Document::SetEntryByNumber(std::string const& content, return false; } // Non even content must be padded with a space (020H)... - 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(); - if ( l != 0) // To avoid to be cheated by 'zero length' integers - { - VRKey vr = valEntry->GetVR(); - if( vr == "US" || vr == "SS" ) - { - // for multivaluated items - c = Util::CountSubstring(content, "\\") + 1; - l = c*2; - } - else if( vr == "UL" || vr == "SL" ) - { - // for multivaluated items - c = Util::CountSubstring(content, "\\") + 1; - l = c*4;; - } - } - valEntry->SetLength(l); + valEntry->SetValue(content); return true; } @@ -968,53 +964,6 @@ bool Document::SetEntryByNumber(uint8_t*content, int lgth, return true; } -/** - * \brief Accesses an existing DocEntry (i.e. a Dicom Element) - * in the PubDocEntrySet of this instance - * through it's (group, element) and modifies it's length with - * the given value. - * \warning Use with extreme caution. - * @param l new length to substitute with - * @param group group number of the Entry to modify - * @param element element number of the Entry to modify - * @return true on success, false otherwise. - */ -/*bool Document::SetEntryLengthByNumber(uint32_t l, - uint16_t group, uint16_t element) -{ - /// \todo use map methods, instead of multimap JPR - TagKey key = DictEntry::TranslateToKey(group, element); - if ( !TagHT.count(key) ) - { - return false; - } - if ( l % 2 ) - { - l++; // length must be even - } - ( ((TagHT.equal_range(key)).first)->second )->SetLength(l); - - return true ; -}*/ - -/** - * \brief Gets (from Header) the offset of a 'non string' element value - * (LoadElementValues has already be executed) - * @param group group number of the Entry - * @param elem element number of the Entry - * @return File Offset of the Element Value - */ -/*size_t Document::GetEntryOffsetByNumber(uint16_t group, uint16_t elem) -{ - DocEntry* entry = GetDocEntryByNumber(group, elem); - if (!entry) - { - dbg.Verbose(1, "Document::GetDocEntryByNumber: no entry present."); - return 0; - } - return entry->GetOffset(); -}*/ - /** * \brief Gets (from Header) a 'non string' element value * (LoadElementValues has already be executed) @@ -1887,7 +1836,6 @@ void Document::FindDocEntryVR( DocEntry *entry ) // within an explicit VR file. Hence we make sure the present tag // is in explicit VR and try to fix things if it happens not to be // the case. - Fp->read (vr, (size_t)2); vr[2] = 0; @@ -2397,6 +2345,7 @@ void Document::Initialise() RefShaDict = NULL; RLEInfo = new RLEFramesInfo; JPEGInfo = new JPEGFragmentsInfo; + Filetype = Unknown; } /** @@ -2690,7 +2639,6 @@ void Document::HandleBrokenEndian(uint16_t group, uint16_t elem) reversedEndian--; SwitchSwapToBigEndian(); } - } /**