-
Notifications
You must be signed in to change notification settings - Fork 0
/
SISO-REF-010-c99.xsl
366 lines (350 loc) · 15.6 KB
/
SISO-REF-010-c99.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<?xml version="1.0"?>
<!--
"Reprinted with permission from SISO Inc."
@file SISO-REF-010-cpp.xsl
Transform EBV-MR XML data file into C++ Header (.h) file
v2.1 09 Oct 2018
updated by Kevin Walther
-->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:siso="http://www.sisostds.org/schemas/SISO-REF-010/2.4"
xmlns:func="http://www.sisostds.org/functions"
version="2.0">
<xsl:output method="text" encoding="utf-8" media-type="text/plain"/>
<xsl:template match="siso:ebv">
<xsl:text>/**
</xsl:text>
<xsl:text> * @file: SisoEnums.h
</xsl:text>
<xsl:text> * @brief: </xsl:text><xsl:value-of select="@description"/><xsl:text>
</xsl:text>
<xsl:text> * @version: </xsl:text><xsl:value-of select="@title"/><xsl:text> - </xsl:text><xsl:value-of select="@release"/><xsl:text>
</xsl:text>
<xsl:text> * @date: </xsl:text><xsl:value-of select="@date"/><xsl:text>
</xsl:text>
<xsl:text> * @author: <kevin.walther@nrl.navy.mil>
</xsl:text>
<xsl:text> */
</xsl:text>
<xsl:text>
</xsl:text>
<xsl:text>#ifndef SISOENUMS_H
</xsl:text>
<xsl:text>#define SISOENUMS_H
</xsl:text>
<xsl:text>
</xsl:text>
<xsl:text>/** Define a top-level SISO namespace. */
</xsl:text>
<xsl:text>namespace SISO {
</xsl:text>
<xsl:text>
</xsl:text>
<xsl:apply-templates select="siso:enum|siso:cet"/>
<xsl:text>
</xsl:text>
<xsl:text>} /** End SISO namespace */
</xsl:text>
<xsl:text>
</xsl:text>
<xsl:text>#endif /* SISOENUMS_H */
</xsl:text>
</xsl:template>
<!-- Define a function to capitalize and remove special characters from a string. -->
<xsl:function name="func:captializeString">
<xsl:param name="unformattedString"/>
<!-- Define a variable to store the capitalized name with all special characters removed, except apostrophes. -->
<xsl:variable name="formattedString1" select="translate($unformattedString, ' !"#$%&()*+,-./:;<=>?@[\]^`abcdefghijklmnopqrstuvwxyz{|}~’–',
'___________________________ABCDEFGHIJKLMNOPQRSTUVWXYZ______')"/>
<!-- Remove apostrophes. -->
<xsl:variable name="formattedString2" select='translate($formattedString1, "'", "")'/>
<!-- Prepend an underscore if the name begins with a numeric character. -->
<xsl:value-of>
<xsl:choose>
<xsl:when test="contains('0123456789', substring($formattedString2,1,1))">
<xsl:value-of select="concat('_', $formattedString2)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$formattedString2"/>
</xsl:otherwise>
</xsl:choose>
</xsl:value-of>
</xsl:function>
<!-- Define a function to print the list of EntityType values in an enum definition. -->
<xsl:function name="func:listEntityTypeEnums">
<xsl:param name="enumName"/>
<xsl:param name="textDescription"/>
<xsl:param name="namespacedEnumName"/>
<xsl:param name="kind"/>
<xsl:param name="domain"/>
<xsl:param name="country"/>
<xsl:param name="category"/>
<xsl:param name="subcategory"/>
<xsl:param name="specific"/>
<xsl:param name="extra"/>
<!-- Print a comments listing the description and full namespace for the enumeration. -->
<xsl:text> /** @brief: </xsl:text>
<xsl:value-of select="$textDescription"/>
<xsl:text> */
</xsl:text>
<xsl:text> /** @namespace: </xsl:text>
<xsl:value-of select="concat($namespacedEnumName, '::', $enumName)"/>
<xsl:text>_E */
</xsl:text>
<xsl:text> enum </xsl:text>
<xsl:value-of select="$enumName"/>
<!-- Append an "_E" after the enumeration name. -->
<xsl:text>_E {
</xsl:text>
<xsl:text> KIND = </xsl:text>
<xsl:value-of select="$kind"/>
<xsl:text>,
 DOMAIN = </xsl:text>
<xsl:value-of select="$domain"/>
<xsl:text>,
 COUNTRY = </xsl:text>
<xsl:value-of select="$country"/>
<xsl:text>,
 CATEGORY = </xsl:text>
<xsl:value-of select="$category"/>
<xsl:text>,
 SUBCATEGORY = </xsl:text>
<xsl:value-of select="$subcategory"/>
<xsl:text>,
 SPECIFIC = </xsl:text>
<xsl:value-of select="$specific"/>
<xsl:text>,
 EXTRA = </xsl:text>
<xsl:value-of select="$extra"/>
<xsl:text>
 };
