summaryrefslogtreecommitdiff
path: root/cpp/rubygen
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/rubygen')
-rwxr-xr-xcpp/rubygen/amqpgen.rb9
-rwxr-xr-xcpp/rubygen/cppgen.rb9
-rwxr-xr-xcpp/rubygen/templates/MethodBodyConstVisitor.rb27
-rwxr-xr-xcpp/rubygen/templates/MethodHolder.rb37
-rwxr-xr-xcpp/rubygen/templates/Proxy.rb2
-rw-r--r--cpp/rubygen/templates/Session.rb4
-rwxr-xr-xcpp/rubygen/templates/all_method_bodies.rb21
7 files changed, 89 insertions, 20 deletions
diff --git a/cpp/rubygen/amqpgen.rb b/cpp/rubygen/amqpgen.rb
index a144825f08..333c7dd654 100755
--- a/cpp/rubygen/amqpgen.rb
+++ b/cpp/rubygen/amqpgen.rb
@@ -115,11 +115,7 @@ class AmqpClass < AmqpElement
# chassis should be "client" or "server"
def amqp_methods_on(chassis)
@cache_amqp_methods_on ||= { }
-
- els = elements.collect("method/chassis[@name='#{chassis}']/..") { |m|
- AmqpMethod.new(m,self)
- }.sort_by_name
- @cache_amqp_methods_on[chassis] ||= els
+ @cache_amqp_methods_on[chassis] ||= elements.collect("method/chassis[@name='#{chassis}']/..") { |m| AmqpMethod.new(m,self) }.sort_by_name
end
end
@@ -153,7 +149,8 @@ class AmqpRoot < AmqpElement
end
def amqp_classes()
- @cache_amqp_classes ||= elements.collect("class") { |c| AmqpClass.new(c,self) }.sort_by_name
+ @cache_amqp_classes ||= elements.collect("class") { |c|
+ AmqpClass.new(c,self) }.sort_by_name
end
# Return all methods on all classes.
diff --git a/cpp/rubygen/cppgen.rb b/cpp/rubygen/cppgen.rb
index 724634e514..a3314c7e11 100755
--- a/cpp/rubygen/cppgen.rb
+++ b/cpp/rubygen/cppgen.rb
@@ -63,6 +63,7 @@ end
class AmqpField
def cppname() @cache_cppname ||= name.lcaps.cppsafe; end
def cpptype() @cache_cpptype ||= amqp_root.param_type(field_type); end
+ def cppret_type() @cache_cpptype ||= amqp_root.return_type(field_type); end
def type_name () @type_name ||= cpptype+" "+cppname; end
end
@@ -159,8 +160,12 @@ class CppGen < Generator
def struct_class(type, name, bases, &block)
genl
gen "#{type} #{name}"
- gen ": #{bases.join(', ')}" unless bases.empty?
- scope(" {","};") { yield }
+ if (!bases.empty?)
+ genl ":"
+ indent { gen "#{bases.join(",\n")}" }
+ end
+ genl
+ scope("{","};") { yield }
end
def struct(name, *bases, &block) struct_class("struct", name, bases, &block); end
diff --git a/cpp/rubygen/templates/MethodBodyConstVisitor.rb b/cpp/rubygen/templates/MethodBodyConstVisitor.rb
new file mode 100755
index 0000000000..6fd7fe8ead
--- /dev/null
+++ b/cpp/rubygen/templates/MethodBodyConstVisitor.rb
@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+$: << ".." # Include .. in load path
+require 'cppgen'
+
+class MethodBodyConstVisitorGen < CppGen
+
+ def initialize(outdir, amqp)
+ super(outdir, amqp)
+ @namespace="qpid::framing"
+ @classname="MethodBodyConstVisitor"
+ @filename="qpid/framing/MethodBodyConstVisitor"
+ end
+
+ def generate()
+ h_file("#{@filename}") {
+ namespace(@namespace) {
+ @amqp.amqp_methods.each { |m| genl "class #{m.body_name};" }
+ cpp_class("MethodBodyConstVisitor") {
+ genl "public:"
+ genl "virtual ~MethodBodyConstVisitor() {}"
+ @amqp.amqp_methods.each { |m| genl "virtual void visit(const #{m.body_name}&) = 0;" }
+ }}}
+ end
+end
+
+MethodBodyConstVisitorGen.new(Outdir, Amqp).generate();
+
diff --git a/cpp/rubygen/templates/MethodHolder.rb b/cpp/rubygen/templates/MethodHolder.rb
index 65fa824fd4..39a570c982 100755
--- a/cpp/rubygen/templates/MethodHolder.rb
+++ b/cpp/rubygen/templates/MethodHolder.rb
@@ -40,23 +40,42 @@ EOS
def gen_construct
cpp_file(@filename+"_construct") {
include @filename
+ include "qpid/framing/MethodBodyConstVisitor.h"
@amqp.amqp_methods.each { |m| include "qpid/framing/#{m.body_name}" }
genl
- namespace(@namespace) {
- scope("void #{@classname}::construct(const Id& newId) {") {
- scope("switch (newId.first) {") {
+ include "qpid/Exception.h"
+ genl
+ namespace(@namespace) {
+ # construct function
+ scope("void #{@classname}::construct(ClassId c, MethodId m) {") {
+ scope("switch (c) {") {
@amqp.amqp_classes.each { |c|
- scope("case #{c.index}: switch(newId.second) {") {
+ scope("case #{c.index}: switch(m) {") {
c.amqp_methods.each { |m|
genl "case #{m.index}: blob.construct(in_place<#{m.body_name}>()); break;"
- }}
+ }
+ genl "default: throw Exception(QPID_MSG(\"Invalid method id \" << m << \" for class #{c.name} \"));"
+ }
genl "break;"
- }}
- genl "id=newId;";
- }}}
+ }
+ genl "default: throw Exception(QPID_MSG(\"Invalid class id \" << c));"
+ }
+ }
+ # CopyVisitor
+ struct("#{@classname}::CopyVisitor", "public MethodBodyConstVisitor") { genl "MethodHolder& holder;"
+ genl "CopyVisitor(MethodHolder& h) : holder(h) {}"
+ @amqp.amqp_methods.each { |m|
+ genl "void visit(const #{m.body_name}& x) { holder.blob=x; }"
+ }
+ }
+ genl
+ # operator=
+ scope("#{@classname}& MethodHolder::operator=(const AMQMethodBody& m) {") {
+ genl "CopyVisitor cv(*this); m.accept(cv); return *this;"
+ }
+ }}
end
-
def generate
gen_max_size
gen_construct
diff --git a/cpp/rubygen/templates/Proxy.rb b/cpp/rubygen/templates/Proxy.rb
index f36d6bcd99..a6c0763a8a 100755
--- a/cpp/rubygen/templates/Proxy.rb
+++ b/cpp/rubygen/templates/Proxy.rb
@@ -38,7 +38,7 @@ EOS
genl "void #{@classname}::#{cname}::#{m.cppname}(#{m.signature.join(", ")})"
scope {
params=(["channel.getVersion()"]+m.param_names).join(", ")
- genl "channel.send(make_shared_ptr(new #{m.body_name}(#{params})));"
+ genl "channel.send(#{m.body_name}(#{params}));"
}}
end
diff --git a/cpp/rubygen/templates/Session.rb b/cpp/rubygen/templates/Session.rb
index eaa4347974..4265731d32 100644
--- a/cpp/rubygen/templates/Session.rb
+++ b/cpp/rubygen/templates/Session.rb
@@ -37,7 +37,7 @@ class SessionGen < CppGen
indent { gen params.join(",\n") }
gen "){\n\n"
indent (2) {
- gen "return impl->send(AMQMethodBody::shared_ptr(new #{m.body_name}("
+ gen "return impl->send(#{m.body_name}("
params = ["version"] + m.param_names
gen params.join(", ")
other_params=[]
@@ -49,7 +49,7 @@ class SessionGen < CppGen
else
other_params << "true"
end
- gen ")), #{other_params.join(", ")});\n"
+ gen "), #{other_params.join(", ")});\n"
}
gen "}\n\n"
end
diff --git a/cpp/rubygen/templates/all_method_bodies.rb b/cpp/rubygen/templates/all_method_bodies.rb
new file mode 100755
index 0000000000..38fbc31593
--- /dev/null
+++ b/cpp/rubygen/templates/all_method_bodies.rb
@@ -0,0 +1,21 @@
+#!/usr/bin/env ruby
+$: << ".." # Include .. in load path
+require 'cppgen'
+
+class AllMethodBodiesGen < CppGen
+
+ def initialize(outdir, amqp)
+ super(outdir, amqp)
+ @namespace="qpid::framing"
+ @filename="qpid/framing/all_method_bodies"
+ end
+
+ def generate()
+ h_file(@filename) {
+ @amqp.amqp_methods.each { |m| include "qpid/framing/"+m.body_name }
+ }
+ end
+end
+
+AllMethodBodiesGen.new(Outdir, Amqp).generate();
+