Skip to content

Commit

Permalink
spectools: use a callback in EbmlCallbacks to validate the size of an…
Browse files Browse the repository at this point in the history
… element

So it can be checked even before the element is created.
  • Loading branch information
robUx4 committed Feb 25, 2024
1 parent 8221e51 commit 571aac1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
11 changes: 11 additions & 0 deletions spectool/schema_2_kaxsemantic_cpp.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ static constexpr const MatroskaProfile VERSION_WEBM_UP_TO_V4 = {true, false, 0,
<xsl:call-template name="output-display-name">
<xsl:with-param name="node" select="."/>
</xsl:call-template>
<xsl:choose>
<xsl:when test="@name='Block' or @name='SimpleBlock' or @name='BlockVirtual'"><xsl:text>, KaxInternalBlock::SizeIsValid</xsl:text></xsl:when>
<xsl:when test="not(@length)"><xsl:text>, libebml::EbmlBinary::SizeIsValid</xsl:text></xsl:when>
<xsl:otherwise>
<xsl:text>, Kax</xsl:text>
<xsl:call-template name="get-class-name">
<xsl:with-param name="node" select="."/>
</xsl:call-template>
<xsl:text>::SizeIsValid</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="output-minmax">
<xsl:with-param name="node" select="."/>
</xsl:call-template>
Expand Down
12 changes: 8 additions & 4 deletions spectool/schema_2_kaxsemantic_h.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ namespace libmatroska {
</xsl:when>
<xsl:when test="@type='binary'">
<xsl:text>DECLARE_MKX_BINARY</xsl:text>
<xsl:if test="@length"><xsl:text>_LENGTH</xsl:text></xsl:if>
</xsl:when>
<xsl:when test="@type='uinteger'">
<xsl:text>DECLARE_MKX_UINTEGER</xsl:text>
Expand Down Expand Up @@ -98,16 +97,21 @@ namespace libmatroska {
<xsl:call-template name="get-class-name">
<xsl:with-param name="node" select="."/>
</xsl:call-template>
<xsl:if test="@length">
<xsl:text>, </xsl:text><xsl:value-of select="@length"/>
</xsl:if>
<xsl:text>)&#10;</xsl:text>
<xsl:if test="@maxver='0' or @maxver='1' or @maxver='2' or @maxver='3'">
<xsl:text>public:&#10;</xsl:text>
</xsl:if>
<xsl:if test="@maxver='0' or @maxver='1' or @maxver='2' or @maxver='3'">
<xsl:text> libebml::filepos_t RenderData(libebml::IOCallback &amp; output, bool bForceRender, const ShouldWrite &amp; writeFilter) override;&#10;</xsl:text>
</xsl:if>
<xsl:if test="@length">
<xsl:text> static inline bool SizeIsValid(std::uint64_t Size) {return Size </xsl:text>
<xsl:choose>
<xsl:when test="contains(@length, '=') or contains(@length, '&lt;') or contains(@length, '&gt;')"><xsl:value-of select="@length"/></xsl:when>
<xsl:otherwise><xsl:text>== </xsl:text><xsl:value-of select="@length"/></xsl:otherwise>
</xsl:choose>
<xsl:text>;}&#10;</xsl:text>
</xsl:if>
<xsl:text>};&#10;</xsl:text>
<!-- <xsl:if test="$minVer &gt; 1 or ebml:extension[@divx='1']">#endif&#10;</xsl:if> -->
<xsl:text>&#10;</xsl:text>
Expand Down

0 comments on commit 571aac1

Please sign in to comment.