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

<!-- this class contains the templates for generating C++ source code for a given framing model -->

<xsl:import href="utils.xsl"/>
<xsl:output method="text" indent="yes" name="textFormat"/> 

<xsl:template match="/"> 
    <xsl:apply-templates mode="generate-multi" select="frames"/>
    <xsl:apply-templates mode="method-list-header" select="frames"/>
    <xsl:apply-templates mode="method-list-source" select="frames"/>
    <xsl:apply-templates mode="method-interface" select="frames"/>
</xsl:template>

<!-- processes all frames outputting the classes in a single stream -->
<xsl:template match="frames" mode="generate-single"> 
    <xsl:result-document href="amqp_methods.h" format="textFormat">
#include "qpid/framing/amqp_framing.h"
        <xsl:for-each select="frame">      
           <xsl:call-template name="generate-class">
                <xsl:with-param name="f" select="."/>
            </xsl:call-template>
        </xsl:for-each>      
    </xsl:result-document>
</xsl:template>

<!-- generates seperate file for each class/frame -->
<xsl:template match="frame" mode="generate-multi"> 
    <xsl:variable name="uri" select="concat(@name, '.h')"/> 
    <xsl:result-document href="{$uri}" format="textFormat"> 
#include "qpid/framing/amqp_types.h"
#include "AMQP_ServerOperations.h"
#include "qpid/framing/AMQMethodBody.h"
#include "qpid/framing/Buffer.h"
#include "qpid/framing/FieldTable.h"

#ifndef _<xsl:value-of select="@name"/>_
#define _<xsl:value-of select="@name"/>_

namespace qpid {
namespace framing {

    <xsl:call-template name="generate-class">
        <xsl:with-param name="f" select="."/>
    </xsl:call-template>
}
}

#endif

</xsl:result-document> 
</xsl:template> 


<!-- main class generation template -->
<xsl:template name="generate-class"> 
    <xsl:param name="f"/>
/**
 * This class is autogenerated, do not modify. [From <xsl:value-of select="$f/parent::frames/@protocol"/>]
 */
class <xsl:value-of select="$f/@name"/> : virtual public AMQMethodBody
{ 
    <xsl:for-each select="$f/field"> 
        <xsl:value-of select="@cpp-type"/>
        <xsl:text> </xsl:text>
        <xsl:value-of select="@name"/>;    
    </xsl:for-each> 

public:
    typedef boost::shared_ptr&lt;<xsl:value-of select="$f/@name"/>&gt; shared_ptr;   

    virtual ~<xsl:value-of select="$f/@name"/>() {}

    <xsl:for-each select="$f/field"> 
        inline <xsl:value-of select="concat(@cpp-arg-type, ' get', amqp:upper-first(@name), '() { return ', @name)"/>; }    
    </xsl:for-each> 
 

    inline void print(std::ostream&amp; out) const{
	out &lt;&lt; "<xsl:value-of select="$f/@declaration_name"/>"
        <xsl:for-each select="$f/field"> 
	    <xsl:text> &lt;&lt; ", </xsl:text>
            <xsl:value-of select="@name"/>="&lt;&lt;
            <xsl:value-of select="@name"/>    
        </xsl:for-each> 
        ;
    }

    inline u_int16_t amqpClassId() const {
        return <xsl:value-of select="$f/@class-id"/>;
    }
   
    inline u_int16_t amqpMethodId() const {
        return <xsl:value-of select="$f/@method-id"/>;
    }

    inline u_int32_t bodySize() const {
        <xsl:choose> 
        <xsl:when test="$f/field">
        return
        <xsl:for-each select="$f/field">
            <xsl:if test="position() != 1">+
            </xsl:if>
            <xsl:value-of select="amqp:field-length(.)"/>
        </xsl:for-each>		 
        ;
        </xsl:when>
        <xsl:otherwise>return 0;</xsl:otherwise>
        </xsl:choose> 
    }

    <xsl:if test="@server='true'">
    inline void invoke(AMQP_ServerOperations&amp; target, u_int16_t channel) {
	<xsl:if test="field">
            <xsl:value-of select="concat('target.get', amqp:upper-first(parent::class/@name), 'Handler()->', @invocation_name, '(channel, ')"/>
            <xsl:value-of select="$f/field/@name" separator=", "/>);
	</xsl:if>
	<xsl:if test="not(field)">
            <xsl:value-of select="concat('target.get', amqp:upper-first(parent::class/@name), 'Handler()->', @invocation_name, '(channel)')"/>;
	</xsl:if>
    }
    </xsl:if>

    inline void encodeContent(Buffer&amp; <xsl:if test="$f/field">buffer</xsl:if>) const
    {
        <xsl:if test="$f/field[@type='bit']">        
	    u_int8_t flags = 0;
            <xsl:for-each select="$f/field[@type='bit']">
                <xsl:value-of select="concat('flags |= ', @name,' &lt;&lt; (', @boolean-index, ' - 1)')"/>; 
            </xsl:for-each>
        </xsl:if>
        <xsl:for-each select="$f/field">
            <xsl:if test="@type != 'bit'">
                <xsl:value-of select="amqp:encoder(.)"/>;
            </xsl:if>
            <xsl:if test="@type = 'bit' and @boolean-index = 1">
                <xsl:text>buffer.putOctet(flags)</xsl:text>;
            </xsl:if>
        </xsl:for-each>		 
    }

    inline void decodeContent(Buffer&amp; <xsl:if test="$f/field">buffer</xsl:if>)
    {
        <xsl:for-each select="$f/field">
            <xsl:choose>
		<xsl:when test="@type = 'bit' and @boolean-index = 1">
		    <xsl:text>u_int8_t flags = buffer.getOctet()</xsl:text>;
		    <xsl:value-of select="amqp:decoder(.)"/>;
		</xsl:when>
		<xsl:otherwise>
		    <xsl:value-of select="amqp:decoder(.)"/>;
		</xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>		 
    }

    <xsl:if test="$f/field">        
    <!-- only generate overloaded constructor if there are fields in this method -->
    inline <xsl:value-of select="$f/@name"/>(<xsl:value-of select="$f/field/concat(@cpp-arg-type, ' _', @name)" separator=", "/>) : <xsl:value-of select="$f/field/concat(@name, '(_', @name, ')')" separator=", "/>
    {
    }
    </xsl:if>

    inline <xsl:value-of select="$f/@name"/>()
    {
    }
};

