CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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, \
22  "You can not duplicate Enum Names '%s'" % name
23  # set the value using the base class
24  key = "%s_%s" % (prefix, name)
25  if asInt:
26  key = count + intOffset
27  object.__setattr__ (self, name, key)
28  self._valueDict[key] = name
29  self._keys.append (name)
30 

Member Function Documentation

def Enumerate.Enumerate.__call__ (   self,
  key 
)

Definition at line 63 of file Enumerate.py.

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

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

Definition at line 36 of file Enumerate.py.

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

Definition at line 31 of file Enumerate.py.

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

Definition at line 46 of file Enumerate.py.

References Enumerate.Enumerate._keys.

46 
47  def keys (self):
48  """ Returns copy of valid keys """
49  # since this is a list, return a copy of it instead of the
50  # list itself
51  return self._keys [:]
52 
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.

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

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.