Class: VirtualBox::COM::IID

Inherits:
Object
  • Object
show all
Defined in:
lib/virtualbox/com/iid.rb,
lib/virtualbox/com/xpcomc-ffi.rb

Defined Under Namespace

Classes: FFIStruct

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ IID

Returns a new instance of IID.



5
6
7
8
9
10
11
# File 'lib/virtualbox/com/iid.rb', line 5

def initialize(obj)
    @i = case obj
         when String
             str = obj.gsub('-', '').hex
         else raise "unsupported object type"
         end
end

Instance Method Details

#to_aObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/virtualbox/com/iid.rb', line 26

def to_a
    @ary ||= [((@i & 0xffffffff000000000000000000000000) >> 96),
              ((@i & 0x00000000ffff00000000000000000000) >> 80),
              ((@i & 0x000000000000ffff0000000000000000) >> 64),
              ((@i & 0x0000000000000000ff00000000000000) >> 56),
              ((@i & 0x000000000000000000ff000000000000) >> 48),
              ((@i & 0x00000000000000000000ff0000000000) >> 40),
              ((@i & 0x0000000000000000000000ff00000000) >> 32),
              ((@i & 0x000000000000000000000000ff000000) >> 24),
              ((@i & 0x00000000000000000000000000ff0000) >> 16),
              ((@i & 0x0000000000000000000000000000ff00) >>  8),
              ((@i & 0x000000000000000000000000000000ff) >>  0)]
             .freeze
end

#to_ffiObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/virtualbox/com/xpcomc-ffi.rb', line 21

def to_ffi
    @ffi ||= begin
                 data = FFIStruct.new
                 data[:m0] = to_a[0]
                 data[:m1] = to_a[1]
                 data[:m2] = to_a[2]
                 to_a[3..-1].each_index{|i| data[:m3][i] = to_a[3..-1][i] }
                 data.freeze
             end
end

#to_iObject



13
14
15
# File 'lib/virtualbox/com/iid.rb', line 13

def to_i
    @i
end

#to_sObject



17
18
19
20
21
22
23
24
# File 'lib/virtualbox/com/iid.rb', line 17

def to_s
    @str ||= (((@i & 0xffffffff000000000000000000000000)>> 96).to_s(16)+'-'+
              ((@i & 0x00000000ffff00000000000000000000)>> 80).to_s(16)+'-'+
              ((@i & 0x000000000000ffff0000000000000000)>> 64).to_s(16)+'-'+
              ((@i & 0x0000000000000000ffff000000000000)>> 48).to_s(16)+'-'+
              ((@i & 0x00000000000000000000ffffffffffff)     ).to_s(16))
             .freeze
end