summaryrefslogtreecommitdiff
path: root/cpp/rubygen/templates/constants.rb
blob: 2ef65027721e944ce39226da9a02661481ab083e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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) { 
        scope("enum AmqpConstant {","};") { 
          genl @amqp.constants.map { |c| "#{c.name.shout}=#{c.value}" }.join(",\n")
        }
      }
    }
    
    h_file("#{@dir}/reply_exceptions") {
      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();