</xsl:text>
</xsl:function>
<!--
Define a template to match each Complex Entity Type (CET) element in the SISO-REF-010 XML file.
-->
<xsl:template match="siso:cet">
<xsl:text>namespace </xsl:text>
<xsl:value-of select="func:captializeString(@name)"/>
<xsl:text> {
</xsl:text>
<xsl:apply-templates select="siso:entity">
<xsl:with-param name="namespaceString"
select="concat('SISO::', func:captializeString(@name))" tunnel="yes"/>
</xsl:apply-templates>
<xsl:text>}
</xsl:text>
</xsl:template>
<!--
Define a template to match each 'entity' (or Kind, Domain, Country) combination in the XML file.
-->
<xsl:template match="siso:entity">
<xsl:param name="namespaceString" tunnel="yes"/>
<xsl:variable name="kindDomainCountryVal" select="concat('_', @kind, '_', @domain, '_', @country)"/>
<xsl:text> namespace </xsl:text>
<xsl:value-of select="$kindDomainCountryVal"/>
<xsl:text> {
</xsl:text>
<xsl:apply-templates select="siso:category">
<xsl:with-param name="namespaceString"
select="concat($namespaceString, '::', $kindDomainCountryVal)" tunnel="yes"/>
<xsl:with-param name="kindNum" select="@kind" tunnel="yes"/>
<xsl:with-param name="domainNum" select="@domain" tunnel="yes"/>
<xsl:with-param name="countryNum" select="@country" tunnel="yes"/>
</xsl:apply-templates>
<xsl:text> }
</xsl:text>
</xsl:template>
<!--
Define a template to match each 'category' in the XML file.
-->
<xsl:template match="siso:category">
<xsl:param name="namespaceString" tunnel="yes"/>
<xsl:param name="kindNum" tunnel="yes"/>
<xsl:param name="domainNum" tunnel="yes"/>
<xsl:param name="countryNum" tunnel="yes"/>
<xsl:variable name="curCategoryName" select="func:captializeString(@description)"/>
<!-- Choose to apply-templates for EntityTypes, otherwise print enums. -->
<xsl:choose>
<!-- Just print the enumerations in AGGREGATE_STATE_AGGREGATE_TYPES case. -->
<xsl:when test="$namespaceString = 'SISO::AGGREGATE_STATE_AGGREGATE_TYPES::1_1_225'">
<xsl:value-of select="func:listEntityTypeEnums($curCategoryName, @description,
concat($namespaceString, '::', $curCategoryName),
$kindNum, $domainNum, $countryNum, @value, 0, 0, 0)"/>
</xsl:when>
<!-- Check for useless enums, such as "deprecated". -->
<xsl:when test="$curCategoryName = '_DEPRECATED_'">
<!-- DO NOTHING -->
</xsl:when>
<xsl:otherwise>
<!-- Apply templates again for EntityTypes, to get subcategories. -->
<xsl:text> namespace </xsl:text>
<xsl:value-of select="$curCategoryName"/>
<xsl:text> {
</xsl:text>
<xsl:apply-templates select="siso:subcategory">
<xsl:with-param name="namespaceString"
select="concat($namespaceString, '::', $curCategoryName)" tunnel="yes"/>
<xsl:with-param name="kindNum" select="$kindNum" tunnel="yes"/>
<xsl:with-param name="domainNum" select="$domainNum" tunnel="yes"/>
<xsl:with-param name="countryNum" select="$countryNum" tunnel="yes"/>
<xsl:with-param name="categoryNum" select="@value" tunnel="yes"/>
</xsl:apply-templates>
<xsl:text> }
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
Define a template to match each 'subcategory' in the XML file.
-->
<xsl:template match="siso:subcategory">
<xsl:param name="namespaceString" tunnel="yes"/>
<xsl:param name="kindNum" tunnel="yes"/>
<xsl:param name="domainNum" tunnel="yes"/>
<xsl:param name="countryNum" tunnel="yes"/>
<xsl:param name="categoryNum" tunnel="yes"/>
<!-- Get the subcategory name. -->
<xsl:variable name="curSubcategoryName" select="func:captializeString(@description)"/>
<xsl:choose>
<!-- Check for useless enums, such as "deprecated". -->
<xsl:when test="$curSubcategoryName = '_DEPRECATED_'">
<!-- DO NOTHING -->
</xsl:when>
<xsl:otherwise>
<!-- Get the fully-namespaced subcategory name. -->
<xsl:variable name="namespacedSubcategoryName"
select="concat($namespaceString, '::', $curSubcategoryName)"/>
<xsl:text> namespace </xsl:text>
<xsl:value-of select="$curSubcategoryName"/>
<!-- Check for repeated subcategories in same namespace. -->
<xsl:if test="(($curSubcategoryName = 'LINDAU_CLASS__TYPE_320_') and (@value = '2'))">
<xsl:text>_</xsl:text>
</xsl:if>
<xsl:text> {
</xsl:text>
<!-- Print the EntityType enums for this subcategory. -->
<xsl:value-of select="func:listEntityTypeEnums($curSubcategoryName, @description,
$namespacedSubcategoryName, $kindNum, $domainNum, $countryNum, $categoryNum, @value, 0, 0)"/>
<xsl:apply-templates select="siso:specific">
<xsl:with-param name="namespaceString" select="$namespacedSubcategoryName" tunnel="yes"/>
<xsl:with-param name="kindNum" select="$kindNum" tunnel="yes"/>
<xsl:with-param name="domainNum" select="$domainNum" tunnel="yes"/>
<xsl:with-param name="countryNum" select="$countryNum" tunnel="yes"/>
<xsl:with-param name="categoryNum" select="$categoryNum" tunnel="yes"/>
<xsl:with-param name="subcategoryNum" select="@value" tunnel="yes"/>
</xsl:apply-templates>
<xsl:text> }
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
Define a template to match each 'specific' in the XML file.
-->
<xsl:template match="siso:specific">
<xsl:param name="namespaceString" tunnel="yes"/>
<xsl:param name="kindNum" tunnel="yes"/>
<xsl:param name="domainNum" tunnel="yes"/>
<xsl:param name="countryNum" tunnel="yes"/>
<xsl:param name="categoryNum" tunnel="yes"/>
<xsl:param name="subcategoryNum" tunnel="yes"/>
<!-- Get the specific name. -->
<xsl:variable name="curSpecificName" select="func:captializeString(@description)"/>
<xsl:choose>
<!-- Check for useless enums, such as "deprecated". -->
<xsl:when test="$curSpecificName = '_DEPRECATED_'">
<!-- DO NOTHING -->
</xsl:when>
<xsl:otherwise>
<!-- Get the fully-namespaced specific name. -->
<xsl:variable name="namespacedSpecificName"
select="concat($namespaceString, '::', $curSpecificName)"/>
<xsl:text> namespace </xsl:text>
<xsl:value-of select="$curSpecificName"/>
<!-- Check for repeated subcategories in same namespace. -->
<xsl:if test="(($curSpecificName = 'M830A1_HEAT_MP_T') and (@value = '11'))">
<xsl:text>_</xsl:text>
</xsl:if>
<xsl:text> {
</xsl:text>
<!-- Print the EntityType enums for this specific. -->
<xsl:value-of select="func:listEntityTypeEnums($curSpecificName, @description,
$namespacedSpecificName, $kindNum, $domainNum, $countryNum, $categoryNum, $subcategoryNum, @value, 0)"/>
<xsl:apply-templates select="siso:extra">
<xsl:with-param name="namespaceString" select="$namespacedSpecificName" tunnel="yes"/>
<xsl:with-param name="kindNum" select="$kindNum" tunnel="yes"/>
<xsl:with-param name="domainNum" select="$domainNum" tunnel="yes"/>
<xsl:with-param name="countryNum" select="$countryNum" tunnel="yes"/>
<xsl:with-param name="categoryNum" select="$categoryNum" tunnel="yes"/>
<xsl:with-param name="subcategoryNum" select="$subcategoryNum" tunnel="yes"/>
<xsl:with-param name="specificNum" select="@value" tunnel="yes"/>
</xsl:apply-templates>
<xsl:text> }
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
Define a template to match each 'extra' in the XML file.
-->
<xsl:template match="siso:extra">
<xsl:param name="namespaceString" tunnel="yes"/>
<xsl:param name="kindNum" tunnel="yes"/>
<xsl:param name="domainNum" tunnel="yes"/>
<xsl:param name="countryNum" tunnel="yes"/>
<xsl:param name="categoryNum" tunnel="yes"/>
<xsl:param name="subcategoryNum" tunnel="yes"/>
<xsl:param name="specificNum" tunnel="yes"/>
<!-- Get the extra name. -->
<xsl:variable name="curExtraName" select="func:captializeString(@description)"/>
<xsl:choose>
<!-- Check for useless enums, such as "deprecated". -->
<xsl:when test="($curExtraName = '_DEPRECATED_') or ($curExtraName = 'AGM_114K_SAL')">
<!-- DO NOTHING -->
</xsl:when>
<xsl:otherwise>
<!-- Get the fully-namespaced specific name. -->
<xsl:variable name="namespacedExtraName"
select="concat($namespaceString, '::', $curExtraName)"/>
<xsl:text> namespace </xsl:text>
<xsl:value-of select="$curExtraName"/>
<!-- Check for repeated subcategories in same namespace. -->
<!-- <xsl:if test="(($curSpecificName = 'M830A1_HEAT_MP_T') and (@value = '11'))">
<xsl:text>_</xsl:text>
</xsl:if> -->
<xsl:text> {
</xsl:text>
<!-- Print the EntityType enums for this extra type. -->
<xsl:value-of select="func:listEntityTypeEnums($curExtraName, @description, $namespacedExtraName,
$kindNum, $domainNum, $countryNum, $categoryNum, $subcategoryNum, $specificNum, @value)"/>
<xsl:text> }
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
Define a template to match each enum element in the XML file.
-->
<xsl:template match="siso:enum">
<xsl:variable name="formattedEnumName" select="func:captializeString(@name)"/>
<!-- Check if this enum has duplicate enumrow names, and should be skipped. -->
<xsl:choose>
<xsl:when test="($formattedEnumName = ('LIFE_FORMS_SUBCATEGORY_U_S__WEAPONS', 'MUNITION_DESCRIPTOR_FUSE',
'VARIABLE_RECORD_TYPES', 'CAPABILITY_REPORT', 'REPAIR_COMPLETE_REPAIR', 'TRANSFER_CONTROL_TRANSFER_TYPE'))">
<!-- SKIP THIS ENUMERATION -->
</xsl:when>
<xsl:otherwise>
<xsl:text>/**
</xsl:text>
<xsl:text> * @brief: </xsl:text><xsl:value-of select="@name"/><xsl:text>
</xsl:text>
<xsl:text> * @namespace: SISO::</xsl:text><xsl:value-of select="func:captializeString(@name)"/><xsl:text>::</xsl:text>
<xsl:value-of select="func:captializeString(@name)"/><xsl:text>_E {
</xsl:text>
<xsl:text> */
</xsl:text>
<xsl:text>namespace </xsl:text><xsl:value-of select="func:captializeString(@name)"/><xsl:text> {
</xsl:text>
<xsl:text> enum </xsl:text><xsl:value-of select="func:captializeString(@name)"/><xsl:text>_E {
</xsl:text>
<xsl:apply-templates select="siso:enumrow"/>
<xsl:text> };
</xsl:text>
<xsl:text>}
</xsl:text>
<xsl:text>
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
Define a template to match each enum/enumrow element in the XML file.
-->
<xsl:template match="siso:enumrow">
<xsl:text> </xsl:text>
<!-- Define the variable based on the value of "description". -->
<xsl:variable name="enumRowName">
<xsl:choose>
<!-- Make sure description is not an empty string. -->
<xsl:when test="(@description = '') or (@description = ' ')">
<xsl:value-of select="./siso:meta/@value"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@description"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Test for any enumerations we want to skip (b/c they are used more than once). -->
<xsl:choose>
<xsl:when test="((func:captializeString($enumRowName)) = ('RESERVED', 'NOT_USED', '_1L13_3__55G6_',
'AN_APN_215', 'IRL144M', 'SNOOP_PING', 'P_18', 'TYPE_208', 'TYPE_753', 'INSTRUMENTATION',
'ABBREVIATED_COMMAND_AND_CONTROL', '_UNAVAILABLE_FOR_USE_'))">
<!-- DO NOTHING -->
</xsl:when>
<xsl:otherwise>
<!-- Print the current enumrow info. -->
<xsl:value-of select="func:captializeString($enumRowName)"/>
<xsl:text> = </xsl:text>
<xsl:value-of select="@value"/>
<xsl:if test="position()!=last()">
<xsl:text>,</xsl:text>
</xsl:if>
<xsl:text>
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Define a default template to match any text -->
<xsl:template match="text()"/>
</xsl:stylesheet>