+ // Study Instance UID
+ s1 = GetEntryValue(0x0020,0x000d);
+ s2 = document.GetEntryValue(0x0020,0x000d);
+ if ( s1 < s2 )
+ {
+ return true;
+ }
+ else if( s1 > s2 )
+ {
+ return false;
+ }
+ else
+ {
+ // Serie Instance UID
+ s1 = GetEntryValue(0x0020,0x000e);
+ s2 = document.GetEntryValue(0x0020,0x000e);
+ if ( s1 < s2 )
+ {
+ return true;
+ }
+ else if( s1 > s2 )
+ {
+ return false;
+ }
+ }
+ }
+ }
+ return false;
+}
+
+//-----------------------------------------------------------------------------
+// Protected
+/**
+ * \brief Reads a supposed to be 16 Bits integer
+ * (swaps it depending on processor endianness)
+ * @return read value
+ */
+uint16_t Document::ReadInt16()
+ throw( FormatError )
+{
+ uint16_t g;
+ Fp->read ((char*)&g, (size_t)2);
+ if ( Fp->fail() )
+ {
+ throw FormatError( "Document::ReadInt16()", " file error." );
+ }
+ if( Fp->eof() )
+ {
+ throw FormatError( "Document::ReadInt16()", "EOF." );
+ }
+ g = SwapShort(g);
+ return g;
+}
+
+/**
+ * \brief Reads a supposed to be 32 Bits integer
+ * (swaps it depending on processor endianness)
+ * @return read value
+ */
+uint32_t Document::ReadInt32()
+ throw( FormatError )
+{
+ uint32_t g;
+ Fp->read ((char*)&g, (size_t)4);
+ if ( Fp->fail() )
+ {
+ throw FormatError( "Document::ReadInt32()", " file error." );
+ }
+ if( Fp->eof() )
+ {
+ throw FormatError( "Document::ReadInt32()", "EOF." );
+ }
+ g = SwapLong(g);
+ return g;
+}
+
+/**
+ * \brief skips bytes inside the source file
+ * \warning NOT end user intended method !
+ * @return
+ */
+void Document::SkipBytes(uint32_t nBytes)
+{
+ //FIXME don't dump the returned value
+ Fp->seekg((long)nBytes, std::ios::cur);
+}
+
+/**
+ * \brief Re-computes the length of a ACR-NEMA/Dicom group from a DcmHeader
+ * @param filetype Type of the File to be written
+ */
+int Document::ComputeGroup0002Length( FileType filetype )
+{
+ uint16_t gr;
+ std::string vr;
+
+ int groupLength = 0;
+ bool found0002 = false;
+
+ // for each zero-level Tag in the DCM Header
+ DocEntry *entry = GetFirstEntry();
+ while( entry )
+ {
+ gr = entry->GetGroup();
+
+ if( gr == 0x0002 )
+ {
+ found0002 = true;
+
+ if( entry->GetElement() != 0x0000 )
+ {
+ vr = entry->GetVR();
+
+ if( filetype == ExplicitVR )
+ {
+ if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") )
+ {
+ // explicit VR AND OB, OW, SQ : 4 more bytes
+ groupLength += 4;
+ }
+ }
+ groupLength += 2 + 2 + 4 + entry->GetLength();
+ }
+ }
+ else if (found0002 )
+ break;
+
+ entry = GetNextEntry();
+ }
+ return groupLength;
+}
+
+//-----------------------------------------------------------------------------
+// Private
+/**
+ * \brief Loads all the needed Dictionaries
+ * \warning NOT end user intended method !
+ */
+void Document::Initialize()
+{
+ RefPubDict = Global::GetDicts()->GetDefaultPubDict();
+ RefShaDict = NULL;
+ Filetype = Unknown;
+}
+
+/**
+ * \brief Parses a DocEntrySet (Zero-level DocEntries or SQ Item DocEntries)
+ * @return length of the parsed set.
+ */
+void Document::ParseDES(DocEntrySet *set, long offset,
+ long l_max, bool delim_mode)
+{
+ DocEntry *newDocEntry = 0;
+ ValEntry *newValEntry;
+ BinEntry *newBinEntry;
+ SeqEntry *newSeqEntry;
+ VRKey vr;
+ bool used = false;
+
+ while (true)
+ {
+ if ( !delim_mode && ((long)(Fp->tellg())-offset) >= l_max)
+ {
+ break;
+ }
+
+ used = true;
+ newDocEntry = ReadNextDocEntry( );
+
+ if ( !newDocEntry )
+ {
+ break;
+ }
+
+ vr = newDocEntry->GetVR();
+ newValEntry = dynamic_cast<ValEntry*>(newDocEntry);
+ newBinEntry = dynamic_cast<BinEntry*>(newDocEntry);
+ newSeqEntry = dynamic_cast<SeqEntry*>(newDocEntry);
+
+ if ( newValEntry || newBinEntry )
+ {
+ if ( newBinEntry )
+ {