11.1.11.1. EnumFactory¶
This module provides an implementation for enumerate.
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'))
builds a enumerate with cst1 set to 0 and cst2 set to 1.
We can get a constant’s value using an integer context like:
int(enum.cst1)
and the constant’s name using:
repr(enum.cst1)
We can test constant equality using:
enum1.cst == enum2.cst
or with something that understand the int protocol:
enum1.cst == obj
# equivalent to
int(enum1.cst) == int(obj)
The number of constants could be retrieved with:
len(enum)
The enumerate factory ExplicitEnumFactory() is a variant that permits to specify the values of
the constants:
enum2 = ExplicitEnumFactory('Enum2', {'cst1':1, 'cst2':3})
We can test if a value is in the enumerate using:
constant_value in enum2
-
class
PySpice.Tools.EnumFactory.EnumConstant(name, value)[source]¶ Bases:
objectDefine an Enum Constant
-
PySpice.Tools.EnumFactory.EnumFactory(enum_name, enum_tuple)[source]¶ Return an
EnumMetaClassinstance, where enum_name is the class name and enum_tuple is an iterable of constant’s names.
-
class
PySpice.Tools.EnumFactory.EnumMetaClass[source]¶ Bases:
PySpice.Tools.EnumFactory.ReadOnlyMetaClassThis meta class implements the
len()protocol.
-
PySpice.Tools.EnumFactory.ExplicitEnumFactory(enum_name, enum_dict)[source]¶ Return an
ExplicitEnumMetaClassinstance, where enum_name is the class name and enum_dict is a dict of constant’s names and their values.
-
class
PySpice.Tools.EnumFactory.ExplicitEnumMetaClass[source]¶ Bases:
PySpice.Tools.EnumFactory.ReadOnlyMetaClassThis meta class implements the operator
in.