#!/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