- * UpdateGroupLength(true,ACR);
- */
-
- gdcmElementSet::Write(fp, filetype); // This one is recursive
-
-}
-
-/**
- * \brief Modifies the value of a given Header Entry (Dicom Element)
- * when it exists. Create it with the given value when unexistant.
- * @param value (string) Value to be set
- * @param group Group number of the Entry
- * @param elem Element number of the Entry
- * \return pointer to the modified/created Header Entry (NULL when creation
- * failed).
- */
-
-gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber(
- std::string const & value,
- uint16_t group,
- uint16_t elem )
-{
- gdcmValEntry* valEntry = 0;
-
- gdcmDocEntry* currentEntry = GetDocEntryByNumber( group, elem);
- if (!currentEntry)
- {
- // The entry wasn't present and we simply create the required ValEntry:
- currentEntry = NewDocEntryByNumber(group, elem);
- if (!currentEntry)
- {
- dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: call to"
- " NewDocEntryByNumber failed.");
- return NULL;
- }
- valEntry = new gdcmValEntry(currentEntry);
- if ( !AddEntry(valEntry))
- {
- dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: AddEntry"
- " failed allthough this is a creation.");
- }
- }
- else
- {
- valEntry = dynamic_cast< gdcmValEntry* >(currentEntry);
- if ( !valEntry )
- {
- // We need to promote the gdcmDocEntry to a gdcmValEntry:
- valEntry = new gdcmValEntry(currentEntry);
- if (!RemoveEntry(currentEntry))
- {
- dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: removal"
- " of previous DocEntry failed.");
- return NULL;
- }
- if ( !AddEntry(valEntry))
- {
- dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: adding"
- " promoted ValEntry failed.");
- return NULL;
- }
- }
- }
-
- SetEntryByNumber(value, group, elem);
-
- return valEntry;
-}
-
-/*
- * \brief Modifies the value of a given Header Entry (Dicom Element)
- * when it exists. Create it with the given value when unexistant.
- * @param voidArea (binary) value to be set
- * @param Group Group number of the Entry
- * @param Elem Element number of the Entry
- * \return pointer to the modified/created Header Entry (NULL when creation
- * failed).
- */
-gdcmBinEntry * gdcmDocument::ReplaceOrCreateByNumber(
- void *voidArea,
- int lgth,
- uint16_t group,
- uint16_t elem)
-{
- gdcmBinEntry* b = 0;
- gdcmDocEntry* a = GetDocEntryByNumber( group, elem);
- if (!a)
- {
- a = NewBinEntryByNumber(group, elem);
- if (!a)
- {
- return 0;
- }
-
- b = new gdcmBinEntry(a);
- AddEntry(b);
- b->SetVoidArea(voidArea);
- }
- SetEntryByNumber(voidArea, lgth, group, elem);
- //b->SetVoidArea(voidArea); //what if b == 0 !!
-
- return b;
-}
-
-
-/*
- * \brief Modifies the value of a given Header Entry (Dicom Element)
- * when it exists. Create it when unexistant.
- * @param Group Group number of the Entry
- * @param Elem Element number of the Entry
- * \return pointer to the modified/created SeqEntry (NULL when creation
- * failed).
- */
-gdcmSeqEntry * gdcmDocument::ReplaceOrCreateByNumber(
- uint16_t group,
- uint16_t elem)
-{
- gdcmSeqEntry* b = 0;
- gdcmDocEntry* a = GetDocEntryByNumber( group, elem);
- if (!a)
- {
- a = NewSeqEntryByNumber(group, elem);
- if (!a)
- {
- return 0;
- }
-
- b = new gdcmSeqEntry(a, 1); // FIXME : 1 (Depth)
- AddEntry(b);
- }
- return b;
-}
-
-/**
- * \brief Set a new value if the invoked element exists
- * Seems to be useless !!!
- * @param value new element value
- * @param group group number of the Entry
- * @param elem element number of the Entry
- * \return boolean
- */
-bool gdcmDocument::ReplaceIfExistByNumber(std::string const & value,
- uint16_t group, uint16_t elem )
-{
- SetEntryByNumber(value, group, elem);
-
- return true;
-}
-
-//-----------------------------------------------------------------------------
-// Protected
-
-/**
- * \brief Checks if a given Dicom Element exists within the H table
- * @param group Group number of the searched Dicom Element
- * @param element Element number of the searched Dicom Element
- * @return number of occurences
- */
-int gdcmDocument::CheckIfEntryExistByNumber(uint16_t group, uint16_t element )
-{
- const std::string &key = gdcmDictEntry::TranslateToKey(group, element );
- return TagHT.count(key);
-}
-
-/**
- * \brief Searches within Header Entries (Dicom Elements) parsed with
- * the public and private dictionaries
- * for the element value of a given tag.
- * \warning Don't use any longer : use GetPubEntryByName
- * @param tagName name of the searched element.
- * @return Corresponding element value when it exists,
- * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
- */
-std::string gdcmDocument::GetEntryByName(TagName const & tagName)
-{
- gdcmDictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName);
- if( !dictEntry )
- {
- return GDCM_UNFOUND;
- }
-
- return GetEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
-}
-
-/**
- * \brief Searches within Header Entries (Dicom Elements) parsed with
- * the public and private dictionaries
- * for the element value representation of a given tag.
- *
- * Obtaining the VR (Value Representation) might be needed by caller
- * to convert the string typed content to caller's native type
- * (think of C++ vs Python). The VR is actually of a higher level
- * of semantics than just the native C++ type.
- * @param tagName name of the searched element.
- * @return Corresponding element value representation when it exists,
- * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
- */
-std::string gdcmDocument::GetEntryVRByName(TagName const & tagName)
-{
- gdcmDictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName);
- if( dictEntry == NULL)
- {
- return GDCM_UNFOUND;
- }
-
- gdcmDocEntry* elem = GetDocEntryByNumber(dictEntry->GetGroup(),
- dictEntry->GetElement());
- return elem->GetVR();
-}
-
-
-/**
- * \brief Searches within Header Entries (Dicom Elements) parsed with
- * the public and private dictionaries
- * for the element value representation of a given tag.
- * @param group Group number of the searched tag.
- * @param element Element number of the searched tag.
- * @return Corresponding element value representation when it exists,
- * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
- */
-std::string gdcmDocument::GetEntryByNumber(uint16_t group, uint16_t element)
-{
- gdcmTagKey key = gdcmDictEntry::TranslateToKey(group, element);
- /// \todo use map methods, instead of multimap JPR
- if ( !TagHT.count(key))
- {
- return GDCM_UNFOUND;
- }
-
- return ((gdcmValEntry *)TagHT.find(key)->second)->GetValue();
-}
-
-/**
- * \brief Searches within Header Entries (Dicom Elements) parsed with
- * the public and private dictionaries
- * for the element value representation of a given tag..
- *
- * Obtaining the VR (Value Representation) might be needed by caller
- * to convert the string typed content to caller's native type
- * (think of C++ vs Python). The VR is actually of a higher level
- * of semantics than just the native C++ type.
- * @param group Group number of the searched tag.
- * @param element Element number of the searched tag.
- * @return Corresponding element value representation when it exists,
- * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
- */
-std::string gdcmDocument::GetEntryVRByNumber(uint16_t group, uint16_t element)
-{
- gdcmDocEntry* elem = GetDocEntryByNumber(group, element);
- if ( !elem )
- {
- return GDCM_UNFOUND;
- }
- return elem->GetVR();
-}
-
-/**
- * \brief Searches within Header Entries (Dicom Elements) parsed with
- * the public and private dictionaries
- * for the value length of a given tag..
- * @param group Group number of the searched tag.
- * @param element Element number of the searched tag.
- * @return Corresponding element length; -2 if not found
- */
-int gdcmDocument::GetEntryLengthByNumber(uint16_t group, uint16_t element)
-{
- gdcmDocEntry* elem = GetDocEntryByNumber(group, element);
- if ( !elem )
- {
- return -2; //magic number
- }
- return elem->GetLength();
-}
-/**
- * \brief Sets the value (string) of the Header Entry (Dicom Element)
- * @param content string value of the Dicom Element
- * @param tagName name of the searched Dicom Element.
- * @return true when found
- */
-bool gdcmDocument::SetEntryByName(std::string const & content,std::string const & tagName)
-{
- gdcmDictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName);
- if( !dictEntry )
- {
- return false;
- }
-
- return SetEntryByNumber(content,dictEntry->GetGroup(),
- dictEntry->GetElement());
-}
-
-/**
- * \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 (string) to substitute with
- * @param group group number of the Dicom Element to modify
- * @param element element number of the Dicom Element to modify
- */
-bool gdcmDocument::SetEntryByNumber(std::string const & content,
- uint16_t group,
- uint16_t element)
-{
- gdcmValEntry* valEntry = GetValEntryByNumber(group, element);
- if (!valEntry )
- {
- dbg.Verbose(0, "gdcmDocument::SetEntryByNumber: no corresponding",
- " ValEntry (try promotion first).");
- return false;
- }
- // Non even content must be padded with a space (020H)...
- std::string evenContent = content;
- if( evenContent.length() % 2 )
- {
- evenContent += '\0'; // ... therefore we padd with (000H) .!?!
- }
- valEntry->SetValue(evenContent);
-
- // Integers have a special treatement for their length:
- gdcmVRKey vr = valEntry->GetVR();
- if( vr == "US" || vr == "SS" )
- {
- valEntry->SetLength(2);
- }
- else if( vr == "UL" || vr == "SL" )
- {
- valEntry->SetLength(4);
- }
- else
- {
- valEntry->SetLength(evenContent.length());
- }
-
- 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 *) 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(void *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->SetVoidArea(content);
- //a->SetLength(lgth); // ???
-
- 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