Class: VirtualBox::COM::IID

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

Defined Under Namespace

Classes: FFIStruct

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ IID

Returns a new instance of IID.



12
13
14
15
16
17
18
# File 'lib/virtualbox/com/xpcomc-ffi/iid.rb', line 12

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

Instance Method Details

#to_aObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/virtualbox/com/xpcomc-ffi/iid.rb', line 33

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



48
49
50
51
52
53
54
55
56
57
# File 'lib/virtualbox/com/xpcomc-ffi/iid.rb', line 48

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



20
21
22
# File 'lib/virtualbox/com/xpcomc-ffi/iid.rb', line 20

def to_i
    @i
end

#to_sObject



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

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