Class: VirtualBox::COM::AbstractEnum

Inherits:
Object
  • Object
show all
Extended by:
Enumerable
Defined in:
lib/virtualbox/com/abstract_enum.rb

Overview

Represents a C enum type. Provides functionality to easily convert an int value to its proper symbol within the enum.

Direct Known Subclasses

Interface::Version_4_0_X::AccessMode, Interface::Version_4_0_X::AudioControllerType, Interface::Version_4_0_X::AudioDriverType, Interface::Version_4_0_X::AuthType, Interface::Version_4_0_X::BIOSBootMenuMode, Interface::Version_4_0_X::BandwidthGroupType, Interface::Version_4_0_X::ChipsetType, Interface::Version_4_0_X::CleanupMode, Interface::Version_4_0_X::ClipboardMode, Interface::Version_4_0_X::CpuPropertyType, Interface::Version_4_0_X::DataType, Interface::Version_4_0_X::DeviceType, Interface::Version_4_0_X::FaultToleranceState, Interface::Version_4_0_X::FirmwareType, Interface::Version_4_0_X::HWVirtExPropertyType, Interface::Version_4_0_X::HostNetworkInterfaceMediumType, Interface::Version_4_0_X::HostNetworkInterfaceStatus, Interface::Version_4_0_X::HostNetworkInterfaceType, Interface::Version_4_0_X::KeyboardHidType, Interface::Version_4_0_X::LockType, Interface::Version_4_0_X::MachineState, Interface::Version_4_0_X::MediumState, Interface::Version_4_0_X::MediumType, Interface::Version_4_0_X::MediumVariant, Interface::Version_4_0_X::NATAliasMode, Interface::Version_4_0_X::NATProtocol, Interface::Version_4_0_X::NetworkAdapterType, Interface::Version_4_0_X::NetworkAttachmentType, Interface::Version_4_0_X::PointingHidType, Interface::Version_4_0_X::PortMode, Interface::Version_4_0_X::SessionState, Interface::Version_4_0_X::SessionType, Interface::Version_4_0_X::StorageBus, Interface::Version_4_0_X::StorageControllerType, Interface::Version_4_0_X::USBDeviceFilterAction, Interface::Version_4_0_X::USBDeviceState, Interface::Version_4_0_X::VirtualSystemDescriptionType, Interface::Version_4_0_X::VirtualSystemDescriptionValueType, Interface::Version_4_1_X::AccessMode, Interface::Version_4_1_X::AdditionsFacilityClass, Interface::Version_4_1_X::AdditionsFacilityStatus, Interface::Version_4_1_X::AdditionsFacilityType, Interface::Version_4_1_X::AdditionsRunLevelType, Interface::Version_4_1_X::AudioControllerType, Interface::Version_4_1_X::AudioDriverType, Interface::Version_4_1_X::AuthType, Interface::Version_4_1_X::BIOSBootMenuMode, Interface::Version_4_1_X::BandwidthGroupType, Interface::Version_4_1_X::ChipsetType, Interface::Version_4_1_X::CleanupMode, Interface::Version_4_1_X::ClipboardMode, Interface::Version_4_1_X::CloneMode, Interface::Version_4_1_X::CpuPropertyType, Interface::Version_4_1_X::DataType, Interface::Version_4_1_X::DeviceType, Interface::Version_4_1_X::DirectoryCreateFlag, Interface::Version_4_1_X::DirectoryOpenFlag, Interface::Version_4_1_X::ExecuteProcessFlag, Interface::Version_4_1_X::ExecuteProcessStatus, Interface::Version_4_1_X::FaultToleranceState, Interface::Version_4_1_X::FirmwareType, Interface::Version_4_1_X::GuestDirEntryType, Interface::Version_4_1_X::HWVirtExPropertyType, Interface::Version_4_1_X::HostNetworkInterfaceMediumType, Interface::Version_4_1_X::HostNetworkInterfaceStatus, Interface::Version_4_1_X::HostNetworkInterfaceType, Interface::Version_4_1_X::ImportOptions, Interface::Version_4_1_X::KeyboardHidType, Interface::Version_4_1_X::LockType, Interface::Version_4_1_X::MachineState, Interface::Version_4_1_X::MediumState, Interface::Version_4_1_X::MediumType, Interface::Version_4_1_X::MediumVariant, Interface::Version_4_1_X::NATAliasMode, Interface::Version_4_1_X::NATProtocol, Interface::Version_4_1_X::NetworkAdapterPromiscModePolicty, Interface::Version_4_1_X::NetworkAdapterType, Interface::Version_4_1_X::NetworkAttachmentType, Interface::Version_4_1_X::PointingHidType, Interface::Version_4_1_X::PortMode, Interface::Version_4_1_X::ProcessOutputFlag, Interface::Version_4_1_X::SessionState, Interface::Version_4_1_X::SessionType, Interface::Version_4_1_X::SettingsVersion, Interface::Version_4_1_X::StorageBus, Interface::Version_4_1_X::StorageControllerType, Interface::Version_4_1_X::USBDeviceFilterAction, Interface::Version_4_1_X::USBDeviceState, Interface::Version_4_1_X::VirtualSystemDescriptionType, Interface::Version_4_1_X::VirtualSystemDescriptionValueType

Class Method Summary collapse

Class Method Details

.[](index) ⇒ Object

Returns the symbol associatd with the given key



35
36
37
# File 'lib/virtualbox/com/abstract_enum.rb', line 35

def [](index)
  @reverse_map[index]
end

.eachObject

Iterate over the enum, yielding each item to a block.



45
46
47
48
49
# File 'lib/virtualbox/com/abstract_enum.rb', line 45

def each
  @map.each do |key, value|
    yield key
  end
end

.index(key) ⇒ Object

Returns the index associated with a value



40
41
42
# File 'lib/virtualbox/com/abstract_enum.rb', line 40

def index(key)
  @map[key]
end

.map(value = nil) ⇒ Object

Defines the mapping of int => symbol for the given Enum. The parameter to this can be an Array or Hash or anything which can be indexed with ‘[]` and an integer and returns a value of some sort. If value is left nil, it will return the current mapping



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/virtualbox/com/abstract_enum.rb', line 13

def map(value = nil)
  if value
    # Convert the array to a hash of equal structure
    if value.is_a?(Array)
      result = {}
      value.each_index do |i|
        result[value[i]] = i
      end

      value = result
    end

    # Store both the map and the reverse map since both lookups
    # are frequently used.
    @map = value
    @reverse_map = @map.invert
  end

  @map
end

.reset!Object

Provided mostly for testing purposes only, but resets the mapping to nil.



53
54
55
# File 'lib/virtualbox/com/abstract_enum.rb', line 53

def reset!
  @map = nil
end