CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Private Attributes
Enumerate.Enumerate Class Reference

Note: Please do not use or modify any data or functions with a leading underscore. More...

Inheritance diagram for Enumerate.Enumerate:

Public Member Functions

def __call__
 
def __init__
 
def __setattr__
 
def isValidKey
 
def isValidValue
 
def keys
 
def valueToKey
 

Private Attributes

 _keys
 
 _valueDict
 

Detailed Description

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.

Constructor & Destructor Documentation

def Enumerate.Enumerate.__init__ (   self,
  names,
  prefix = '',
  asInt = False,
  intOffset = 0 
)

Definition at line 13 of file Enumerate.py.

13 
14  def __init__(self, names, prefix = '', asInt = False, intOffset = 0):
15  biggest = smallest = ""
16  self._keys = []
17  self._valueDict = {}
18  for count, name in enumerate (names.split()) :
19  # make sure we don't already have this key
20  if self.isValidKey (name):
21  raise RuntimeError("You can not duplicate Enum Names '%s'" % name)
22  # set the value using the base class
23  key = "%s_%s" % (prefix, name)
24  if asInt:
25  key = count + intOffset
26  object.__setattr__ (self, name, key)
27  self._valueDict[key] = name
28  self._keys.append (name)
29 

Member Function Documentation

def Enumerate.Enumerate.__call__ (   self,
  key 
)

Definition at line 62 of file Enumerate.py.

62 
63  def __call__ (self, key):
64  return self.__dict__.get (key, None)
65 
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 52 of file Enumerate.py.

52 
53  def __setattr__ (self, name, value):
54  """Lets me set internal values, but throws an error if any of
55  the enum values are changed"""
56  if not name.startswith ("_"):
57  # Once it's set, you can't change the values
58  raise RuntimeError("You can not modify Enum values.")
59  else:
60  object.__setattr__ (self, name, value)
61 
def Enumerate.Enumerate.isValidKey (   self,
  key 
)
Returns true if this value is a valid enum key

Definition at line 35 of file Enumerate.py.

35 
36  def isValidKey (self, key):
37  """ Returns true if this value is a valid enum key"""
38  return key in self.__dict__
39 
def Enumerate.Enumerate.isValidValue (   self,
  value 
)
Returns true if this value is a valid enum value

Definition at line 30 of file Enumerate.py.

References Enumerate.Enumerate._valueDict.

30 
31  def isValidValue (self, value):
32  """ Returns true if this value is a valid enum value"""
33  return value in self._valueDict
34 
def Enumerate.Enumerate.keys (   self)
Returns copy of valid keys 

Definition at line 45 of file Enumerate.py.

References Enumerate.Enumerate._keys.

Referenced by psClasses.queueList.__init__(), psClasses.queueList.smallestQueue(), and psClasses.queueList.thinerQueue().

45 
46  def keys (self):
47  """ Returns copy of valid keys """
48  # since this is a list, return a copy of it instead of the
49  # list itself
50  return self._keys [:]
51 
def Enumerate.Enumerate.valueToKey (   self,
  value 
)
Returns the key (if it exists) for a given enum value

Definition at line 40 of file Enumerate.py.

40 
41  def valueToKey (self, value):
42  """ Returns the key (if it exists) for a given enum value"""
43  return self._valueDict.get (value, None)
44 

Member Data Documentation

Enumerate.Enumerate._keys
private

Definition at line 15 of file Enumerate.py.

Referenced by Enumerate.Enumerate.keys().

Enumerate.Enumerate._valueDict
private

Definition at line 16 of file Enumerate.py.

Referenced by Enumerate.Enumerate.isValidValue().