+ DicomDict = in;
+ SetKey( in->GetKey( ) );
+ Offset = 0 ; // To avoid further missprinting
+
+ // init some variables
+ ReadLength = 0;
+ Length = 0;
+}
+
+//-----------------------------------------------------------------------------
+// Public
+/**
+ * \brief Writes the common part of any ValEntry, BinEntry, SeqEntry
+ * @param fp already open ofstream pointer
+ * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
+ */
+void DocEntry::WriteContent(std::ofstream *fp, FileType filetype)
+{
+ uint32_t ffff = 0xffffffff;
+ uint16_t group = GetGroup();
+ VRKey vr = GetVR();
+ uint16_t el = GetElement();
+ uint32_t lgth = GetLength();
+
+ if ( group == 0xfffe && el == 0x0000 )
+ {
+ // Fix in order to make some MR PHILIPS images e-film readable
+ // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm:
+ // we just *always* ignore spurious fffe|0000 tag !
+ return;
+ }
+ //
+ // ----------- Writes the common part
+ //
+ binary_write( *fp, group); //group number
+ binary_write( *fp, el); //element number
+
+ if ( filetype == ExplicitVR )
+ {
+ // Special case of delimiters:
+ if (group == 0xfffe)
+ {
+ // Delimiters have NO Value Representation
+ // Hence we skip writing the VR.
+ // In order to avoid further troubles, we choose to write them
+ // as 'no-length' Item Delimitors (we pad by writing 0xffffffff)
+ // We shall force the end of a given Item by writting
+ // a Item Delimitation Item (fffe, e00d)
+
+ uint32_t ff = 0xffffffff;
+ binary_write(*fp, ff);
+ return;
+ }
+
+ uint16_t z = 0;
+ uint16_t shortLgr = (uint16_t)lgth;
+
+ if (vr == GDCM_UNKNOWN)
+ {
+ // Unknown was 'written'
+ // deal with Little Endian
+ binary_write(*fp, shortLgr);
+ binary_write(*fp, z);
+ }
+ else
+ {
+ binary_write(*fp, vr);
+ gdcmAssertMacro( vr.size() == 2 );
+
+ if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || (vr == "UN") )
+ {
+ binary_write(*fp, z);
+ if (vr == "SQ")
+ {
+ // we set SQ length to ffffffff
+ // and we shall write a Sequence Delimitor Item
+ // at the end of the Sequence!
+ binary_write(*fp, ffff);
+ }
+ else
+ {
+ binary_write(*fp, lgth);
+ }
+ }
+ else
+ {
+ binary_write(*fp, shortLgr);
+ }
+ }
+ }
+ else // IMPLICIT VR
+ {
+ if (vr == "SQ")
+ {
+ binary_write(*fp, ffff);
+ }
+ else
+ {
+ binary_write(*fp, lgth);
+ }
+ }
+}
+
+/**
+ * \brief Gets the full length of the elementary DocEntry (not only value
+ * length) depending on the VR.
+ */
+uint32_t DocEntry::GetFullLength()
+{
+ uint32_t l = GetReadLength();
+ if ( IsImplicitVR() )
+ {
+ l = l + 8; // 2 (gr) + 2 (el) + 4 (lgth)
+ }
+ else
+ {
+ if ( GetVR()=="OB" || GetVR()=="OW" || GetVR()=="SQ" )
+ {
+ l = l + 12; // 2 (gr) + 2 (el) + 2 (vr) + 2 (unused) + 4 (lgth)
+ }
+ else
+ {
+ l = l + 8; // 2 (gr) + 2 (el) + 2 (vr) + 2 (lgth)
+ }
+ }
+ return l;
+}
+
+/**
+ * \brief tells us if entry is the last one of a 'no length' SequenceItem
+ * (fffe,e00d)
+ */
+bool DocEntry::IsItemDelimitor()
+{
+ return (GetGroup() == 0xfffe && GetElement() == 0xe00d);