summaryrefslogtreecommitdiff
path: root/cpp/rubygen
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-11-22 23:55:39 +0000
committerAlan Conway <aconway@apache.org>2007-11-22 23:55:39 +0000
commitcb070d9813e4232b4ec8409ca555b529ee5cee4b (patch)
tree7f8ed15de2c4f933db59b79b52222c70f2a2a240 /cpp/rubygen
parent4d16c847bd0868ac8ff3039ce22fcdae28606aeb (diff)
downloadqpid-python-cb070d9813e4232b4ec8409ca555b529ee5cee4b.tar.gz
Added framing::BodyHolder:
- Uniform holder for all body types, replaces MethodHolder. - Uses in_place constructors to avoid avoid body copy. framing::AMQFrame: - Holds body in heap-allocated intrusive_ptr<BodyHolder> - Uses in_place constructors to avoid avoid body copy. Removed/downgraded to TODO many redundant FIXME comments. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@597513 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/rubygen')
-rwxr-xr-xcpp/rubygen/templates/MethodHolder.rb54
1 files changed, 34 insertions, 20 deletions
diff --git a/cpp/rubygen/templates/MethodHolder.rb b/cpp/rubygen/templates/MethodHolder.rb
index 95c60f5727..7e915677b2 100755
--- a/cpp/rubygen/templates/MethodHolder.rb
+++ b/cpp/rubygen/templates/MethodHolder.rb
@@ -7,13 +7,16 @@ class MethodHolderGen < CppGen
def initialize(outdir, amqp)
super(outdir, amqp)
@namespace="qpid::framing"
- @classname="MethodHolder"
- @filename="qpid/framing/MethodHolder"
+ @classname="BodyHolder"
+ @filename="qpid/framing/BodyHolder"
end
def gen_max_size()
# Generate program to generate MaxSize.h
- cpp_file("generate_#{@classname}MaxSize_h") {
+ cpp_file("generate_MaxMethodBodySize_h") {
+ include "qpid/framing/AMQHeaderBody"
+ include "qpid/framing/AMQContentBody"
+ include "qpid/framing/AMQHeartbeatBody"
@amqp.methods_.each { |m| include "qpid/framing/#{m.body_name}" }
genl
include "<algorithm>"
@@ -24,13 +27,16 @@ class MethodHolderGen < CppGen
genl
scope("int main(int, char** argv) {") {
genl "size_t maxSize=0;"
+ genl "maxSize=max(maxSize, sizeof(AMQHeaderBody));"
+ genl "maxSize=max(maxSize, sizeof(AMQContentBody));"
+ genl "maxSize=max(maxSize, sizeof(AMQHeartbeatBody));"
@amqp.methods_.each { |m|
genl "maxSize=max(maxSize, sizeof(#{m.body_name}));" }
gen <<EOS
-ofstream out("#{@filename}MaxSize.h");
+ofstream out("qpid/framing/MaxMethodBodySize.h");
out << "// GENERATED CODE: generated by " << argv[0] << endl;
out << "namespace qpid{ namespace framing { " << endl;
-out << "const size_t MAX_METHODBODY_SIZE=" << maxSize << ";" << endl;
+out << "const size_t MAX_METHOD_BODY_SIZE=" << maxSize << ";" << endl;
out << "}}" << endl;
EOS
}
@@ -38,40 +44,48 @@ EOS
end
def gen_construct
- cpp_file(@filename+"_construct") {
+ cpp_file(@filename+"_gen") {
include @filename
- include "qpid/framing/MethodBodyConstVisitor.h"
+ include "qpid/framing/AMQHeaderBody"
+ include "qpid/framing/AMQContentBody"
+ include "qpid/framing/AMQHeartbeatBody"
@amqp.methods_.each { |m| include "qpid/framing/#{m.body_name}" }
- genl
+ include "qpid/framing/FrameDefaultVisitor.h"
include "qpid/Exception.h"
genl
namespace(@namespace) {
- # construct function
- scope("void #{@classname}::construct(ClassId c, MethodId m) {") {
+ scope("void #{@classname}::setMethod(ClassId c, MethodId m) {") {
scope("switch (c) {") {
@amqp.classes.each { |c|
scope("case #{c.index}: switch(m) {") {
c.methods_.each { |m|
- genl "case #{m.index}: blob.construct(in_place<#{m.body_name}>()); break;"
+ genl "case #{m.index}: blob = in_place<#{m.body_name}>(); break;"
}
- genl "default: throw Exception(QPID_MSG(\"Invalid method id \" << m << \" for class #{c.name} \"));"
+ genl "default: throw Exception(QPID_MSG(\"Invalid method id \" << int(m) << \" for class #{c.name} \"));"
}
genl "break;"
}
- genl "default: throw Exception(QPID_MSG(\"Invalid class id \" << c));"
+ genl "default: throw Exception(QPID_MSG(\"Invalid class id \" << int(c)));"
}
}
- # CopyVisitor
- struct("#{@classname}::CopyVisitor", "public MethodBodyConstVisitor") { genl "MethodHolder& holder;"
- genl "CopyVisitor(MethodHolder& h) : holder(h) {}"
+
+ struct("CopyVisitor", "public FrameDefaultVisitor") {
+ genl "using FrameDefaultVisitor::visit;"
+ genl "using FrameDefaultVisitor::defaultVisit;"
+ genl "BodyHolder& holder;"
+ genl "CopyVisitor(BodyHolder& h) : holder(h) {}"
+ ["Header", "Content", "Heartbeat"].each { |type|
+ genl "void visit(const AMQ#{type}Body& x) { holder=x; }"
+ }
@amqp.methods_.each { |m|
- genl "void visit(const #{m.body_name}& x) { holder.blob=x; }"
+ genl "void visit(const #{m.body_name}& x) { holder=x; }"
}
+ genl "void defaultVisit(const AMQBody&) { assert(0); }"
}
genl
- # operator=
- scope("#{@classname}& MethodHolder::operator=(const AMQMethodBody& m) {") {
- genl "CopyVisitor cv(*this); m.accept(cv); return *this;"
+
+ scope("void BodyHolder::setBody(const AMQBody& b) {") {
+ genl "CopyVisitor cv(*this); b.accept(cv);"
}
}}
end