+/**
+ * \brief Assuming the internal file pointer \ref gdcmDocument::fp
+ * is placed at the beginning of a tag (TestGroup, TestElement),
+ * read the length associated to the Tag.
+ * \warning On success the internal file pointer \ref gdcmDocument::fp
+ * is modified to point after the tag and it's length.
+ * On failure (i.e. when the tag wasn't the expected tag
+ * (TestGroup, TestElement) the internal file pointer
+ * \ref gdcmDocument::fp is restored to it's original position.
+ * @param TestGroup The expected group of the tag.
+ * @param TestElement The expected Element of the tag.
+ * @return On success returns the length associated to the tag. On failure
+ * returns 0.
+ */
+guint32 gdcmDocument::ReadTagLength(guint16 TestGroup, guint16 TestElement)
+{
+ guint16 ItemTagGroup;
+ guint16 ItemTagElement;
+ long PositionOnEntry = ftell(fp);
+ long CurrentPosition = ftell(fp); // On debugging purposes
+
+ //// Read the Item Tag group and element, and make
+ // sure they are respectively 0xfffe and 0xe000:
+ ItemTagGroup = ReadInt16();
+ ItemTagElement = ReadInt16();
+ if ( (ItemTagGroup != TestGroup) || (ItemTagElement != TestElement ) )
+ {
+ std::ostringstream s;
+ s << " We should have found tag (";
+ s << std::hex << TestGroup << "," << TestElement << ")" << std::endl;
+ s << " but instead we encountered tag (";
+ s << std::hex << ItemTagGroup << "," << ItemTagElement << ")"
+ << std::endl;
+ s << " at address: " << (unsigned)CurrentPosition << std::endl;
+ dbg.Verbose(0, "gdcmDocument::ReadItemTagLength: wrong Item Tag found:");
+ dbg.Verbose(0, s.str().c_str());
+ fseek(fp, PositionOnEntry, SEEK_SET);
+ return 0;
+ }
+
+ //// Then read the associated Item Length
+ CurrentPosition=ftell(fp);
+ guint32 ItemLength;
+ ItemLength = ReadInt32();
+ {
+ std::ostringstream s;
+ s << "Basic Item Length is: "
+ << ItemLength << std::endl;
+ s << " at address: " << (unsigned)CurrentPosition << std::endl;
+ dbg.Verbose(0, "gdcmDocument::ReadItemTagLength: ", s.str().c_str());
+ }
+ return ItemLength;
+}
+
+/**
+ * \brief Read the length of an exptected Item tag i.e. (0xfffe, 0xe000).
+ * \sa \ref gdcmDocument::ReadTagLength
+ * \warning See warning of \ref gdcmDocument::ReadTagLength
+ * @return On success returns the length associated to the item tag.
+ * On failure returns 0.
+ */
+guint32 gdcmDocument::ReadItemTagLength(void)
+{
+ return ReadTagLength(0xfffe, 0xe000);
+}
+
+/**
+ * \brief Read the length of an exptected Sequence Delimiter tag i.e.
+ * (0xfffe, 0xe0dd).
+ * \sa \ref gdcmDocument::ReadTagLength
+ * \warning See warning of \ref gdcmDocument::ReadTagLength
+ * @return On success returns the length associated to the Sequence
+ * Delimiter tag. On failure returns 0.
+ */
+guint32 gdcmDocument::ReadSequenceDelimiterTagLength(void)
+{
+ return ReadTagLength(0xfffe, 0xe0dd);
+}
+