+/**
+ * \brief Modifies the value of a given Doc Entry (Dicom Element)
+ * when it exists. Creates 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
+ * @param vr V(alue) R(epresentation) of the Entry -if private Entry-
+ * \return pointer to the modified/created Header Entry (NULL when creation
+ * failed).
+ */
+DataEntry *DocEntrySet::InsertEntryString(std::string const &value,
+ uint16_t group, uint16_t elem,
+ VRKey const &vr )
+{
+ DataEntry *dataEntry = 0;
+ DocEntry *currentEntry = GetDocEntry( group, elem );
+ VRKey localVR = vr;
+ if (currentEntry)
+ {
+ dataEntry = dynamic_cast<DataEntry *>(currentEntry);
+
+ // Verify the VR
+ if ( dataEntry )
+ if ( dataEntry->GetVR()!=vr )
+ dataEntry = NULL;
+
+ // if currentEntry doesn't correspond to the requested dataEntry
+ if ( !dataEntry)
+ {
+ if ( !RemoveEntry(currentEntry) )
+ {
+ gdcmWarningMacro( "Removal of previous DocEntry failed.");
+ return NULL;
+ }
+ }
+ }
+
+ else // the 'currentEntry' was not found
+ {
+ if ( vr == GDCM_VRUNKNOWN ) // user didn't specify a VR.
+ // Probabely he trusts the Dicom Dict !
+ {
+ DictEntry *e =
+ Global::GetDicts()->GetDefaultPubDict()->GetEntry(group, elem);
+ if ( e )
+ {
+ localVR = e->GetVR();
+ e->Register(); // ?? JPRx
+ }
+ }
+ }
+
+ // Create a new dataEntry if necessary
+ if ( !dataEntry )
+ {
+ dataEntry = NewDataEntry( group, elem, localVR );
+
+ if ( !AddEntry(dataEntry) )
+ {
+ gdcmWarningMacro("AddEntry " << dataEntry->GetKey()
+ << " failed although this is a creation.");
+ dataEntry->Delete();
+ return NULL;
+ }
+ dataEntry->Delete(); // ?!? JPRx
+ }
+
+ // Set the dataEntry value
+ SetEntryString(value, dataEntry); // The std::string value
+ return dataEntry;
+}