summaryrefslogtreecommitdiff
path: root/cpp/etc/stylesheets/code_utils.xsl
blob: d2bbea2cdc8e37a725fb90f3dc8f6ab82958dcf8 (plain)
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
<?xml version='1.0'?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amqp="http://amqp.org">

  <!--
  ========================
  Function: amqp:copyright
  ========================
  Print out a standard Apache copyright notice and generated code warning.
  -->
  <xsl:function name="amqp:copyright">//
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
// 
//   http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.
//

 
//
//
// NOTE: This file is generated directly from the AMQP XML specification.
// === DO NOT EDIT ===
//
//&#xA;</xsl:function>

  <!--
  ==========================
  Function: amqp:upper-first
  ==========================
  Convert the first character of the parameter to upper-case
  -->
  <xsl:function name="amqp:upper-first">
    <xsl:param name="in"/>
    <xsl:value-of select="concat(upper-case(substring($in, 1, 1)), substring($in, 2))"/>
  </xsl:function>

  <!--
  ========================
  Function: amqp:cpp-name-1
  ========================
  Convert parameter "name" to a valid C++ identifier, finding spaces and '-'s
  in the parameter name and replacing them with '_' chars. Also check for C++
  reserved words and prefix them with '_'. No capitalization is performed.
  -->
  <xsl:function name="amqp:cpp-name-1">
    <xsl:param name="name"/>
    <xsl:choose>
      <!-- C++ reserved words. -->
      <xsl:when test="$name='delete'">delete_</xsl:when>
      <xsl:when test="$name='return'">return_</xsl:when>
      <!-- Change unsuitable C++ identifier characters. -->
      <xsl:otherwise><xsl:value-of select="translate($name, ' -', '__')"/></xsl:otherwise>
    </xsl:choose>
  </xsl:function>

  <!--
  =======================
  Function: amqp:cpp-name
  =======================
  Convert parameter "name" to a valid, camel cased C++ name. 
  -->
  <xsl:function name="amqp:cpp-name">
    <xsl:param name="name"/>
    <xsl:value-of select="amqp:cpp-name-1(amqp:camel-case($name))"/>
  </xsl:function>

  <!--
  =============================
  Function: amqp:cpp-class-name
  =============================
  Convert parameter "name" to a valid C++ identifier, finding spaces and '-'s
  in the parameter name and replacing them with '_' chars. Also check for C++
  reserved words and prefix them with '_'. First letter only is capitalized.
  -->
  <xsl:function name="amqp:cpp-class-name">
    <xsl:param name="name"/>
    <xsl:value-of select="amqp:upper-first(amqp:cpp-name($name))"/>
  </xsl:function>

  <!--
  =========================
  Function: amqp:camel-case
  =========================
  *** NOTE: Only works with *one* of either '-' or ' '. If a name contains 2 or
  *** more of these characters, then this will break.
  Convert parameter "name" to camel case, where words are separated by ' ' or '-'
  -->
  <xsl:function name="amqp:camel-case">
    <xsl:param name="name"/>
    <xsl:choose>
        <xsl:when test="contains($name, ' ')">
            <xsl:value-of select="concat(substring-before($name, ' '), amqp:upper-first(substring-after($name, ' ')))"/>
        </xsl:when>
        <xsl:when test="contains($name, '-')">
            <xsl:value-of select="concat(substring-before($name, '-'), amqp:upper-first(substring-after($name, '-')))"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$name"/>
        </xsl:otherwise>
    </xsl:choose>
  </xsl:function>

  <!--
  =========================
  Function: amqp:field-name
  =========================
  Get a valid field name, processing spaces and '-'s where appropriate
  -->
  <xsl:function name="amqp:field-name">
    <xsl:param name="name"/>
    <xsl:value-of select="amqp:upper-first(amqp:camel-case($name))"/>
  </xsl:function>

  <!--
  =======================
  Function: amqp:cpp-type
  =======================
  Map the set of simple AMQP types to C++ types. Also map the AMQP table
  domain to appropriate C++ class.
  -->
  <xsl:function name="amqp:cpp-type">
    <xsl:param name="type"/>
    <xsl:choose>
      <!-- Simple AMQP domain types -->
      <xsl:when test="$type='octet'">u_int8_t</xsl:when>
      <xsl:when test="$type='short'">u_int16_t</xsl:when>
      <xsl:when test="$type='shortstr'">string</xsl:when>
      <xsl:when test="$type='longstr'">string</xsl:when>
      <xsl:when test="$type='bit'">bool</xsl:when>
      <xsl:when test="$type='long'">u_int32_t</xsl:when>
      <xsl:when test="$type='longlong'">u_int64_t</xsl:when>
      <xsl:when test="$type='timestamp'">u_int64_t</xsl:when>
      <!-- AMQP structures -->
      <xsl:when test="$type='table'">FieldTable</xsl:when>
      <!-- Fallback: unknown type -->
      <xsl:otherwise>unknown_type /* WARNING: undefined type */</xsl:otherwise>
    </xsl:choose>
  </xsl:function>

  <!--
  ==========================
  Function: amqp:cpp-arg-ref
  ==========================
  Determines whether a C++ reference is required for an argument.
  -->
  <xsl:function name="amqp:cpp-arg-ref">
    <xsl:param name="type"/>
    <xsl:choose>
      <xsl:when test="$type='string'">&amp;</xsl:when>
      <xsl:when test="$type='FieldTable'">&amp;</xsl:when>
    </xsl:choose>
  </xsl:function>

  <!--
  =========================
  Function: amqp:cpp-lookup
  =========================
  Template and function for looking up the cpp type from the domain name.
  The template runs on a lookup table XML generated by the "domain_table"
  template in amqp_domaintypes.xsl.
  -->
  <xsl:template match="/" mode="cpp-lookup">
    <xsl:param name="domain-name"/>
    <xsl:for-each select="key('domain-lookup', $domain-name)">
      <xsl:value-of select="@cpp-type"/>
    </xsl:for-each>
  </xsl:template>

  <xsl:function name="amqp:cpp-lookup">
    <xsl:param name="domain-name"/>
    <xsl:param name="domain-cpp-table"/>
    <xsl:apply-templates mode="cpp-lookup" select="$domain-cpp-table">
      <xsl:with-param name="domain-name" select="$domain-name"/>
    </xsl:apply-templates>
  </xsl:function>

  <!--
  =========================
  Function: amqp:cpp-lookup
  =========================
  Template and function for processing the possibly multiple <doc> elements
  within a node.
  -->
  <xsl:template match="doc" mode="process-doc-elts">
    <xsl:for-each select=".">
      <xsl:choose>
        <xsl:when test=".[@type='grammar']"><xsl:value-of select="."/></xsl:when>
        <xsl:when test=".[@type='scenario']"><xsl:value-of select="concat('&#xA;Test Scenario: ', normalize-space(.))"/></xsl:when>
        <xsl:otherwise><xsl:value-of select="normalize-space(.)"/></xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
  </xsl:template>

  <xsl:function name="amqp:process-docs">
    <xsl:param name="doc-elts"/>
    <xsl:apply-templates mode="process-doc-elts" select="$doc-elts"/>
  </xsl:function>


</xsl:stylesheet>