Class: Babeltrace2Gen::BTValueCLass::Map
- Inherits:
-
Babeltrace2Gen::BTValueCLass
- Object
- Babeltrace2Gen::BTValueCLass
- Babeltrace2Gen::BTValueCLass::Map
- 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
Class Method Summary collapse
Instance Method Summary collapse
- #get(struct, map) ⇒ Object
- #get_struct_definition(_name) ⇒ Object
-
#initialize(entries = []) ⇒ Map
constructor
A new instance of Map.
Methods included from Babeltrace2Gen::BTPrinter
context, #name_sanitized, pr, #scope
Constructor Details
#initialize(entries = []) ⇒ Map
Returns a new instance of 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 |