diff options
author | Alan Conway <aconway@apache.org> | 2008-11-04 19:52:49 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2008-11-04 19:52:49 +0000 |
commit | eda249ff22edb3726243da81ff48c82e4d88e872 (patch) | |
tree | 0939d790e6a1b0d86993c9c3804c1adaa369aeb8 /cpp/rubygen | |
parent | 5d2471636928eff8b8031237c54348db0d5c388d (diff) | |
download | qpid-python-eda249ff22edb3726243da81ff48c82e4d88e872.tar.gz |
constants.rb: generate type code constants for AMQP types. Useful with Array.
framing/Array:
- added some std:::vector like functions & typedefs.
- use TypeCode enums, human readable ostream << operator.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@711365 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/rubygen')
-rwxr-xr-x | cpp/rubygen/amqpgen.rb | 25 | ||||
-rwxr-xr-x | cpp/rubygen/cppgen.rb | 2 | ||||
-rwxr-xr-x | cpp/rubygen/framing.0-10/constants.rb | 57 |
3 files changed, 74 insertions, 10 deletions
diff --git a/cpp/rubygen/amqpgen.rb b/cpp/rubygen/amqpgen.rb index 80542ebc77..b77ab09ac0 100755 --- a/cpp/rubygen/amqpgen.rb +++ b/cpp/rubygen/amqpgen.rb @@ -165,7 +165,7 @@ class AmqpElement # The root <amqp> element. def root() @root ||=parent ? parent.root : self; end - def to_s() "#<#{self.class}(#{fqname})>"; end + def to_s() "#<#{self.class}(#{fqname})>"; end def inspect() to_s; end # Text of doc child if there is one. @@ -181,6 +181,21 @@ class AmqpElement return self if is_a? AmqpClass return parent && parent.containing_class end + + # 0-10 array domains are missing element type information, add it here. + ArrayTypes={ + "str16-array" => "str-16", + "amqp-host-array" => "connection.amqp-host-url", + "command-fragments" => "session.command-fragment", + "in-doubt" => "dtx.xid", + "tx-publish" => "str-8", + "queues" => "str-8" + } + + def array_type(name) + return ArrayTypes[name] if ArrayTypes[name] + raise "Missing ArrayType entry for " + name + end end @@ -204,14 +219,6 @@ class AmqpEnum < AmqpElement amqp_child_reader :choice end -# 0-10 array domains are missing element type information, add it here. -ArrayTypes={ - "str16-array" => "str-16", - "amqp-host-array" => "connection.amqp-host-url", - "command-fragments" => "session.command-fragment", - "in-doubt" => "dtx.xid" -} - class AmqpDomain < AmqpElement def initialize(xml, parent) super diff --git a/cpp/rubygen/cppgen.rb b/cpp/rubygen/cppgen.rb index 13f6f3744d..7818e1c4b0 100755 --- a/cpp/rubygen/cppgen.rb +++ b/cpp/rubygen/cppgen.rb @@ -147,7 +147,7 @@ end class AmqpElement # convert my amqp type_ attribute to a C++ type. def amqp2cpp() - return "ArrayDomain<#{ArrayTypes[name].amqp2cpp}> " if type_=="array" + return "ArrayDomain<#{array_type(name).amqp2cpp}> " if type_=="array" return type_.amqp2cpp end diff --git a/cpp/rubygen/framing.0-10/constants.rb b/cpp/rubygen/framing.0-10/constants.rb index 0560cef887..206aabadf9 100755 --- a/cpp/rubygen/framing.0-10/constants.rb +++ b/cpp/rubygen/framing.0-10/constants.rb @@ -46,6 +46,62 @@ class ConstantsGen < CppGen } end + def typecode_enum(t) "TYPE_CODE_#{t.name.shout}" end + + def typecode_h_cpp + path="#{@dir}/TypeCode" + h_file(path) { + include("<iosfwd>") + namespace(@namespace) { + scope("enum TypeCode {", "};") { + genl @amqp.types.map { |t| "#{typecode_enum t} = #{t.code}" if t.code }.compact.join(",\n") + } + genl <<EOS + +/** True if t is a valid TypeCode value */ +bool isTypeCode(uint8_t t); + +/** Throw exception if not a valid TypeCode */ +TypeCode typeCode(uint8_t); + +/**@return 0 if t is not a valid enum TypeCode value. */ +const char* typeName(TypeCode t); + +std::ostream& operator<<(std::ostream&, TypeCode); +EOS + } + } + + cpp_file(path) { + include(path); + include("qpid/Exception.h") + include("<ostream>") + namespace(@namespace) { + scope("const char* typeName(TypeCode t) {") { + scope("switch (t) {") { + @amqp.types.each { |t| genl "case #{typecode_enum t}: return \"#{t.name}\";" if t.code } + genl "default: break;" + } + genl "return 0;"; + } + genl <<EOS + +bool isTypeCode(uint8_t t) { return typeName(TypeCode(t)); } + +TypeCode typeCode(uint8_t t) { + if (!isTypeCode(t)) throw Exception(QPID_MSG("Invalid TypeCode " << t)); + return TypeCode(t); +} + +std::ostream& operator<<(std::ostream& o, TypeCode t) { + if (isTypeCode(t)) return o << typeName(t); + else return o << "Invalid TypeCode " << t; +} +EOS + } + } + end + def enum_h() h_file("#{@dir}/enum") { # Constants for enum domains. @@ -134,6 +190,7 @@ class ConstantsGen < CppGen enum_h reply_exceptions_h reply_exceptions_cpp + typecode_h_cpp end end |