+/**
+ * \ingroup DocEntry
+ * \brief Writes the common part of any ValEntry, BinEntry, SeqEntry
+ * @param fp already open file pointer
+ * @param filetype type of the file to be written
+ */
+void DocEntry::Write(std::ofstream* fp, FileType filetype)
+{
+ uint32_t ffff = 0xffffffff;
+ uint16_t group = GetGroup();
+ VRKey vr = GetVR();
+ uint16_t el = GetElement();
+ uint32_t lgr = GetReadLength();
+
+ 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
+ binary_write( *fp, el); //element
+
+ 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)
+ // The end of a given Item will be found when :
+ // - a new Item Delimitor Item is encountered (the Seq goes on)
+ // - a Sequence Delimitor Item is encountered (the Seq just ended)
+
+ // TODO : verify if the Sequence Delimitor Item was forced during Parsing
+
+ uint32_t ff = 0xffffffff;
+ binary_write(*fp, ff);
+ return;
+ }
+
+ uint16_t z = 0;
+ uint16_t shortLgr = lgr;
+
+ if (vr == "unkn")
+ {
+ // Unknown was 'written'
+ // deal with Little Endian
+ binary_write(*fp, shortLgr);
+ binary_write(*fp, z);
+ }
+ else
+ {
+ binary_write(*fp, vr);
+ assert( 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, lgr);
+ }
+ }
+ else
+ {
+ binary_write(*fp, shortLgr);
+ }
+ }
+ }
+ else // IMPLICIT VR
+ {
+ if (vr == "SQ")
+ {
+ binary_write(*fp, ffff);
+ }
+ else
+ {
+ binary_write(*fp, lgr);
+ }
+ }
+}
+