summaryrefslogtreecommitdiff
path: root/cpp/rubygen
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-04-08 19:53:07 +0000
committerAlan Conway <aconway@apache.org>2008-04-08 19:53:07 +0000
commite72e25abd1272c4e9489f7efd5bc02c4ecf0b5cd (patch)
tree2d32b5153aefb4059ec410118ffd80f37d64b6bd /cpp/rubygen
parent43aaed1c309c8c7ff95695109cf49b5b9157f4b6 (diff)
downloadqpid-python-e72e25abd1272c4e9489f7efd5bc02c4ecf0b5cd.tar.gz
Summary: added 0-10 Array encoding and decoding.
rubygen/0-10/allsegmenttypes.rb: test header,body and each command and control type. rubygen/0-10/specification.rb: enable packed encoding. src/qpid/amqp_0_10/Array.h: Implemented array and array domains. src/qpid/amqp_0_10/Codec.h: enable litte-endian encoding for pack bits src/qpid/amqp_0_10/Packer.h: use litte-endian encoding for pack bits src/qpid/amqp_0_10/Unit.cpp, .h: setting flags, fix op <<. src/qpid/amqp_0_10/complex_types.cpp, .h: added op << src/qpid/framing/Blob.h: copy-object template constructor. src/tests/amqp_0_10/serialize.cpp: - test Array Minor adjustments for new Array.h: src/qpid/amqp_0_10/Map.cpp src/qpid/amqp_0_10/Map.h src/qpid/amqp_0_10/UnknownType.h src/qpid/amqp_0_10/built_in_types.h src/qpid/amqp_0_10/Body.h git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@646054 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/rubygen')
-rwxr-xr-xcpp/rubygen/0-10/allsegmenttypes.rb34
-rwxr-xr-xcpp/rubygen/0-10/specification.rb15
-rwxr-xr-xcpp/rubygen/0-10/typecode.rb20
3 files changed, 59 insertions, 10 deletions
diff --git a/cpp/rubygen/0-10/allsegmenttypes.rb b/cpp/rubygen/0-10/allsegmenttypes.rb
new file mode 100755
index 0000000000..c4c4095e02
--- /dev/null
+++ b/cpp/rubygen/0-10/allsegmenttypes.rb
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+$: << ".." # Include .. in load path
+require 'cppgen'
+
+class GenAllSegmentTypes < CppGen
+ def initialize(outdir, amqp)
+ super(outdir, amqp)
+ end
+
+ def generate
+ h_file("tests/allSegmentTypes.h") {
+ include "qpid/amqp_0_10/specification.h"
+ include "qpid/amqp_0_10/Header.h"
+ include "qpid/amqp_0_10/Body.h"
+ genl
+ genl "using namespace qpid::amqp_0_10;"
+ genl
+ scope("template <class Op> size_t allSegmentTypes(Op& op) {"){
+ genl "op(Header());"
+ genl "op(Body());"
+ n = 2;
+ @amqp.classes.each { |c|
+ c.commands.each { |s| genl "op(CommandHolder(#{c.nsname}::#{s.classname}()));" }
+ c.controls.each { |s| genl "op(ControlHolder(#{c.nsname}::#{s.classname}()));" }
+ n += 2
+ }
+ genl "return #{n};"
+ }
+ }
+ end
+end
+
+GenAllSegmentTypes.new($outdir, $amqp).generate();
+
diff --git a/cpp/rubygen/0-10/specification.rb b/cpp/rubygen/0-10/specification.rb
index d8c5378538..54d39de9b4 100755
--- a/cpp/rubygen/0-10/specification.rb
+++ b/cpp/rubygen/0-10/specification.rb
@@ -64,11 +64,11 @@ class Specification < CppGen
genl
yield if block
}
+ genl "inline Packer<#{x.classname}> serializable(#{x.classname}& x) { return Packer<#{x.classname}>(x); }" unless x.respond_to? :pack and x.pack == "0"
genl "std::ostream& operator << (std::ostream&, const #{x.classname}&);"
genl "bool operator==(const #{x.classname}&, const #{x.classname}&);"
end
- # FIXME aconway 2008-03-10: packing, coding
def action_struct_cpp(x)
genl
genl "const char* #{x.classname}::NAME=\"#{x.fqname}\";"
@@ -89,7 +89,7 @@ class Specification < CppGen
scope("std::ostream& operator << (std::ostream& o, const #{x.classname}&#{"x" unless x.fields.empty?}) {") {
genl "o << \"[#{x.fqname}\";";
x.fields.each{ |f| genl "o << \" #{f.name}=\" << x.#{f.cppname};" }
- genl "o << \"];\";"
+ genl "o << \"]\";"
genl "return o;"
}
end
@@ -151,8 +151,8 @@ class Specification < CppGen
def gen_specification()
h_file("#{@dir}/specification") {
include "#{@dir}/specification_fwd"
- include "#{@dir}/complex_types"
- include "#{@dir}/Map.h"
+ include "#{@dir}/all_built_in_types"
+ include "#{@dir}/Packer.h"
include "<boost/call_traits.hpp>"
include "<iosfwd>"
genl "using boost::call_traits;"
@@ -271,7 +271,7 @@ class Specification < CppGen
holder_base="amqp_0_10::Holder<#{base}Holder, #{base}, #{base.downcase}_max::MAX>"
struct("#{name}", "public #{holder_base}") {
genl "#{name}() {}"
- genl "template <class T> #{name}(const T& t) : #{holder_base}(t) {}"
+ genl "template <class T> explicit #{name}(const T& t) : #{holder_base}(t) {}"
genl "using #{holder_base}::operator=;"
genl "void set(uint8_t classCode, uint8_t code);"
}
@@ -281,7 +281,8 @@ class Specification < CppGen
}
cpp_file("#{@dir}/#{name}") {
- include "#{@dir}/#{name}"
+ include "#{name}"
+ include "exceptions.h"
namespace(@ns) {
genl "using framing::in_place;"
genl
@@ -291,7 +292,7 @@ class Specification < CppGen
subs.each { |s|
genl "case 0x#{s.full_code.to_s(16)}: *this=in_place<#{s.fqclassname}>(); break;"
}
- genl "default: assert(0);"
+ genl "default: throw CommandInvalidException(QPID_MSG(\"Invalid class-#{base.downcase} key \" << std::hex << key));"
}}
genl
genl "std::ostream& operator<<(std::ostream& o, const #{name}& h) { return h.get() ? (o << *h.get()) : (o << \"<empty #{name}>\"); }"
diff --git a/cpp/rubygen/0-10/typecode.rb b/cpp/rubygen/0-10/typecode.rb
index 459516e51c..e36b92c07c 100755
--- a/cpp/rubygen/0-10/typecode.rb
+++ b/cpp/rubygen/0-10/typecode.rb
@@ -13,6 +13,7 @@ class TypeCode < CppGen
def type_for_code_h()
h_file("#{@dir}/TypeForCode") {
+ include "#{@dir}/built_in_types.h"
include "#{@dir}/UnknownType.h"
namespace(@ns) {
genl
@@ -61,17 +62,30 @@ class TypeCode < CppGen
end
def code_for_type_h()
- h_file("#{@dir}/CodeForType") {
+ name="#{@dir}/CodeForType"
+ h_file(name) {
+ include "#{@dir}/built_in_types.h"
+
namespace(@ns) {
genl
genl "template <class T> struct CodeForType;"
genl
@types.each { |t|
- genl "template <> struct CodeForType<#{t.typename}> { static const uint8_t value=#{t.code}; };"
+ genl "template <> struct CodeForType<#{t.typename}> { static const uint8_t value; };"
}
genl
genl "template <class T> uint8_t codeFor(const T&) { return CodeForType<T>::value; }"
- }}
+ }
+ }
+
+ cpp_file(name) {
+ include name
+ namespace(@ns) {
+ @types.each { |t|
+ genl "const uint8_t CodeForType<#{t.typename}>::value=#{t.code};"
+ }
+ }
+ }
end
def generate