summaryrefslogtreecommitdiff
path: root/cpp/rubygen
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-04-02 17:56:14 +0000
committerAlan Conway <aconway@apache.org>2008-04-02 17:56:14 +0000
commit213961a20d63578f36d5c42acae175b539e2965f (patch)
tree1d71d1ac8f854f94972cf72affd17a250d81c958 /cpp/rubygen
parente2611af099984e1e2eea65cded8140a21136ddbf (diff)
downloadqpid-python-213961a20d63578f36d5c42acae175b539e2965f.tar.gz
Encoding/decoding for new types: amqp_0_10::Map, amqp_0_10:UnknownType
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@643995 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/rubygen')
-rwxr-xr-xcpp/rubygen/0-10/specification.rb1
-rwxr-xr-xcpp/rubygen/0-10/typecode.rb85
-rwxr-xr-xcpp/rubygen/cppgen.rb11
3 files changed, 94 insertions, 3 deletions
diff --git a/cpp/rubygen/0-10/specification.rb b/cpp/rubygen/0-10/specification.rb
index a11abdb877..dbb05fb752 100755
--- a/cpp/rubygen/0-10/specification.rb
+++ b/cpp/rubygen/0-10/specification.rb
@@ -117,6 +117,7 @@ class Specification < CppGen
h_file("#{@dir}/specification") {
include "#{@dir}/built_in_types"
include "#{@dir}/complex_types"
+ include "#{@dir}/Map.h"
include "<boost/call_traits.hpp>"
include "<iosfwd>"
genl "using boost::call_traits;"
diff --git a/cpp/rubygen/0-10/typecode.rb b/cpp/rubygen/0-10/typecode.rb
new file mode 100755
index 0000000000..459516e51c
--- /dev/null
+++ b/cpp/rubygen/0-10/typecode.rb
@@ -0,0 +1,85 @@
+#!/usr/bin/env ruby
+$: << ".." # Include .. in load path
+require 'cppgen'
+
+class TypeCode < CppGen
+ def initialize(outdir, amqp)
+ super(outdir, amqp)
+ @ns="qpid::amqp_#{@amqp.version.bars}"
+ @dir="qpid/amqp_#{@amqp.version.bars}"
+ @types = @amqp.collect_all(AmqpType).select { |t| t.code }
+
+ end
+
+ def type_for_code_h()
+ h_file("#{@dir}/TypeForCode") {
+ include "#{@dir}/UnknownType.h"
+ namespace(@ns) {
+ genl
+ genl "template <uint8_t Code> struct TypeForCode;"
+ genl
+ @types.each { |t|
+ genl "template <> struct TypeForCode<#{t.code}> { typedef #{t.typename} type; };"
+ }
+ genl
+ genl "template <class V> typename V::result_type"
+ scope("apply_visitor(V& visitor, uint8_t code) {") {
+ scope("switch (code) {", "}") {
+ @types.each { |t|
+ genl "case #{t.code}: return visitor((#{t.typename}*)0);"
+ }
+ genl "default: return visitor((UnknownType*)0);"
+ }
+ }
+ genl
+ genl "std::string typeName(uint8_t code);"
+ }
+ }
+ end
+
+ def type_for_code_cpp()
+ cpp_file("#{@dir}/TypeForCode") {
+ include "<string>"
+ include "<sstream>"
+ namespace(@ns) {
+ namespace("") {
+ struct("Names") {
+ scope("Names() {") {
+ scope("for (int i =0; i < 256; ++i) {") {
+ genl "std::ostringstream os;"
+ genl "os << \"UnknownType<\" << i << \">\";"
+ genl "names[i] = os.str();"
+ }
+ @types.each { |t| genl "names[#{t.code}] = \"#{t.name}\";" }
+ }
+ genl "std::string names[256];"
+ }
+ genl "Names names;"
+ }
+ genl "std::string typeName(uint8_t code) { return names.names[code]; }"
+ }}
+ end
+
+ def code_for_type_h()
+ h_file("#{@dir}/CodeForType") {
+ 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
+ genl "template <class T> uint8_t codeFor(const T&) { return CodeForType<T>::value; }"
+ }}
+ end
+
+ def generate
+ type_for_code_h
+ type_for_code_cpp
+ code_for_type_h
+ end
+end
+
+TypeCode.new($outdir, $amqp).generate();
+
diff --git a/cpp/rubygen/cppgen.rb b/cpp/rubygen/cppgen.rb
index 63a2e6857e..d0f31a8ba8 100755
--- a/cpp/rubygen/cppgen.rb
+++ b/cpp/rubygen/cppgen.rb
@@ -57,7 +57,6 @@ class String
def cppsafe() CppMangle.include?(self) ? self+"_" : self; end
def amqp2cpp()
- throw 'Invalid "array".amqp2cpp' if self=="array"
path=split(".")
name=path.pop
return name.typename if path.empty?
@@ -116,7 +115,7 @@ end
class AmqpElement
# convert my amqp type_ attribute to a C++ type.
def amqp2cpp()
- return "Array<#{ArrayTypes[name].amqp2cpp}> " if type_=="array"
+ return "ArrayDomain<#{ArrayTypes[name].amqp2cpp}> " if type_=="array"
return type_.amqp2cpp
end
end
@@ -166,6 +165,11 @@ class AmqpAction
include AmqpHasFields
end
+class AmqpType
+ def typename() name.typename; end
+ def fixed?() fixed_width; end
+end
+
class AmqpCommand < AmqpAction
def base() "Command"; end
end
@@ -281,10 +285,11 @@ class CppGen < Generator
genl
names = name.split("::")
names.each { |n| genl "namespace #{n} {" }
+ genl "namespace {" if (names.empty?)
genl
yield
genl
- genl('}'*names.size+" // namespace "+name)
+ genl('}'*([names.size, 1].max)+" // namespace "+name)
genl
end