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: object

Define an Enum Constant

PySpice.Tools.EnumFactory.EnumFactory(enum_name, enum_tuple)[source]

Return an EnumMetaClass instance, 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.ReadOnlyMetaClass

This meta class implements the len() protocol.

PySpice.Tools.EnumFactory.ExplicitEnumFactory(enum_name, enum_dict)[source]

Return an ExplicitEnumMetaClass instance, 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.ReadOnlyMetaClass

This meta class implements the operator in.

class PySpice.Tools.EnumFactory.ReadOnlyMetaClass[source]

Bases: type

This meta class implements a class where attributes are read only.