Class: Babeltrace2Gen::BTValueCLass::Map

Inherits:
Babeltrace2Gen::BTValueCLass show all
Includes:
Babeltrace2Gen::BTPrinter
Defined in:
lib/metababel/bt2_values_generator.rb

Constant Summary

Constants included from Babeltrace2Gen::BTPrinter

Babeltrace2Gen::BTPrinter::INDENT_INCREMENT

Instance Attribute Summary

Attributes inherited from Babeltrace2Gen::BTValueCLass

#cast_type

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Babeltrace2Gen::BTPrinter

context, #name_sanitized, pr, #scope

Constructor Details

#initialize(entries = []) ⇒ Map



66
67
68
# File 'lib/metababel/bt2_values_generator.rb', line 66

def initialize(entries = [])
  @entries = entries.collect { |m| BTValueCLass.from_h(**m) }
end

Class Method Details

.from_h(model) ⇒ Object



62
63
64
# File 'lib/metababel/bt2_values_generator.rb', line 62

def self.from_h(model)
  new(model[:entries])
end

Instance Method Details

#get(struct, map) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/metababel/bt2_values_generator.rb', line 70

def get(struct, map)
  @entries.map do |m|
    scope do
      pr "const bt_value *val = bt_value_map_borrow_entry_value_const(#{map}, \"#{m.name}\");"
      m.get("#{struct}->#{m.name}", 'val')
    end
  end
end

#get_struct_definition(_name) ⇒ Object



79
80
81
82
83
84
# File 'lib/metababel/bt2_values_generator.rb', line 79

def get_struct_definition(_name)
  @entries.map do |e|
    type = e.cast_type || e.class.instance_variable_get(:@bt_return_type)
    "  #{type} #{e.name};"
  end.join("\n")
end