class GLib::MkEnums - glib2-2.2.0 Documentation

# class GLib::MkEnums

### Public Class Methods

create(target_filename, files, g_type_prefix, include_files, options) click to toggle source

Create target_filename.c and target_filename.h from files with g_type_prefix and include_files.

- target_filename: the target file name. This creates #{target_filename.c} and #{target_filename.h}.

- files: header files to parse

- g_type_prefix: the gtype prefix such as GTK_TYPE_

- include_files: define include <file> lines into target_filename.c

    # File lib/glib-mkenums.rb, line 136
    def self.create(target_filename, files, g_type_prefix, include_files,
                    options)
      puts "creating #{target_filename}.c"
      mkenums = MkEnums.new(target_filename, files, g_type_prefix, include_files,
                            options)

      open("#{target_filename}.c", "w") do |out|
        out.write(mkenums.create_c)
      end
      puts "creating #{target_filename}.h"
      open("#{target_filename}.h", "w") do |out|
        out.write(mkenums.create_h)
      end
    end

new(target_filename, files, g_type_prefix, include_files, options) click to toggle source

Initialize GLib::MkEnums

- target_filename: the target file name. This creates #{target_filename.c} and #{target_filename.h}.

- files: header files to parse

- g_type_prefix: the gtype prefix such as GTK_TYPE_

- include_files: define include <file> lines into target_filename.c

    # File lib/glib-mkenums.rb, line 157
    def initialize(target_filename, files, g_type_prefix, include_files, options)
      @target_filename = target_filename
      @include_files = include_files
      @targets = []
      files.each do |path|
        data = ""
        File.open(path) do |i|
          data = i.read
        end
        @targets << [path, EnumDefinition.parse(data, g_type_prefix, options)]
      end
    end

### Public Instance Methods

create_c() click to toggle source

Create a C source as a String.

    # File lib/glib-mkenums.rb, line 184
    def create_c
      ret = "\n/* Generated by glib-mkenums.rb ($Id$) */ \n\n"
      ret << %Q[#include "#{@target_filename}.h"\n]
      @include_files.each do |file|
        ret << "#include <#{file}>\n"
      end
      ret << "\n"
      ret << create_enums(:create_c)
      ret << "\n\n/* Generated data ends here */\n\n"
      ret
    end

create_h() click to toggle source

Create a C header as a String.

    # File lib/glib-mkenums.rb, line 197
    def create_h
      header = "#{@target_filename}.h"
      const = "__#{File.basename(header).upcase.gsub(/-|\./, '_')}__"

      ret = "\n/* Generated by glib-mkenums.rb ($Id$) */ \n\n"
      ret << "#ifndef #{const}\n"
      ret << "#define #{const}\n\n"
      ret << "#include <glib-object.h>\n\n"
      ret << "G_BEGIN_DECLS"
      ret << create_enums(:create_h)
      ret << "\n\nG_END_DECLS\n\n"
      ret << "#endif /* #{const} */\n"
      ret << "\n/* Generated data ends here */\n\n"
      ret
    end