aboutsummaryrefslogtreecommitdiff
path: root/src/philo/event.py
blob: ddcbe597dfee3d07ef02cd5bb2bd153c805b57cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# ############################################################################ #
#                                                                              #
#                                                         :::      ::::::::    #
#    event.py                                           :+:      :+:    :+:    #
#                                                     +:+ +:+         +:+      #
#    By: cacharle <me@cacharle.xyz>                 +#+  +:+       +#+         #
#                                                 +#+#+#+#+#+   +#+            #
#    Created: 2020/10/01 10:51:13 by cacharle          #+#    #+#              #
#    Updated: 2020/10/01 11:21:00 by cacharle         ###   ########.fr        #
#                                                                              #
# ############################################################################ #

import enum

class Event(enum.Enum):
    FORK  = 1
    EAT   = 2
    SLEEP = 3
    THINK = 4
    DIE   = 5
    NONE  = 6

    @staticmethod
    def from_string(representation: str) -> "Event":
        return {
            "has taken fork": Event.FORK,
            "is thinking":    Event.THINK,
            "is eating":      Event.EAT,
            "is sleeping":    Event.SLEEP,
            "died":           Event.DIE,
        }[representation]

    @staticmethod
    def to_string(event: "Event") -> str:
        return {
            Event.FORK:  "has taken fork",
            Event.THINK: "is thinking",
            Event.EAT:   "is eating",
            Event.SLEEP: "is sleeping",
            Event.DIE:   "died"
        }[event]