Author: aconway
Date: Tue Apr 15 08:57:58 2008
New Revision: 648297
URL: http://svn.apache.org/viewvc?rev=648297&view=rev
Log:
Cleanup of size calculations and handling UnknownStruct
Modified:
incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb
incubator/qpid/trunk/qpid/cpp/src/tests/amqp_0_10/serialize.cpp
Modified: incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb?rev=648297&r1=648296&r2=648297&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb (original)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb Tue Apr 15
08:57:58 2008
@@ -3,7 +3,8 @@
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 @@
end
def gen_visitor(base, subs)
- if base=="Struct"
- subs << UnknownStructSub.new
- end
-
h_file("[EMAIL PROTECTED]/#{base}Visitor.h") {
include base=="Struct" ? "[EMAIL PROTECTED]/structs" : "[EMAIL
PROTECTED]/specification"
namespace("[EMAIL PROTECTED]") {
@@ -293,16 +290,14 @@
include base=="Struct" ? "[EMAIL PROTECTED]/structs" : "[EMAIL
PROTECTED]/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 @@
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 @@
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
Modified: incubator/qpid/trunk/qpid/cpp/src/tests/amqp_0_10/serialize.cpp
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/amqp_0_10/serialize.cpp?rev=648297&r1=648296&r2=648297&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/amqp_0_10/serialize.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/amqp_0_10/serialize.cpp Tue Apr 15
08:57:58 2008
@@ -227,6 +227,15 @@
BOOST_REQUIRE(dp2);
BOOST_CHECK_EQUAL(dp2->priority, message::MEDIUM);
BOOST_CHECK_EQUAL(dp2->routingKey, "foo");
+
+ // Verify we can recode an unknown struct unchanged.
+ data.clear();
+ Codec::encode(back_inserter(data))(uint32_t(10));
+ data.append(10, 'X');
+ Codec::decode(data.begin())(s2);
+ string data2;
+ Codec::decode(back_inserter(data2));
+ BOOST_CHECK_EQUAL(data, data2);
}
struct DummyPacked {