CMS 3D CMS Logo

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

List of all members.

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.

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 


Member Function Documentation

def Enumerate::Enumerate::__call__ (   self,
  key 
)

Definition at line 63 of file Enumerate.py.

00064                             :
00065         return self.__dict__.get (key, None)
00066 
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.

00037                               :
00038         """ Returns true if this value is a valid enum key"""
00039         return self.__dict__.has_key (key)
00040 

def Enumerate::Enumerate::isValidValue (   self,
  value 
)
Returns true if this value is a valid enum value

Definition at line 31 of file Enumerate.py.

00032                                   :
00033         """ Returns true if this value is a valid enum value"""
00034         return self._valueDict.has_key (value)
00035 

def Enumerate::Enumerate::keys (   self)
Returns copy of valid keys 

Definition at line 46 of file Enumerate.py.

00047                    :
00048         """ Returns copy of valid keys """
00049         # since this is a list, return a copy of it instead of the
00050         # list itself
00051         return self._keys [:]
00052 

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.

00042                                 :
00043         """ Returns the key (if it exists) for a given enum value"""
00044         return self._valueDict.get (value, None)
00045 


Member Data Documentation

Definition at line 13 of file Enumerate.py.

Definition at line 13 of file Enumerate.py.