diff options
| author | Alan Conway <aconway@apache.org> | 2008-02-27 16:37:48 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2008-02-27 16:37:48 +0000 |
| commit | 0e9451480c83511bd37f99d83ad82b30b399f05d (patch) | |
| tree | cacafa4337b63df842398a43c9e33cc29bf324fe /qpid/cpp/rubygen/99-0/constants.rb | |
| parent | ba38d82dfdaf089f26ae204326d36190c46fd1c3 (diff) | |
| download | qpid-python-0e9451480c83511bd37f99d83ad82b30b399f05d.tar.gz | |
Generate code for both 0-99 preview and 0-10 final specs .
0-10 final: extended code generation and non-generated support classes.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@631638 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/rubygen/99-0/constants.rb')
| -rwxr-xr-x | qpid/cpp/rubygen/99-0/constants.rb | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/qpid/cpp/rubygen/99-0/constants.rb b/qpid/cpp/rubygen/99-0/constants.rb new file mode 100755 index 0000000000..b5f559d504 --- /dev/null +++ b/qpid/cpp/rubygen/99-0/constants.rb @@ -0,0 +1,82 @@ +#!/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 constants_h() + h_file("#{@dir}/constants") { + namespace(@namespace) { + scope("enum AmqpConstant {","};") { + l=[] + l.concat @amqp.constants.map { |c| "#{c.name.shout}=#{c.value}" } + @amqp.classes.each { |c| + l << "#{c.name.shout}_CLASS_ID=#{c.index}" + l.concat c.methods_.map { |m| + "#{c.name.shout}_#{m.name.shout}_METHOD_ID=#{m.index}" } + } + genl l.join(",\n") + }}} + end + + def exbase(c) + case c.class_ + when "soft-error" then "ChannelException" + when "hard-error" then "ConnectionException" + end + end + + def reply_exceptions_h() + h_file("#{@dir}/reply_exceptions") { + include "qpid/Exception" + namespace(@namespace) { + @amqp.constants.each { |c| + base = exbase c + if base + genl + struct(c.name.caps+"Exception", base) { + genl "#{c.name.caps}Exception(const std::string& msg=std::string()) : #{base}(#{c.value}, \"#{c.name}: \"+msg) {}" + } + end + } + genl + genl "void throwReplyException(int code, const std::string& text);" + } + } + end + + def reply_exceptions_cpp() + cpp_file("#{@dir}/reply_exceptions") { + include "#{@dir}/reply_exceptions" + include "<sstream>" + namespace("qpid::framing") { + scope("void throwReplyException(int code, const std::string& text) {"){ + scope("switch (code) {") { + genl "case 200: break; // No exception" + @amqp.constants.each { |c| + if exbase c + genl "case #{c.value}: throw #{c.name.caps}Exception(text);" + end + } + scope("default:","") { + genl "std::ostringstream msg;" + genl 'msg << "Invalid reply code " << code << ": " << text;' + genl 'throw InvalidArgumentException(msg.str());' + }}}}} + end + + def generate() + constants_h + reply_exceptions_h + reply_exceptions_cpp + end +end + +ConstantsGen.new($outdir, $amqp).generate(); + |
