This module provides an implementation for enumerate data type.
The enumerate factory EnumFactory() builds a enumerate from a list of names and assigns to these constants a value from 0 to N-1, where N is the number of constants. For example:
enum = EnumFactory('Enum1', ('cst1', 'cst2'))
will build a enumerate with cst1 set to 0 and cst2 set to 1.
We can retrieve a constant’s value using an integer context:
int(enum.cst1)
and the constant’s name using:
str(enum.cst1)
We can test if two constants are equal using:
enum1.cst == enum2.cst
or with an object that implements the int protocol:
enum1.cst == obj
# is equivalent to
int(enum1.cst) == int(obj)
The number of constants could be retrieved with:
len(enum)
The enumerate factory :func:`ExplicitEnumFactory` is a variant that permits to specify the constant`s values::
enum2 = ExplicitEnumFactory('Enum2', {'cst1':1, 'cst2':3})
We can test if a value is in the enumerate using:
constant_value in enum2
Bases: object
Define an Enum Constant
Return an EnumMetaClass instance, where enum_name is the class name and enum_tuple is an iterable of constant’s names.
Bases: PyOpenGLng.Tools.EnumFactory.ReadOnlyMetaClass
This metaclass implements the len() protocol.
Return an ExplicitEnumMetaClass instance, where enum_name is the class name and enum_dict is a dict of constant’s names and their values.
Bases: PyOpenGLng.Tools.EnumFactory.ReadOnlyMetaClass
This metaclass implements the in operator.