You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2007/08/28 21:40:37 UTC

svn commit: r570540 - in /incubator/qpid/trunk/qpid/cpp/rubygen: amqpgen.rb templates/Operations.rb templates/constants.rb

Author: aconway
Date: Tue Aug 28 12:40:36 2007
New Revision: 570540

URL: http://svn.apache.org/viewvc?rev=570540&view=rev
Log:
Generate constants and reply exceptions from spec constants.

Added:
    incubator/qpid/trunk/qpid/cpp/rubygen/templates/constants.rb   (with props)
Modified:
    incubator/qpid/trunk/qpid/cpp/rubygen/amqpgen.rb
    incubator/qpid/trunk/qpid/cpp/rubygen/templates/Operations.rb

Modified: incubator/qpid/trunk/qpid/cpp/rubygen/amqpgen.rb
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/amqpgen.rb?rev=570540&r1=570539&r2=570540&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/amqpgen.rb (original)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/amqpgen.rb Tue Aug 28 12:40:36 2007
@@ -15,6 +15,9 @@
   # Convert to underbar_separated_form.
   def bars() tr('- .','_'); end
 
+  # Convert to ALL_UPPERCASE_FORM
+  def shout() bars.upcase!;  end
+
   # Convert to lowerCaseCapitalizedForm
   def lcaps() gsub( /\W(\w)/ ) { |m| $1.upcase } end
 
@@ -104,6 +107,9 @@
 
   def to_s() "#<#{self.class}(#{name})>"; end
   def inspect() to_s; end
+
+  # Text of doc child if there is one.
+  def doc() d=xml.elements["doc"]; d and d.text; end
 end
 
 AmqpResponse = AmqpElement
@@ -135,7 +141,7 @@
 
 class AmqpConstant < AmqpElement
   def initialize(xml, parent) super; end
-  amqp_attr_reader :value, :datatype
+  amqp_attr_reader :value, :class
 end
 
 class AmqpResult < AmqpElement
@@ -192,7 +198,7 @@
   end
 
   amqp_attr_reader :major, :minor
-  amqp_child_reader :class, :domain
+  amqp_child_reader :class, :domain, :constant
 
   def version() major + "-" + minor; end
 

Modified: incubator/qpid/trunk/qpid/cpp/rubygen/templates/Operations.rb
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/templates/Operations.rb?rev=570540&r1=570539&r2=570540&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/templates/Operations.rb (original)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/templates/Operations.rb Tue Aug 28 12:40:36 2007
@@ -78,9 +78,6 @@
 
     virtual ProtocolVersion getVersion() const = 0;
 
-    // Include framing constant declarations - why?
-    //#include "qpid/framing/AMQP_Constants.h"
-
     // Inner classes
 EOS
   indent { @amqp.classes.each { |c| handler_class(c) } }

Added: incubator/qpid/trunk/qpid/cpp/rubygen/templates/constants.rb
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/templates/constants.rb?rev=570540&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/templates/constants.rb (added)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/templates/constants.rb Tue Aug 28 12:40:36 2007
@@ -0,0 +1,42 @@
+#!/usr/bin/env ruby
+$: << ".."                      # Include .. in load path
+require 'cppgen'
+
+class ConstantsGen < CppGen
+  
+  def initialize(outdir, amqp)
+    super(outdir, amqp)
+    @namespace="qpid::framing"
+    @dir="qpid/framing"
+  end
+
+  def generate()
+    h_file("#{@dir}/constants") {
+      namespace(@namespace) { 
+        @amqp.constants.each { |c|
+          genl "inline const int #{c.name.shout} = #{c.value};"
+        }
+      }
+    }
+    
+    h_file("#{@dir}/reply_exceptions") {
+      include "constants"
+      include "qpid/Exception"
+      namespace(@namespace) {
+        @amqp.constants.each { |c|
+          if c.class_
+            exname=c.name.caps+"Exception"
+            base = c.class_=="soft-error" ? "ChannelException" : "ConnectionException"
+            text=(c.doc or c.name).tr_s!(" \t\n"," ")
+            struct(exname, base) {
+              genl "#{exname}(const std::string& msg=\"#{text})\") : #{base}(#{c.value}, msg) {}"
+            }
+          end
+        }
+      }
+    }
+  end
+end
+
+ConstantsGen.new(Outdir, Amqp).generate();
+

Propchange: incubator/qpid/trunk/qpid/cpp/rubygen/templates/constants.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/rubygen/templates/constants.rb
------------------------------------------------------------------------------
    svn:executable = *