Package mrv :: Module enum :: Class Enumeration
[hide private]
[frames] | no frames]

Class Enumeration

source code

object --+    
         |    
     tuple --+
             |
            Enumeration

This class represents an enumeration. You should not normally create multiple instances of the same enumeration, instead create one with however many references are convenient.

The enumeration is a tuple of all of the values in it. You can iterate through the values, perform 'in' tests, slicing, etc. It also includes functions to lookup specific values by name, or names by value.

You can specify your own element values, or use the create factory method to create default Elements. These elements are unique system wide, and are ordered based on the order of the elements in the enumeration. They also are _repr_'d by the name of the element, which is convenient for testing, debugging, and generation text output.


Note: pickling this class with Elements will fail as they contain cyclic references that it cannot deal with

To Do: implement proper pickle __getstate__ and __setstate__ that deal with that problem

Instance Methods [hide private]
 
__setattr__(self, name, value)
Do not allow to change this instance
source code
 
__getattr__(self, attr)
Prefer to return value from our value map
source code
 
__init__(self, names, values, **kwargs)
The arguments needed to construct this class are a list of element names (which must be unique strings), and element values (which can be any type of value).
source code
 
valueFromName(self, name)
Look up the enumeration value for a given element name.
source code
 
nameFromValue(self, value)
Look up the name of an enumeration element, given it's value.
source code
 
_nextOrPrevious(self, element, direction, wrap_around)
do-it method, see next and previous
source code
 
next(self, element, wrap_around=False)
Returns: element following after given element
source code
 
previous(self, element, wrap_around=False)
Returns: element coming before the given element
source code
 
__call__(self, name)
Look up the enumeration value for a given element name.
source code

Inherited from tuple: __add__, __contains__, __eq__, __ge__, __getattribute__, __getitem__, __getnewargs__, __getslice__, __gt__, __hash__, __iter__, __le__, __len__, __lt__, __mul__, __ne__, __repr__, __rmul__, __sizeof__, count, index

Inherited from object: __delattr__, __format__, __reduce__, __reduce_ex__, __str__, __subclasshook__

Static Methods [hide private]
a new object with type S, a subtype of T
__new__(self, names, values, **kwargs)
This method is needed to get the tuple parent class to do the Right Thing(tm).
source code
Class Variables [hide private]
  _slots_ = ('_nameMap', '_valueMap', '_supports_bitflags')
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__new__(self, names, values, **kwargs)
Static Method

source code 
This method is needed to get the tuple parent class to do the Right Thing(tm).
Returns: a new object with type S, a subtype of T
Overrides: object.__new__

__setattr__(self, name, value)

source code 
Do not allow to change this instance
Overrides: object.__setattr__

__init__(self, names, values, **kwargs)
(Constructor)

source code 

The arguments needed to construct this class are a list of element names (which must be unique strings), and element values (which can be any type of value). If you don't have special needs, then it's recommended that you use Element instances for the values.

This constructor is normally called through the create factory (which will create Elements for you), but that is not a requirement.

Overrides: object.__init__

valueFromName(self, name)

source code 
Look up the enumeration value for a given element name.
Raises:
  • ValueError

nameFromValue(self, value)

source code 

Look up the name of an enumeration element, given it's value.

If there are multiple elements with the same value, you will only get a single matching name back. Which name is undefined.

Raises:
  • ValueError - if value is not a part of our enumeration

_nextOrPrevious(self, element, direction, wrap_around)

source code 
do-it method, see next and previous
Parameters:
  • direction - -1 = previous, 1 = next

next(self, element, wrap_around=False)

source code 
Parameters:
  • element - element whose successor to return
  • wrap_around - if True, the first Element will be returned if there is no next element
Returns:
element following after given element
Raises:
  • ValueError - if wrap_around is False and there is no next element

previous(self, element, wrap_around=False)

source code 
Parameters:
  • element - element whose predecessor to return
  • wrap_around - see next
Returns:
element coming before the given element
Raises:
  • ValueError - if wrap_around is False and there is no previous element

__call__(self, name)
(Call operator)

source code 
Look up the enumeration value for a given element name.
Raises:
  • ValueError