Skip to content

Commit b118992

Browse files
committed
spectools: use a callback in EbmlCallbacks to validate the size of an element
So it can be checked even before the element is created.
1 parent 8221e51 commit b118992

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

spectool/schema_2_kaxsemantic_cpp.xsl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ static constexpr const MatroskaProfile VERSION_MATROSKA_UP_TO_V2 = {false, false
5959
static constexpr const MatroskaProfile VERSION_MATROSKA_UP_TO_V3 = {false, false, 0, 3};
6060
// available since version 1, 2, 3 and 4 of Matroska and WebM but not DivX
6161
static constexpr const MatroskaProfile VERSION_WEBM_UP_TO_V4 = {true, false, 0, 4};
62+
63+
static inline bool ValidateBinary4(std::uint64_t Size)
64+
{
65+
return Size == 4;
66+
}
67+
68+
static inline bool ValidateBinary16(std::uint64_t Size)
69+
{
70+
return Size == 16;
71+
}
72+
6273
<xsl:for-each select="ebml:element[not(starts-with(@path,'\EBML\'))]">
6374
<!-- sorting messes the detection of the previous element MATROSKA_VERSION state -->
6475
<!-- Maybe for each output we create we also create a counterpart call to check if the new MATROSKA_VERSION state that should be used -->
@@ -176,6 +187,13 @@ static constexpr const MatroskaProfile VERSION_WEBM_UP_TO_V4 = {true, false, 0,
176187
<xsl:call-template name="output-display-name">
177188
<xsl:with-param name="node" select="."/>
178189
</xsl:call-template>
190+
<xsl:choose>
191+
<xsl:when test="@length=4"><xsl:text>, ValidateBinary4</xsl:text></xsl:when>
192+
<xsl:when test="@length=16"><xsl:text>, ValidateBinary16</xsl:text></xsl:when>
193+
<xsl:when test="@name='Block' or @name='SimpleBlock' or @name='BlockVirtual'"><xsl:text>, KaxInternalBlock::SizeIsValid</xsl:text></xsl:when>
194+
<xsl:when test="not(@length)"><xsl:text>, libebml::EbmlCallbacks::AnySizeValid</xsl:text></xsl:when>
195+
<xsl:otherwise><xsl:text>, false</xsl:text></xsl:otherwise>
196+
</xsl:choose>
179197
<xsl:call-template name="output-minmax">
180198
<xsl:with-param name="node" select="."/>
181199
</xsl:call-template>

spectool/schema_2_kaxsemantic_h.xsl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ namespace libmatroska {
6767
</xsl:when>
6868
<xsl:when test="@type='binary'">
6969
<xsl:text>DECLARE_MKX_BINARY</xsl:text>
70-
<xsl:if test="@length"><xsl:text>_LENGTH</xsl:text></xsl:if>
7170
</xsl:when>
7271
<xsl:when test="@type='uinteger'">
7372
<xsl:text>DECLARE_MKX_UINTEGER</xsl:text>
@@ -98,9 +97,6 @@ namespace libmatroska {
9897
<xsl:call-template name="get-class-name">
9998
<xsl:with-param name="node" select="."/>
10099
</xsl:call-template>
101-
<xsl:if test="@length">
102-
<xsl:text>, </xsl:text><xsl:value-of select="@length"/>
103-
</xsl:if>
104100
<xsl:text>)&#10;</xsl:text>
105101
<xsl:if test="@maxver='0' or @maxver='1' or @maxver='2' or @maxver='3'">
106102
<xsl:text>public:&#10;</xsl:text>

0 commit comments

Comments
 (0)