Nektar++
Functions | Variables
CellMLToNektar.enum Namespace Reference

Functions

def Enum (*names)
 

Variables

def Days = Enum('Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su')
 
def Confirmation = Enum('No', 'Yes')
 
def answer = Confirmation.No
 
 __value
 assert names, "Empty enums are not supported" # <- Don't like empty enums? Uncomment! More...
 

Function Documentation

◆ Enum()

def CellMLToNektar.enum.Enum ( names)

Definition at line 8 of file enum.py.

8def Enum(*names):
9 ##assert names, "Empty enums are not supported" # <- Don't like empty enums? Uncomment!
10
11 class EnumClass(object):
12 __slots__ = names
13 def __iter__(self): return iter(constants)
14 def __len__(self): return len(constants)
15 def __getitem__(self, i): return constants[i]
16 def __repr__(self): return 'Enum' + str(names)
17 def __str__(self): return 'enum ' + str(constants)
18
19 class EnumValue(object):
20 __slots__ = ('__value')
21 def __init__(self, value): self.__value = value
22 Value = property(lambda self: self.__value)
23 EnumType = property(lambda self: EnumType)
24 def __hash__(self): return hash(self.__value)
25 def __cmp__(self, other):
26 # C fans might want to remove the following assertion
27 # to make all enums comparable by ordinal value {;))
28 assert self.EnumType is other.EnumType, "Only values from the same enum are comparable"
29 return cmp(self.__value, other.__value)
30 def __invert__(self): return constants[maximum - self.__value]
31 def __nonzero__(self): return bool(self.__value)
32 def __repr__(self): return str(names[self.__value])
33
34 maximum = len(names) - 1
35 constants = [None] * len(names)
36 for i, each in enumerate(names):
37 val = EnumValue(i)
38 setattr(EnumClass, each, val)
39 constants[i] = val
40 constants = tuple(constants)
41 EnumType = EnumClass()
42 return EnumType
43
44
def Enum(*names)
Definition: enum.py:8

Variable Documentation

◆ __value

CellMLToNektar.enum.__value
private

assert names, "Empty enums are not supported" # <- Don't like empty enums? Uncomment!

Definition at line 21 of file enum.py.

◆ answer

def CellMLToNektar.enum.answer = Confirmation.No

Definition at line 58 of file enum.py.

Referenced by Nektar::FieldUtils::OutputFileBase.WriteFile().

◆ Confirmation

def CellMLToNektar.enum.Confirmation = Enum('No', 'Yes')

Definition at line 57 of file enum.py.

◆ Days

def CellMLToNektar.enum.Days = Enum('Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su')

Definition at line 48 of file enum.py.