diff options
Diffstat (limited to 'cpp/rubygen')
| -rwxr-xr-x | cpp/rubygen/templates/MethodHolder.rb | 54 |
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 |
