- return gdcmGlobal::GetDicts()->NewVirtualDictEntry(group,element,vr,fourth,name);
-}
+ 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;
+}