- c = CountSubstring(content, "\\") + 1; // for multivaluated items
- l = c*4;;
- }
- }
- valEntry->SetLength(l);
- return true;
-}
-
-/**
- * \brief Accesses an existing gdcmDocEntry (i.e. a Dicom Element)
- * through it's (group, element) and modifies it's content with
- * the given value.
- * @param content new value (void* -> uint8_t*) to substitute with
- * @param lgth new value length
- * @param group group number of the Dicom Element to modify
- * @param element element number of the Dicom Element to modify
- */
-bool gdcmDocument::SetEntryByNumber(uint8_t*content,
- int lgth,
- uint16_t group,
- uint16_t element)
-{
- (void)lgth; //not used
- gdcmTagKey key = gdcmDictEntry::TranslateToKey(group, element);
- if ( !TagHT.count(key))
- {
- return false;
- }
-
-/* Hope Binary field length is *never* wrong
- if(lgth%2) // Non even length are padded with a space (020H).
- {
- lgth++;
- //content = content + '\0'; // fing a trick to enlarge a binary field?
- }
-*/
- gdcmBinEntry* a = (gdcmBinEntry *)TagHT[key];
- a->SetBinArea(content);
- a->SetLength(lgth);
- a->SetValue(GDCM_BINLOADED);
-
- return true;
-}
-
-/**
- * \brief Accesses an existing gdcmDocEntry (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 gdcmDocument::SetEntryLengthByNumber(uint32_t l,
- uint16_t group,
- uint16_t element)
-{
- /// \todo use map methods, instead of multimap JPR
- gdcmTagKey key = gdcmDictEntry::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 gdcmDocument::GetEntryOffsetByNumber(uint16_t group, uint16_t elem)
-{
- gdcmDocEntry* entry = GetDocEntryByNumber(group, elem);
- if (!entry)
- {
- dbg.Verbose(1, "gdcmDocument::GetDocEntryByNumber: no entry present.");
- return 0;
- }
- return entry->GetOffset();
-}
-
-/**
- * \brief Gets (from Header) 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 Pointer to the 'non string' area
- */
-void* gdcmDocument::GetEntryBinAreaByNumber(uint16_t group, uint16_t elem)
-{
- gdcmDocEntry* entry = GetDocEntryByNumber(group, elem);
- if (!entry)
- {
- dbg.Verbose(1, "gdcmDocument::GetDocEntryByNumber: no entry");
- return 0;
- }
- return ((gdcmBinEntry *)entry)->GetBinArea();
-}
-
-/**
- * \brief Loads (from disk) the element content
- * when a string is not suitable
- * @param group group number of the Entry
- * @param elem element number of the Entry
- */
-void* gdcmDocument::LoadEntryBinArea(uint16_t group, uint16_t elem)
-{
- gdcmDocEntry *docElement = GetDocEntryByNumber(group, elem);
- if ( !docElement )
- {
- return NULL;
- }
- size_t o =(size_t)docElement->GetOffset();
- fseek(Fp, o, SEEK_SET);
- size_t l = docElement->GetLength();
- uint8_t* a = new uint8_t[l];
- if(!a)
- {
- dbg.Verbose(0, "gdcmDocument::LoadEntryBinArea cannot allocate a");
- return NULL;
- }
- size_t l2 = fread(a, 1, l , Fp);
- if( l != l2 )
- {
- delete[] a;
- return NULL;
- }
- /// \todo Drop any already existing void area! JPR
- if( !SetEntryBinAreaByNumber( a, group, elem ) );
- {
- dbg.Verbose(0, "gdcmDocument::LoadEntryBinArea setting failed.");
- }
- return a;
-}
-/**
- * \brief Loads (from disk) the element content
- * when a string is not suitable
- * @param element Entry whose binArea is going to be loaded
- */
-void* gdcmDocument::LoadEntryBinArea(gdcmBinEntry* element)
-{
- size_t o =(size_t)element->GetOffset();
- fseek(Fp, o, SEEK_SET);
- size_t l = element->GetLength();
- uint8_t* a = new uint8_t[l];
- if( !a )
- {
- dbg.Verbose(0, "gdcmDocument::LoadEntryBinArea cannot allocate a");
- return NULL;
- }
- element->SetBinArea((uint8_t*)a);
- /// \todo check the result
- size_t l2 = fread(a, 1, l , Fp);
- if( l != l2 )
- {
- delete[] a;
- return NULL;
- }
-
- return a;
-}
-
-/**
- * \brief Sets a 'non string' value to a given Dicom Element
- * @param area area containing the 'non string' value
- * @param group Group number of the searched Dicom Element
- * @param element Element number of the searched Dicom Element
- * @return
- */
-bool gdcmDocument::SetEntryBinAreaByNumber(uint8_t* area,
- uint16_t group,
- uint16_t element)
-{
- gdcmDocEntry* currentEntry = GetDocEntryByNumber(group, element);
- if ( !currentEntry )
- {
- return false;
- }
- if ( gdcmBinEntry* binEntry = dynamic_cast<gdcmBinEntry*>(currentEntry) )
- {
- binEntry->SetBinArea( area );
- return true;
- }
- return true;
-}
-
-/**
- * \brief Update the entries with the shadow dictionary.
- * Only non even entries are analyzed
- */
-void gdcmDocument::UpdateShaEntries()
-{
- //gdcmDictEntry *entry;
- std::string vr;
-
- /// \todo TODO : still any use to explore recursively the whole structure?
-/*
- for(ListTag::iterator it=listEntries.begin();
- it!=listEntries.end();
- ++it)
- {
- // Odd group => from public dictionary
- if((*it)->GetGroup()%2==0)
- continue;
-
- // Peer group => search the corresponding dict entry
- if(RefShaDict)
- entry=RefShaDict->GetDictEntryByNumber((*it)->GetGroup(),(*it)->GetElement());
- else
- entry=NULL;
-
- if((*it)->IsImplicitVR())
- vr="Implicit";
- else
- vr=(*it)->GetVR();
-
- (*it)->SetValue(GetDocEntryUnvalue(*it)); // to go on compiling
- if(entry){
- // Set the new entry and the new value
- (*it)->SetDictEntry(entry);
- CheckDocEntryVR(*it,vr);
-
- (*it)->SetValue(GetDocEntryValue(*it)); // to go on compiling
-