Class: Rbind::GeneratorExtern

Inherits:
Object
  • Object
show all
Defined in:
lib/rbind/generator_extern.rb

Defined Under Namespace

Classes: Config

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ GeneratorExtern

Returns a new instance of GeneratorExtern.



20
21
22
# File 'lib/rbind/generator_extern.rb', line 20

def initialize(root)
    @root = root
end

Instance Attribute Details

#cpathObject

Returns the value of attribute cpath.



10
11
12
# File 'lib/rbind/generator_extern.rb', line 10

def cpath
  @cpath
end

#file_prefixObject

Returns the value of attribute file_prefix.



9
10
11
# File 'lib/rbind/generator_extern.rb', line 9

def file_prefix
  @file_prefix
end

#output_pathObject

Returns the value of attribute output_path.



7
8
9
# File 'lib/rbind/generator_extern.rb', line 7

def output_path
  @output_path
end

#ruby_module_nameObject

Returns the value of attribute ruby_module_name.



8
9
10
# File 'lib/rbind/generator_extern.rb', line 8

def ruby_module_name
  @ruby_module_name
end

Class Method Details

.normalize_operation_name(name) ⇒ Object



16
17
18
# File 'lib/rbind/generator_extern.rb', line 16

def self.normalize_operation_name(name)
    name.gsub('::','.').gsub(" ","")
end

.normalize_type_name(name) ⇒ Object



12
13
14
# File 'lib/rbind/generator_extern.rb', line 12

def self.normalize_type_name(name)
    name.gsub('::','.').gsub(" ","")
end

Instance Method Details

#generate(path = @output_path, ruby_module_name = @ruby_module_name, file_prefix = @file_prefix, cpath = @cpath) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rbind/generator_extern.rb', line 24

def generate(path = @output_path,ruby_module_name = @ruby_module_name,file_prefix = @file_prefix,cpath=@cpath)
    @output_path = path
    @ruby_module_name = ruby_module_name
    @file_prefix = file_prefix
    @cpath = File.expand_path(cpath)
    FileUtils.mkdir_p(path) if path && !File.directory?(path)
    file_extern = File.new(File.join(path,"extern.rbind"),"w")
    file_config = File.new(File.join(path,"config.rbind"),"w")

    #write all types so they get parsed first
    @root.each_type do |t|
        if t.is_a?(RClass) 
            file_extern.write "class #{GeneratorExtern.normalize_type_name(t.full_name)}\n"
        elsif t.is_a?(REnum)
            file_extern.write "enum #{GeneratorExtern.normalize_type_name(t.full_name)}\n"
        end
    end

    # write all consts
    @root.each_const do |c|
        file_extern.write "const #{GeneratorExtern.normalize_type_name(c.full_name)}\n"
    end

    #write all operations
    @root.each_type do |t|
        if t.is_a? RClass
            t.each_operation do |op|
                next if op.is_a? RCastOperation
                r = if op.return_type
                        GeneratorExtern.normalize_type_name(op.return_type.full_name)
                    end
                file_extern.write "#{GeneratorExtern.normalize_operation_name(op.full_name)} #{r}\n"
                op.parameters.each do |p|
                    file_extern.write "   #{GeneratorExtern.normalize_type_name(p.type.full_name)} #{p.name}"\
                                      "#{" #{p.default_value}" if p.default_value}#{" /O" unless p.const?}\n"
                end
            end
        end
    end

    file_extern.write("\n")
    file_config.write Config.new(ruby_module_name,file_prefix,@cpath).to_yaml
end