CMS 3D CMS Logo

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__ (self, key)
 
def __init__ (self, names, prefix='', asInt=False, intOffset=0)
 
def __setattr__ (self, name, value)
 
def isValidKey (self, key)
 
def isValidValue (self, value)
 
def keys (self)
 
def valueToKey (self, value)
 

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

Member Function Documentation

def Enumerate.Enumerate.__call__ (   self,
  key 
)

Definition at line 62 of file Enumerate.py.

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

Referenced by GenObject.GenObject.setValue().

52  def __setattr__ (self, name, value):
53  """Lets me set internal values, but throws an error if any of
54  the enum values are changed"""
55  if not name.startswith ("_"):
56  # Once it's set, you can't change the values
57  raise RuntimeError("You can not modify Enum values.")
58  else:
59  object.__setattr__ (self, name, value)
60 
61 
def __setattr__(self, name, value)
Definition: Enumerate.py:52
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  def isValidKey (self, key):
36  """ Returns true if this value is a valid enum key"""
37  return key in self.__dict__
38 
39 
def isValidKey(self, key)
Definition: Enumerate.py:35
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  def isValidValue (self, value):
31  """ Returns true if this value is a valid enum value"""
32  return value in self._valueDict
33 
34 
def isValidValue(self, value)
Definition: Enumerate.py:30
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  def keys (self):
46  """ Returns copy of valid keys """
47  # since this is a list, return a copy of it instead of the
48  # list itself
49  return self._keys [:]
50 
51 
def keys(self)
Definition: Enumerate.py:45
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  def valueToKey (self, value):
41  """ Returns the key (if it exists) for a given enum value"""
42  return self._valueDict.get (value, None)
43 
44 
def valueToKey(self, value)
Definition: Enumerate.py:40

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().