From c11f9a79eec63da7aa6e6dac248a689a9d461beb Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Tue, 31 Jul 2007 20:00:10 +0000 Subject: Ruby code generator for C++. Not yet in active use yet but two sample templates are provided. Note: same dependency story as java codegen: distribution has pre-generated code so ruby not required to build a distro. Only required for svn working copy builds. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@561468 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/rubygen/cppgen.rb | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100755 cpp/rubygen/cppgen.rb (limited to 'cpp/rubygen/cppgen.rb') diff --git a/cpp/rubygen/cppgen.rb b/cpp/rubygen/cppgen.rb new file mode 100755 index 0000000000..3e3800c4cd --- /dev/null +++ b/cpp/rubygen/cppgen.rb @@ -0,0 +1,126 @@ +#!/usr/bin/ruby +# +# General purpose C++ code generation. +# +require 'amqpgen' +require 'set' + +Copyright=< ["bool"], + "octet"=>["u_int8_t"], + "short"=>["u_int16_t"], + "long"=>["u_int32_t"], + "longlong"=>["u_int64_t"], + "timestamp"=>["u_int64_t"], + "longstr"=>["string", "const string&"], + "shortstr"=>["string", "const string&"], + "table"=>["FieldTable", "const FieldTable&", "const FieldTable&"], + "content"=>["Content", "const Content&", "const Content&"] + } + + def lookup(amqptype) + CppTypeMap[amqptype] or raise "No cpp type for #{amqptype}"; + end + + def member_type(amqptype) lookup(amqptype)[0]; end + def param_type(amqptype) t=lookup(amqptype); t[1] or t[0]; end + def return_type(amqptype) t=lookup(amqptype); t[2] or t[0]; end +end + +# Additional methods for AmqpClass +class AmqpClass + def cppname() @cache_cppname ||= name.caps; end +end + +class CppGen < Generator + def initialize(outdir, *specs) + super(outdir,*specs) + end + + # Write a header file. + def h_file(path) + guard=path.upcase.tr('./-','_') + file(path) { + gen "#ifndef #{guard}\n" + gen "#define #{guard}\n" + gen Copyright + yield + gen "#endif /*!#{guard}*/\n" + } + end + + # Write a .cpp file. + def cpp_file(path) + file (path) do + gen Copyright + yield + end + end +end + -- cgit v1.2.1