38 lines
1 KiB
Nim
38 lines
1 KiB
Nim
import ../../../types
|
|
import bitops
|
|
|
|
proc parseProduct*(cls: int): Product =
|
|
var tmp = cls
|
|
var res = 0
|
|
while tmp > 1:
|
|
tmp = tmp shr 1
|
|
res += 1
|
|
|
|
return Product(res)
|
|
|
|
proc parseProducts*(pCls: int): Products =
|
|
return Products(
|
|
nationalExp: pCls.testBit(0),
|
|
national: pCls.testBit(1),
|
|
regionalExp: pCls.testBit(2),
|
|
regional: pCls.testBit(3),
|
|
suburban: pCls.testBit(4),
|
|
bus: pCls.testBit(5),
|
|
ferry: pCls.testBit(6),
|
|
subway: pCls.testBit(7),
|
|
tram: pCls.testBit(8),
|
|
taxi: pCls.testBit(9),
|
|
)
|
|
|
|
proc formatProducts*(p: Products): int =
|
|
if p.nationalExp: result.setBit(0)
|
|
if p.national: result.setBit(1)
|
|
if p.regionalExp: result.setBit(2)
|
|
if p.regional: result.setBit(3)
|
|
if p.suburban: result.setBit(4)
|
|
if p.bus: result.setBit(5)
|
|
if p.ferry: result.setBit(6)
|
|
if p.subway: result.setBit(7)
|
|
if p.tram: result.setBit(8)
|
|
if p.taxi: result.setBit(9)
|