VirtualBox

source: vbox/trunk/src/VBox/Main/xml/SchemaDefs.xsl@ 33146

Last change on this file since 33146 was 29385, checked in by vboxsync, 14 years ago

Main: cleaned up some pedantic warnings.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.1 KB
Line 
1<?xml version="1.0"?>
2
3<!--
4 * A template to generate a header that will contain some important constraints
5 * extracted from the VirtualBox XML Schema (VirtualBox-settings-*.xsd).
6 * The output file name must be SchemaDefs.h.
7 *
8 * This template depends on XML Schema structure (type names and constraints)
9 * and should be reviewed on every Schema change.
10
11 Copyright (C) 2006-2008 Oracle Corporation
12
13 This file is part of VirtualBox Open Source Edition (OSE), as
14 available from http://www.virtualbox.org. This file is free software;
15 you can redistribute it and/or modify it under the terms of the GNU
16 General Public License (GPL) as published by the Free Software
17 Foundation, in version 2 as it comes in the "COPYING" file of the
18 VirtualBox OSE distribution. VirtualBox OSE is distributed in the
19 hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20-->
21
22<xsl:stylesheet version="1.0"
23 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
24 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
25>
26<xsl:output method="text"/>
27
28<xsl:strip-space elements="*"/>
29
30<xsl:param name="mode" expr=''/>
31
32<!--
33// helpers
34////////////////////////////////////////////////////////////////////////////////
35-->
36
37<!--
38 * Extract the specified value and assign it to an enum member with the given
39 * name
40-->
41<xsl:template name="defineEnumMember">
42 <xsl:param name="member"/>
43 <xsl:param name="select"/>
44 <xsl:if test="$select">
45 <xsl:value-of select="concat($member, ' = ', $select, ',&#x0A;')"/>
46 </xsl:if>
47</xsl:template>
48
49<!--
50// templates
51////////////////////////////////////////////////////////////////////////////////
52-->
53
54<!--
55 * shut down all implicit templates
56-->
57<xsl:template match="*"/>
58<xsl:template match="*" mode="declare"/>
59<xsl:template match="*" mode="declare.enum"/>
60<xsl:template match="*" mode="define"/>
61
62<xsl:template match="/">
63 <xsl:choose>
64 <xsl:when test="$mode='declare'">
65 <xsl:apply-templates select="/" mode="declare"/>
66 </xsl:when>
67 <xsl:when test="$mode='define'">
68 <xsl:apply-templates select="/" mode="define"/>
69 </xsl:when>
70 <xsl:otherwise>
71 <xsl:message terminate="yes">
72Value '<xsl:value-of select="$mode"/>' of parameter 'mode' is invalid!
73 </xsl:message>
74 </xsl:otherwise>
75 </xsl:choose>
76</xsl:template>
77
78<!--
79 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
80 * declare mode (C++ header file)
81 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
82-->
83
84<xsl:template match="/" mode="declare">
85<xsl:text>
86/*
87 * DO NOT EDIT.
88 *
89 * This header is automatically generated from the VirtualBox XML Settings
90 * Schema and contains selected schema constraints declared in C++.
91 */
92
93#ifndef ____H_SCHEMADEFS
94#define ____H_SCHEMADEFS
95
96namespace SchemaDefs
97{
98 enum
99 {
100</xsl:text>
101
102 <xsl:apply-templates select="xsd:schema" mode="declare.enum"/>
103
104<xsl:text> DummyTerminator
105 };
106</xsl:text>
107
108<xsl:apply-templates select="xsd:schema" mode="declare"/>
109
110<xsl:text>}
111
112#endif // !____H_SCHEMADEFS
113</xsl:text>
114</xsl:template>
115
116<!--
117 * enumeration values
118-->
119<xsl:template match="xsd:schema" mode="declare.enum">
120
121 <!-- process include statements -->
122 <xsl:for-each select="xsd:include">
123 <!-- skip VirtualBox-settings-root.xsd inclusion as it is computed at runtime -->
124 <xsl:if test="not(@schemaLocation='VirtualBox-settings-root.xsd')">
125 <xsl:apply-templates select="document(@schemaLocation)/xsd:schema" mode="declare.enum"/>
126 </xsl:if>
127 </xsl:for-each>
128
129 <xsl:call-template name="defineEnumMember">
130 <xsl:with-param name="member" select="' MinGuestRAM'"/>
131 <xsl:with-param name="select" select="
132 xsd:complexType[@name='TMemory']/xsd:attribute[@name='RAMSize']//xsd:minInclusive/@value
133 "/>
134 </xsl:call-template>
135 <xsl:call-template name="defineEnumMember">
136 <xsl:with-param name="member" select="' MaxGuestRAM'"/>
137 <xsl:with-param name="select" select="
138 xsd:complexType[@name='TMemory']/xsd:attribute[@name='RAMSize']//xsd:maxInclusive/@value
139 "/>
140 </xsl:call-template>
141
142 <xsl:call-template name="defineEnumMember">
143 <xsl:with-param name="member" select="' MinGuestVRAM'"/>
144 <xsl:with-param name="select" select="
145 xsd:complexType[@name='TDisplay']/xsd:attribute[@name='VRAMSize']//xsd:minInclusive/@value
146 "/>
147 </xsl:call-template>
148 <xsl:call-template name="defineEnumMember">
149 <xsl:with-param name="member" select="' MaxGuestVRAM'"/>
150 <xsl:with-param name="select" select="
151 xsd:complexType[@name='TDisplay']/xsd:attribute[@name='VRAMSize']//xsd:maxInclusive/@value
152 "/>
153 </xsl:call-template>
154
155 <xsl:call-template name="defineEnumMember">
156 <xsl:with-param name="member" select="' MinCPUCount'"/>
157 <xsl:with-param name="select" select="
158 xsd:simpleType[@name='TCPUCount']//xsd:minInclusive/@value
159 "/>
160 </xsl:call-template>
161 <xsl:call-template name="defineEnumMember">
162 <xsl:with-param name="member" select="' MaxCPUCount'"/>
163 <xsl:with-param name="select" select="
164 xsd:simpleType[@name='TCPUCount']//xsd:maxInclusive/@value
165 "/>
166 </xsl:call-template>
167
168 <xsl:call-template name="defineEnumMember">
169 <xsl:with-param name="member" select="' MaxGuestMonitors'"/>
170 <xsl:with-param name="select" select="
171 xsd:complexType[@name='TDisplay']/xsd:attribute[@name='monitorCount']//xsd:maxInclusive/@value
172 "/>
173 </xsl:call-template>
174 <xsl:call-template name="defineEnumMember">
175 <xsl:with-param name="member" select="' NetworkAdapterCount'"/>
176 <xsl:with-param name="select" select="
177 xsd:complexType[@name='TNetworkAdapter']/xsd:attribute[@name='slot']//xsd:maxExclusive/@value
178 "/>
179 </xsl:call-template>
180
181 <xsl:call-template name="defineEnumMember">
182 <xsl:with-param name="member" select="' SerialPortCount'"/>
183 <xsl:with-param name="select" select="
184 xsd:complexType[@name='TUARTPort']/xsd:attribute[@name='slot']//xsd:maxExclusive/@value
185 "/>
186 </xsl:call-template>
187
188 <xsl:call-template name="defineEnumMember">
189 <xsl:with-param name="member" select="' ParallelPortCount'"/>
190 <xsl:with-param name="select" select="
191 xsd:complexType[@name='TLPTPort']/xsd:attribute[@name='slot']//xsd:maxExclusive/@value
192 "/>
193 </xsl:call-template>
194
195 <xsl:call-template name="defineEnumMember">
196 <xsl:with-param name="member" select="' MaxBootPosition'"/>
197 <xsl:with-param name="select" select="
198 xsd:complexType[@name='TBoot']//xsd:element[@name='Order']//xsd:attribute[@name='position']//xsd:maxInclusive/@value
199 "/>
200 </xsl:call-template>
201
202</xsl:template>
203
204<!--
205 * aliases (defines) for individual OSTypeIds array elements
206-->
207<xsl:template match="xsd:schema" mode="declare">
208
209 <xsl:text>&#x0A; extern const char *OSTypeIds[];&#x0A;</xsl:text>
210
211 <xsl:text>&#x0A; enum { OSTypeId_COUNT = </xsl:text>
212 <xsl:value-of select="count (
213 xsd:simpleType[@name='TGuestOSType']/xsd:restriction[@base='xsd:string']/xsd:enumeration |
214 document(xsd:include[not(@schemaLocation='VirtualBox-settings-root.xsd')]/@schemaLocation)/xsd:schema/xsd:simpleType[@name='TGuestOSType']/xsd:restriction[@base='xsd:string']/xsd:enumeration
215 )"/>
216 <xsl:text> };&#x0A;&#x0A;</xsl:text>
217
218 <xsl:for-each select="
219 xsd:simpleType[@name='TGuestOSType']/xsd:restriction[@base='xsd:string']/xsd:enumeration |
220 document(xsd:include[not(@schemaLocation='VirtualBox-settings-root.xsd')]/@schemaLocation)/xsd:schema/xsd:simpleType[@name='TGuestOSType']/xsd:restriction[@base='xsd:string']/xsd:enumeration
221 ">
222 <xsl:text> #define SchemaDefs_OSTypeId_</xsl:text>
223 <xsl:value-of select="@value"/>
224 <xsl:text> SchemaDefs::OSTypeIds [</xsl:text>
225 <xsl:value-of select="position()-1"/>
226 <xsl:text>]&#x0A;</xsl:text>
227 </xsl:for-each>
228
229</xsl:template>
230
231<!--
232 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
233 * define mode (C++ source file)
234 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
235-->
236
237<xsl:template match="/" mode="define">
238<xsl:text>
239/*
240 * DO NOT EDIT.
241 *
242 * This source is automatically generated from the VirtualBox XML Settings
243 * Schema and contains selected schema constraints defined in C++.
244 */
245
246#include "SchemaDefs.h"
247
248namespace SchemaDefs
249{
250</xsl:text>
251
252<xsl:apply-templates select="xsd:schema" mode="define"/>
253
254<xsl:text>}
255</xsl:text>
256</xsl:template>
257
258<!--
259 * array of OSTypeIds
260-->
261<xsl:template match="xsd:schema" mode="define">
262 <xsl:text> const char *OSTypeIds[] =
263 {
264</xsl:text>
265 <xsl:for-each select="
266 xsd:simpleType[@name='TGuestOSType']/xsd:restriction[@base='xsd:string']/xsd:enumeration |
267 document(xsd:include[not(@schemaLocation='VirtualBox-settings-root.xsd')]/@schemaLocation)/xsd:schema/xsd:simpleType[@name='TGuestOSType']/xsd:restriction[@base='xsd:string']/xsd:enumeration
268 ">
269 <xsl:text> "</xsl:text>
270 <xsl:value-of select="@value"/>
271 <xsl:text>",
272</xsl:text>
273 </xsl:for-each>
274 <xsl:text> };
275</xsl:text>
276</xsl:template>
277
278<!--
279 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
280 * END
281 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
282-->
283
284</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette