# File lib/glib-mkenums.rb, line 19 def initialize(name, const_lines, g_type_prefix, options={}) @options = options || {} @EnumName = name @g_type_prefix = g_type_prefix @constants = [] @enum_name = to_snail_case(@EnumName) @ENUM_NAME = @enum_name.upcase @ENUM_SHORT = @ENUM_NAME.sub(/^#{@g_type_prefix.sub(/_TYPE.*$/, "")}/, "").sub(/^_/, "") parse_const_lines(const_lines) end
# File lib/glib-mkenums.rb, line 64 def create_c constants = "\n" + @constants.collect{|name, nick| %[ { #{name}, "#{name}", "#{nick}" },\n] }.join + %[ { 0, NULL, NULL }] ret = GType#{@enum_name}_get_type (void){ static GType etype = 0; if (etype == 0) { static const G#{@Type}Value values[] = {#{constants} }; etype = g_#{@type}_register_static ("#{@EnumName}", values); } return etype;} ret end
# File lib/glib-mkenums.rb, line 87 def create_h %[ GType #{@enum_name}_get_type (void); #define #{@g_type_prefix}#{@ENUM_SHORT} (#{@enum_name}_get_type())] end
# File lib/glib-mkenums.rb, line 49 def extract_prefix(ary) return [] if ary == nil a = ary[0].split(//) if ary.size == 1 @ENUM_NAME + "_" else ary[1..-1].each do |b| b = b.split(//) l = [a.length, b.length].min a = a[0, (0...l).find{|i| a[i] != b[i] } || l] end a.join('') end end
# File lib/glib-mkenums.rb, line 31 def parse_const_lines(const_lines) if @options[:force_flags] or /<</ =~ const_lines @type = "flags" @Type = "Flags" else @type = "enum" @Type = "Enum" end constants = [] const_lines.scan(/^\s*([^\s,]*).*\n/) do |name| constants << name[0] unless name[0] =~ /(^[\/\*]|^#|^$)/ end @prefix = extract_prefix(constants) constants.each do |name| @constants << [name, name.sub(/#{@prefix}/, "").gsub(/_/, "-").downcase] end end
Generated with the Darkfish Rdoc Generator 2.