diff options
author | Alan Conway <aconway@apache.org> | 2007-08-28 19:40:36 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2007-08-28 19:40:36 +0000 |
commit | 8799975f897abb7f71a5651f110ca657c5853b42 (patch) | |
tree | fb4a45b00e91c1fac69c28175521678f2e042dd2 /cpp | |
parent | 9e10f4ea3b2f8ab6650f635cada48e4735ca20d7 (diff) | |
download | qpid-python-8799975f897abb7f71a5651f110ca657c5853b42.tar.gz |
Generate constants and reply exceptions from spec constants.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@570540 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp')
-rwxr-xr-x | cpp/rubygen/amqpgen.rb | 10 | ||||
-rwxr-xr-x | cpp/rubygen/templates/Operations.rb | 3 | ||||
-rwxr-xr-x | cpp/rubygen/templates/constants.rb | 42 |
3 files changed, 50 insertions, 5 deletions
diff --git a/cpp/rubygen/amqpgen.rb b/cpp/rubygen/amqpgen.rb index 6707b0c5a0..f47b8e2f9f 100755 --- a/cpp/rubygen/amqpgen.rb +++ b/cpp/rubygen/amqpgen.rb @@ -15,6 +15,9 @@ class String # Convert to underbar_separated_form. def bars() tr('- .','_'); end + # Convert to ALL_UPPERCASE_FORM + def shout() bars.upcase!; end + # Convert to lowerCaseCapitalizedForm def lcaps() gsub( /\W(\w)/ ) { |m| $1.upcase } end @@ -104,6 +107,9 @@ class AmqpElement def to_s() "#<#{self.class}(#{name})>"; end def inspect() to_s; end + + # Text of doc child if there is one. + def doc() d=xml.elements["doc"]; d and d.text; end end AmqpResponse = AmqpElement @@ -135,7 +141,7 @@ end class AmqpConstant < AmqpElement def initialize(xml, parent) super; end - amqp_attr_reader :value, :datatype + amqp_attr_reader :value, :class end class AmqpResult < AmqpElement @@ -192,7 +198,7 @@ class AmqpRoot < AmqpElement end amqp_attr_reader :major, :minor - amqp_child_reader :class, :domain + amqp_child_reader :class, :domain, :constant def version() major + "-" + minor; end diff --git a/cpp/rubygen/templates/Operations.rb b/cpp/rubygen/templates/Operations.rb index fff4f796c3..1002bf07a4 100755 --- a/cpp/rubygen/templates/Operations.rb +++ b/cpp/rubygen/templates/Operations.rb @@ -78,9 +78,6 @@ class #{@classname} { virtual ProtocolVersion getVersion() const = 0; - // Include framing constant declarations - why? - //#include "qpid/framing/AMQP_Constants.h" - // Inner classes EOS indent { @amqp.classes.each { |c| handler_class(c) } } diff --git a/cpp/rubygen/templates/constants.rb b/cpp/rubygen/templates/constants.rb new file mode 100755 index 0000000000..7e212bd38a --- /dev/null +++ b/cpp/rubygen/templates/constants.rb @@ -0,0 +1,42 @@ +#!/usr/bin/env ruby +$: << ".." # Include .. in load path +require 'cppgen' + +class ConstantsGen < CppGen + + def initialize(outdir, amqp) + super(outdir, amqp) + @namespace="qpid::framing" + @dir="qpid/framing" + end + + def generate() + h_file("#{@dir}/constants") { + namespace(@namespace) { + @amqp.constants.each { |c| + genl "inline const int #{c.name.shout} = #{c.value};" + } + } + } + + h_file("#{@dir}/reply_exceptions") { + include "constants" + include "qpid/Exception" + namespace(@namespace) { + @amqp.constants.each { |c| + if c.class_ + exname=c.name.caps+"Exception" + base = c.class_=="soft-error" ? "ChannelException" : "ConnectionException" + text=(c.doc or c.name).tr_s!(" \t\n"," ") + struct(exname, base) { + genl "#{exname}(const std::string& msg=\"#{text})\") : #{base}(#{c.value}, msg) {}" + } + end + } + } + } + end +end + +ConstantsGen.new(Outdir, Amqp).generate(); + |