</xsl:template> 

<xsl:template match="frames" mode="method-list-header">	
<xsl:result-document href="amqp_methods.h" format="textFormat">
/**
 * This file is autogenerated, do not modify.
 */

#ifndef AMQ_METHODS_H
#define AMQ_METHODS_H

        <xsl:for-each select="class/frame">
#include "<xsl:value-of select="@name"/>.h"
        </xsl:for-each>

namespace qpid {
namespace framing {

        <xsl:for-each select="class/frame">
const <xsl:value-of select="concat(@name, ' ', @declaration_name)"/>;
        </xsl:for-each>

AMQMethodBody* createAMQMethodBody(u_int16_t classId, u_int16_t methodId);

}
}

#endif
</xsl:result-document>
</xsl:template> 

<xsl:template match="frames" mode="method-list-source">	
    <xsl:result-document href="amqp_methods.cpp" format="textFormat">
#include "amqp_methods.h"
#include "qpid/QpidError.h"

namespace qpid {
namespace framing {
/**
 * This method is autogenerated, do not modify.
 */
AMQMethodBody* createAMQMethodBody(u_int16_t classId, u_int16_t methodId){
    switch(classId * 1000 + methodId)
    {
        <xsl:for-each select="class/frame">
            <xsl:text>case </xsl:text>
            <xsl:value-of select="@class-id"/>         
	    <xsl:text> * 1000 + </xsl:text> 
            <xsl:value-of select="@method-id"/>         
	    <xsl:text>: return new </xsl:text> 
            <xsl:value-of select="@name"/>();         
        </xsl:for-each>
    }
    THROW_QPID_ERROR(FRAMING_ERROR, "Unknown method");	
}

}
}
</xsl:result-document>
</xsl:template> 

<xsl:template match="frames" mode="generate-interface">	
    <xsl:result-document href="AMQPServer.h" format="textFormat">
#include "qpid/framing/amqp_types.h"
#include "qpid/framing/FieldTable.h"

#ifndef _AMQPServer_
#define _AMQPServer_

namespace qpid {
namespace framing {

class AMQPServer
{
    public:

    <xsl:for-each select="class">
    class <xsl:value-of select="concat(amqp:upper-first(@name), 'Handler')"/>{
        public:
        <xsl:for-each select="frame[@server='true']">      
        <xsl:if test="field">
            virtual void <xsl:value-of select="@invocation_name"/>(u_int16_t channel, <xsl:value-of select="field/concat(@cpp-arg-type, ' ', @name)" separator=", "/>) = 0; 
        </xsl:if>
        <xsl:if test="not(field)">
            virtual void <xsl:value-of select="@invocation_name"/>(u_int16_t channel) = 0; 
        </xsl:if>
        </xsl:for-each>      
            virtual ~<xsl:value-of select="concat(amqp:upper-first(@name), 'Handler')"/>(){}
    };

    virtual <xsl:value-of select="concat(amqp:upper-first(@name), 'Handler* get', amqp:upper-first(@name), 'Handler')"/>() = 0;       
 
    </xsl:for-each>      
    virtual ~AMQPServer(){}
};

}
}

#endif
</xsl:result-document>

    <xsl:result-document href="AMQPClient.h" format="textFormat">
#include "qpid/framing/amqp_types.h"
#include "qpid/framing/FieldTable.h"

#ifndef _AMQPClient_
#define _AMQPClient_

namespace qpid {
namespace framing {

class AMQPClient
{
    public:

    <xsl:for-each select="class">
    class <xsl:value-of select="concat(amqp:upper-first(@name), 'Handler')"/>{
        public:
        <xsl:for-each select="frame[@client='true']">      
        <xsl:if test="field">
            virtual void <xsl:value-of select="@invocation_name"/>(u_int16_t channel, <xsl:value-of select="field/concat(@cpp-arg-type, ' ', @name)" separator=", "/>) = 0; 
        </xsl:if>
        <xsl:if test="not(field)">
            virtual void <xsl:value-of select="@invocation_name"/>(u_int16_t channel) = 0; 
        </xsl:if>
        </xsl:for-each>      
            virtual ~<xsl:value-of select="concat(amqp:upper-first(@name), 'Handler')"/>(){}
    };

    virtual <xsl:value-of select="concat(amqp:upper-first(@name), 'Handler* get', amqp:upper-first(@name), 'Handler')"/>() = 0;       
 
    </xsl:for-each>      

    virtual ~AMQPClient(){}
};

}
}

#endif
</xsl:result-document>

</xsl:template> 

</xsl:stylesheet>