+/**
+ * \brief Modifies the value of a given Header Entry (Dicom Element)
+ * when it exists. Create it with the given value when unexistant.
+ * A copy of the binArea is made to be kept in the Document.
+ * @param binArea (binary) value to be set
+ * @param lgth length of the Bin Area we want to 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::InsertEntryBinArea(uint8_t *binArea, int lgth,
+ uint16_t group, uint16_t elem,
+ VRKey const &vr )
+{
+ DataEntry *dataEntry = 0;
+ DocEntry *currentEntry = GetDocEntry( group, elem );
+
+ // Verify the currentEntry
+ 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;
+ }
+ }
+ }
+
+ // Create a new dataEntry if necessary
+ if ( !dataEntry)
+ {
+ dataEntry = NewDataEntry(group, elem, vr);
+
+ if ( !AddEntry(dataEntry) )
+ {
+ gdcmWarningMacro( "AddEntry failed although this is a creation.");
+ dataEntry->Delete();
+ return NULL;
+ }
+ dataEntry->Delete();
+ }
+
+ // Set the dataEntry value
+ uint8_t *tmpArea;
+ if ( lgth>0 && binArea )
+ {
+ tmpArea = new uint8_t[lgth];
+ memcpy(tmpArea,binArea,lgth);
+ }
+ else
+ {
+ tmpArea = 0;
+ }
+ if ( !SetEntryBinArea(tmpArea,lgth,dataEntry) )
+ {
+ if ( tmpArea )
+ {
+ delete[] tmpArea;
+ }
+ }
+ return dataEntry;
+}