06 Jun 2013, 15:59
Since Murl Engine Version 1.00.2194 it is possible to get a Map containing the key/value pairs for all Murl enums. The corresponding methods are:
The map makes it easy to iterate through the enum. The code above to iterate through the RawKey enum would change to:
Please note that this is the preferred way. Iterating through the map guarantees that only valid enum values are used even if the enum contains “holes”. Consider the following enum:
The previous version would iterate through all values from 1 to 99 while the new version only considers the two valid values.
GetItemsByValue() // Get a map with the enum name as value and the enumeration value as key.
GetItemsByName() // Get a map with the enum name as key and the enumeration value as value.
The map makes it easy to iterate through the enum. The code above to iterate through the RawKey enum would change to:
Logic::IDeviceHandler* deviceHandler = state->GetDeviceHandler();
const Murl::Map<UInt32, String>& mapRawKeyValues = GetRawKeyCodeEnum().GetItemsByValue();
for (UInt32 i=0, size = mapRawKeyValues.GetCount() ; i<size; i++)
{
UInt32 code = mapRawKeyValues.GetKey(i);
if ((deviceHandler->WasRawKeyPressed(static_cast<RawKeyCode>(code))))
{
Debug::Trace("Key pressed");
Debug::Trace("RawKeyCode is %d", i);
Debug::Trace("RawKeyName is %s", mapRawKeyValues.Get(code));
}
}
Please note that this is the preferred way. Iterating through the map guarantees that only valid enum values are used even if the enum contains “holes”. Consider the following enum:
enum Foo
{
a = 1,
b = 99,
MAX
};
The previous version would iterate through all values from 1 to 99 while the new version only considers the two valid values.