diff options
author | Alan Conway <aconway@apache.org> | 2008-04-15 15:57:58 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2008-04-15 15:57:58 +0000 |
commit | c61ea56812df14a7465cb17d840039996e85fe78 (patch) | |
tree | 2f195af5ff3e924fae71fb4a8dabcdf5cdeb2551 /cpp/rubygen | |
parent | 5347c108018ad11334e435c0eb2da638888080a9 (diff) | |
download | qpid-python-c61ea56812df14a7465cb17d840039996e85fe78.tar.gz |
Cleanup of size calculations and handling UnknownStruct
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@648297 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/rubygen')
-rwxr-xr-x | cpp/rubygen/0-10/specification.rb | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/cpp/rubygen/0-10/specification.rb b/cpp/rubygen/0-10/specification.rb index 25618116cb..4f912228f7 100755 --- a/cpp/rubygen/0-10/specification.rb +++ b/cpp/rubygen/0-10/specification.rb @@ -3,7 +3,8 @@ $: << ".." # Include .. in load path require 'cppgen' -class UnknownStructSub +# Dummy element representing an unknown struct type. +class UnknownStruct def visitable?() true end def fqclassname() "UnknownStruct" end end @@ -264,10 +265,6 @@ class Specification < CppGen end def gen_visitor(base, subs) - if base=="Struct" - subs << UnknownStructSub.new - end - h_file("#{@dir}/#{base}Visitor.h") { include base=="Struct" ? "#{@dir}/structs" : "#{@dir}/specification" namespace("#{@ns}") { @@ -293,16 +290,14 @@ class Specification < CppGen include base=="Struct" ? "#{@dir}/structs" : "#{@dir}/specification" namespace(@ns){ namespace("#{base.downcase}_max") { - gen "template <class M, class X> " - struct("Max") { - genl "static const size_t max=(M::max > sizeof(X)) ? M::max : sizeof(X);" - } - genl "struct Max000 { static const size_t max=0; };" - last="Max000" + genl "static const size_t MAX000=0;" + last="MAX000" subs.each { |s| - genl "typedef Max<#{last}, #{s.fqclassname}> #{last.succ!};" + sizeof="sizeof(#{s.fqclassname})" + genl "static const size_t #{last.succ} = #{sizeof} > #{last} ? #{sizeof} : #{last};" + last.succ! } - genl "static const int MAX=#{last}::max;" + genl "static const int MAX=#{last};" } holder_base="amqp_0_10::Holder<#{name}, #{base}, #{base.downcase}_max::MAX>" struct("#{name}", "public #{holder_base}") { @@ -326,7 +321,7 @@ class Specification < CppGen genl "uint16_t key=(classCode<<8)+code;" scope ("switch(key) {") { subs.each { |s| - genl "case 0x#{s.full_code.to_s(16)}: *this=in_place<#{s.fqclassname}>(); break;" + genl "case 0x#{s.full_code.to_s(16)}: *this=in_place<#{s.fqclassname}>(); break;" unless (s.is_a? UnknownStruct) } genl "default: " indent { @@ -345,6 +340,7 @@ class Specification < CppGen end def gen_visitable(base, subs) + subs << UnknownStruct.new if base=="Struct" # Extra case for unknown structs. gen_holder(base, subs) gen_visitor(base, subs) end |