Back to index

salome-kernel  6.5.0
Public Member Functions | Private Attributes
KERNEL_PY.kernel.enumerate.Enumerate Class Reference

List of all members.

Public Member Functions

def __init__
def contains
def isValid
def listkeys
def listvalues
def keyOf

Private Attributes

 _dict_keynumbers

Detailed Description

This class emulates a C-like enum for python. It is initialized with a list
of strings to be used as the enum symbolic keys. The enum values are automatically
generated as sequencing integer starting at the specified offset value.

Definition at line 24 of file enumerate.py.


Constructor & Destructor Documentation

def KERNEL_PY.kernel.enumerate.Enumerate.__init__ (   self,
  keys,
  offset = 0 
)
Canonical constructor
@keys a list of string to be used as the enum symbolic keys. The enum values
are automatically generated as a sequence of integers starting at the specified
offset value.

Definition at line 30 of file enumerate.py.

00030 
00031     def __init__(self, keys, offset=0):
00032         """
00033         Canonical constructor
00034         @keys a list of string to be used as the enum symbolic keys. The enum values
00035         are automatically generated as a sequence of integers starting at the specified
00036         offset value.
00037         """
00038         self._dict_keynumbers = {}
00039         for number, key in enumerate(keys):
00040             value = offset + number
00041             setattr(self, key, value)
00042             self._dict_keynumbers[key] = value


Member Function Documentation

Return true if this enumerate contains the specified key string
@key a key string to test

Definition at line 43 of file enumerate.py.

00043 
00044     def contains(self, key):
00045         """
00046         Return true if this enumerate contains the specified key string
00047         @key a key string to test
00048         """
00049         return (key in self._dict_keynumbers.keys())

def KERNEL_PY.kernel.enumerate.Enumerate.isValid (   self,
  value 
)
Returns true if the specified integer value is defined as an identifier
in this enumarate.
@value a value to test

Definition at line 50 of file enumerate.py.

00050 
00051     def isValid(self, value):
00052         """
00053         Returns true if the specified integer value is defined as an identifier
00054         in this enumarate.
00055         @value a value to test
00056         """
00057         return (value in self._dict_keynumbers.values())

Here is the caller graph for this function:

def KERNEL_PY.kernel.enumerate.Enumerate.keyOf (   self,
  value 
)
Returns the symbolic key string associated to the specified identifier
value.
@param value : an integer value whose associated key string is requested.

Definition at line 74 of file enumerate.py.

00074 
00075     def keyOf(self, value):
00076         """
00077         Returns the symbolic key string associated to the specified identifier
00078         value.
00079         @param value : an integer value whose associated key string is requested.
00080         """
00081         if not self.isValid(value):
00082             return None
00083         # _MEM_ We assume here that the keys and associated values are in the
00084         # same order in their list.
00085         return self._dict_keynumbers.keys()[self._dict_keynumbers.values().index(value)]
00086 
00087         # If not, weshould use a longer implementation such that:
00088         #for key in self._dict_keynumbers.keys():
00089         #    if self._dict_keynumbers[key] == value:
00090         #        return key
00091 
00092 #
00093 # ==============================================================================
00094 # Basic use cases and unit test functions
00095 # ==============================================================================
00096 #

Here is the call graph for this function:

Returns the list of keys in this enumerate.

Definition at line 58 of file enumerate.py.

00058 
00059     def listkeys(self):
00060         """
00061         Returns the list of keys in this enumerate.
00062         """
00063         list = self._dict_keynumbers.keys()
00064         list.sort()
00065         return list

Returns the list of values specified to initiate this enumerate.

Definition at line 66 of file enumerate.py.

00066 
00067     def listvalues(self):
00068         """
00069         Returns the list of values specified to initiate this enumerate.
00070         """
00071         list = self._dict_keynumbers.values()
00072         list.sort()
00073         return list


Member Data Documentation

Definition at line 37 of file enumerate.py.


The documentation for this class was generated from the following file: