Note: Please do not use or modify any data or functions with a leading underscore. More...
Public Member Functions | |
def | __call__ |
def | __init__ |
def | __setattr__ |
def | isValidKey |
def | isValidValue |
def | keys |
def | valueToKey |
Private Attributes | |
_keys | |
_valueDict |
Note: Please do not use or modify any data or functions with a leading underscore.
If you "mess" with the internal structure, the classes may not function as intended.
Similar to C++'s 'enum', but with a few extra toys. Takes a string with spaces in between the different 'enum' names (keys). If 'asInt' is true, then values will be integers (useful for array indicies). Once created, the enum values can not be changed.
Definition at line 7 of file Enumerate.py.
def Enumerate::Enumerate::__init__ | ( | self, | |
names, | |||
prefix = '' , |
|||
asInt = False , |
|||
intOffset = 0 |
|||
) |
Definition at line 13 of file Enumerate.py.
00014 : 00015 biggest = smallest = "" 00016 self._keys = [] 00017 self._valueDict = {} 00018 for count, name in enumerate (names.split()) : 00019 # make sure we don't already have this key 00020 if self.isValidKey (name): 00021 raise RuntimeError, \ 00022 "You can not duplicate Enum Names '%s'" % name 00023 # set the value using the base class 00024 key = "%s_%s" % (prefix, name) 00025 if asInt: 00026 key = count + intOffset 00027 object.__setattr__ (self, name, key) 00028 self._valueDict[key] = name 00029 self._keys.append (name) 00030
def Enumerate::Enumerate::__call__ | ( | self, | |
key | |||
) |
Definition at line 63 of file Enumerate.py.
def Enumerate::Enumerate::__setattr__ | ( | self, | |
name, | |||
value | |||
) |
Lets me set internal values, but throws an error if any of the enum values are changed
Definition at line 53 of file Enumerate.py.
00054 : 00055 """Lets me set internal values, but throws an error if any of 00056 the enum values are changed""" 00057 if not name.startswith ("_"): 00058 # Once it's set, you can't change the values 00059 raise RuntimeError, "You can not modify Enum values." 00060 else: 00061 object.__setattr__ (self, name, value) 00062
def Enumerate::Enumerate::isValidKey | ( | self, | |
key | |||
) |
Returns true if this value is a valid enum key
Definition at line 36 of file Enumerate.py.
def Enumerate::Enumerate::isValidValue | ( | self, | |
value | |||
) |
Returns true if this value is a valid enum value
Definition at line 31 of file Enumerate.py.
def Enumerate::Enumerate::keys | ( | self | ) |
Returns copy of valid keys
Definition at line 46 of file Enumerate.py.
def Enumerate::Enumerate::valueToKey | ( | self, | |
value | |||
) |
Returns the key (if it exists) for a given enum value
Definition at line 41 of file Enumerate.py.
Enumerate::Enumerate::_keys [private] |
Definition at line 13 of file Enumerate.py.
Enumerate::Enumerate::_valueDict [private] |
Definition at line 13 of file Enumerate.py.