Sha256: 5a60822d163afd162ffc553b70350c04494713c516c82866642ea35305b08f6a
Contents?: true
Size: 786 Bytes
Versions: 2
Compression:
Stored size: 786 Bytes
Contents
# bitmap functions. module Flags def flags(name, flags) def_field name def_get name, flags def_set name, flags end def def_field(name) module_eval("uint32 :#{name}") end def def_get(name, flags) str = %{ def get list = #{flags.inspect} list.each_with_object([]) do |(key, value), result| result << key if #{name} & value != 0 result end end } module_eval str end def def_set(name, flags) str = %{ def set(v) list = #{flags.inspect} v.each do |each| fail "Invalid state flag: \#{v}" unless list.keys.include?(each) end self.#{name} = v.empty? ? 0 : v.map { |each| list[each] }.inject(:|) end } module_eval str end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pio-0.9.0 | lib/pio/open_flow/flags.rb |
pio-0.8.2 | lib/pio/open_flow/flags.rb |