Class: CTypes::Importers::CastXML::Loader
- Inherits:
-
Object
- Object
- CTypes::Importers::CastXML::Loader
- Includes:
- Helpers
- Defined in:
- lib/ctypes/importers/castxml/loader.rb
Instance Attribute Summary collapse
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Instance Method Summary collapse
-
#initialize(io) ⇒ Loader
constructor
A new instance of Loader.
- #load ⇒ Object
- #load_into(namespace) ⇒ Object
Methods included from Helpers
#array, #bitfield, #bitmap, #enum, #string, #struct, #union
Constructor Details
#initialize(io) ⇒ Loader
Returns a new instance of Loader.
10 11 12 13 14 15 16 17 18 |
# File 'lib/ctypes/importers/castxml/loader.rb', line 10 def initialize(io) @doc = Nokogiri.parse(io) @xml = @doc.xpath("//castxml[1]")&.first or raise Error, "<castxml> node not found" @nodes = @xml.xpath("./*[@id]").each_with_object({}) { |n, o| o[n[:id]] = n } @ctypes = {} end |
Instance Attribute Details
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
19 20 21 |
# File 'lib/ctypes/importers/castxml/loader.rb', line 19 def xml @xml end |
Instance Method Details
#load ⇒ Object
21 22 23 24 |
# File 'lib/ctypes/importers/castxml/loader.rb', line 21 def load m = Module.new load_into(m) end |
#load_into(namespace) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ctypes/importers/castxml/loader.rb', line 26 def load_into(namespace) @xml.children.each do |node| next unless node.element? case node.name when "typedef", "struct", "union", "array", "enumeration" # skip builtin types next if node[:file] == "f0" name, type = ctype(node[:id]) next if name.empty? namespace.define_singleton_method(name) { type } end end namespace end |