Parent

Class/Module Index [+]

Quicksearch

GLib::EnumDefinition

Attributes

ENUM_NAME[RW]
ENUM_SHORT[RW]
EnumName[RW]
Type[RW]
constants[R]
enum_name[RW]
g_type_prefix[RW]
prefix[RW]
type[RW]

Public Class Methods

new(name, const_lines, g_type_prefix, options={}) click to toggle source
# File glib2/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

Public Instance Methods

create_c() click to toggle source
# File glib2/lib/glib-mkenums.rb, line 66
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
create_h() click to toggle source
# File glib2/lib/glib-mkenums.rb, line 89
    def create_h
      %[
GType #{@enum_name}_get_type (void);
#define #{@g_type_prefix}#{@ENUM_SHORT} (#{@enum_name}_get_type())]
    end
extract_prefix(ary) click to toggle source
# File glib2/lib/glib-mkenums.rb, line 51
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
parse_const_lines(const_lines) click to toggle source
# File glib2/lib/glib-mkenums.rb, line 31
def parse_const_lines(const_lines)
  ret = ""

  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

[Validate]

Generated with the Darkfish Rdoc Generator 2.