+ {
+ PreviousDocEntry = newDocEntry;
+ }
+
+ used = true;
+ newDataEntry = dynamic_cast<DataEntry*>(newDocEntry);
+
+ if ( newDataEntry )
+ {
+ //////////////////////////// DataEntry
+
+ //vr = newDocEntry->GetVR(); // useless ?
+
+ if ( !set->AddEntry( newDataEntry ) )
+ {
+ gdcmDebugMacro( "in ParseDES : cannot add a DataEntry "
+ << newDataEntry->GetKey()
+ << " (at offset : 0x("
+ << newDataEntry->GetOffset() << ") )" );
+ used=false;
+ }
+ else
+ {
+ newDataEntry->Delete();
+ // Load only if we can add (not a duplicate key)
+ LoadDocEntry( newDataEntry );
+ }
+ if ( newDataEntry->GetElement() == 0x0000 ) // if on group length
+ {
+ if ( newDataEntry->GetGroup()%2 != 0 ) // if Shadow Group
+ {
+ if ( LoadMode & LD_NOSHADOW ) // if user asked to skip shad.gr
+ {
+ std::string strLgrGroup = newDataEntry->GetString();
+
+ int lgrGroup;
+ //if ( newDataEntry->IsUnfound() ) /?!? JPR
+ {
+ lgrGroup = atoi(strLgrGroup.c_str());
+ Fp->seekg(lgrGroup, std::ios::cur); // Once per Shadow group, when NOSHADOW
+ RemoveEntry( newDocEntry ); // Remove and delete
+ continue;
+ }
+ }
+ }
+ }
+
+ bool delimitor = newDataEntry->IsItemDelimitor();
+ bool outOfBounds = false;
+ if (!delim_mode )
+ if ( ((long)(Fp->tellg())-offset) >= l_max ) //Once per DataEntry when no delim mode
+ outOfBounds = true;
+
+ // 'and then', 'or else' don't exist in C++ :-(
+ // if ( (delimitor) ||
+ // (!delim_mode && ((long)(Fp->tellg())-offset) >= l_max) ) // Once per DataEntry
+
+ if ( delimitor || outOfBounds )
+ {
+ if ( !used )
+ newDocEntry->Delete();
+ break;
+ }
+
+ // Just to make sure we are at the beginning of next entry.
+ SkipToNextDocEntry(newDocEntry); // FIXME : once per DocEntry, segfault if commented out
+ }
+ else
+ {
+ /////////////////////// SeqEntry : VR = "SQ"
+
+ unsigned long l = newDocEntry->GetReadLength();
+ if ( l != 0 ) // don't mess the delim_mode for 'zero-length sequence'
+ {
+ if ( l == 0xffffffff )
+ {
+ delim_mode_intern = true;
+ }
+ else
+ {
+ delim_mode_intern = false;
+ }
+ }
+
+ if ( (LoadMode & LD_NOSHADOWSEQ) && ! delim_mode_intern )
+ {
+ // User asked to skip SeQuences *only* if they belong to Shadow Group
+ if ( newDocEntry->GetGroup()%2 != 0 )
+ {
+ Fp->seekg( l, std::ios::cur); // once per SQITEM, when NOSHADOWSEQ
+ newDocEntry->Delete(); // Delete, not in the set
+ continue;
+ }
+ }
+ if ( (LoadMode & LD_NOSEQ) && ! delim_mode_intern )
+ {
+ // User asked to skip *any* SeQuence
+ Fp->seekg( l, std::ios::cur); // Once per SQ, when NOSEQ
+ newDocEntry->Delete(); // Delete, not in the set
+ continue;
+ }
+ // delay the dynamic cast as late as possible
+ newSeqEntry = dynamic_cast<SeqEntry*>(newDocEntry);
+
+ // no other way to create the Delimitor ...
+ newSeqEntry->SetDelimitorMode( delim_mode_intern );
+
+ // At the top of the hierarchy, stands a Document. When "set"
+ // is a Document, then we are building the first depth level.
+ // Hence the SeqEntry we are building simply has a depth
+ // level of one:
+ if ( set == this ) // ( dynamic_cast< Document* > ( set ) )
+ {
+ newSeqEntry->SetDepthLevel( 1 );
+ }
+ // But when "set" is already a SQItem, we are building a nested
+ // sequence, and hence the depth level of the new SeqEntry
+ // we are building, is one level deeper: