3 def enum(*sequential, **named):
4 """ simulation of C=style enum
5 credit: Alec Thomas, http://stackoverflow.com/questions/36932/how-can-i-represent-an-enum-in-python
7 enums = dict(zip(sequential, range(len(sequential))), **named)
9 reverse = dict((value, key) for key, value in enums.items())
10 enums['reverse_mapping'] = reverse
11 return type('Enum', (), enums)
13 # some commonly required enums
14 # C-style pseudo-enum representing the directions a segment might run
15 directions = enum('N', 'NE', 'E', 'SE', 'S' , 'SW', 'W' , 'NW')
16 positions = enum('NONE', 'START', 'MID', 'END')
18 # Common Integrated Circuit signal names
19 s = ['NC', 'GND', 'Vcc', 'Vdd']
20 # logic gate signal names (covers multi-gate components up to quad-gate)
21 for l in ('A', 'B', 'Y'):
23 s.append("%s%s" % (n, l))
24 signals = enum(tuple(s))
26 # populate dictionary with common logic gate types
27 gates = enum('AND', 'OR', 'XOR', 'NOT', 'NAND', 'NOR')