- return gdcmGlobal::GetDicts()->NewVirtualDictEntry(group,element,vr,fourth,name);
-}
+ BinEntry *binEntry = 0;
+ DocEntry *currentEntry = GetDocEntry( group, elem );
+
+ // Verify the currentEntry
+ if (currentEntry)
+ {
+ binEntry = dynamic_cast<BinEntry *>(currentEntry);
+
+ // Verify the VR
+ if ( binEntry )
+ if ( binEntry->GetVR()!=vr )
+ binEntry = NULL;
+
+ // if currentEntry doesn't correspond to the requested valEntry
+ if ( !binEntry)
+ {
+ if ( !RemoveEntry(currentEntry) )
+ {
+ gdcmWarningMacro( "Removal of previous DocEntry failed.");
+
+ return NULL;
+ }
+ }
+ }
+
+ // Create a new binEntry if necessary
+ if ( !binEntry)
+ {
+ binEntry = NewBinEntry(group, elem, vr);
+
+ if ( !AddEntry(binEntry) )
+ {
+ gdcmWarningMacro( "AddEntry failed although this is a creation.");
+
+ delete binEntry;
+ return NULL;
+ }
+ }
+
+ // Set the binEntry value
+ uint8_t *tmpArea;
+ if ( lgth>0 && binArea )
+ {
+ tmpArea = new uint8_t[lgth];
+ memcpy(tmpArea,binArea,lgth);
+ }
+ else
+ {
+ tmpArea = 0;
+ }
+ if ( !SetBinEntry(tmpArea,lgth,binEntry) )
+ {
+ if ( tmpArea )
+ {
+ delete[] tmpArea;
+ }
+ }
+
+ return binEntry;
+}