8 """Similar to C++'s 'enum', but with a few extra toys. Takes a
9 string with spaces in between the different 'enum' names (keys).
10 If 'asInt' is true, then values will be integers (useful for array
11 indicies). Once created, the enum values can not be changed."""
13 def __init__(self, names, prefix = '', asInt = False, intOffset = 0):
14 biggest = smallest =
""
17 for count, name
in enumerate (names.split()) :
20 raise RuntimeError(
"You can not duplicate Enum Names '%s'" % name)
22 key =
"%s_%s" % (prefix, name)
24 key = count + intOffset
25 object.__setattr__ (self, name, key)
27 self.
_keys.append (name)
31 """ Returns true if this value is a valid enum value"""
36 """ Returns true if this value is a valid enum key"""
37 return key
in self.__dict__
41 """ Returns the key (if it exists) for a given enum value"""
46 """ Returns copy of valid keys """
53 """Lets me set internal values, but throws an error if any of
54 the enum values are changed"""
55 if not name.startswith (
"_"):
57 raise RuntimeError(
"You can not modify Enum values.")
59 object.__setattr__ (self, name, value)
63 return self.__dict__.get (key,
None)