"""Author: Changbeom Choi (@cbchoi)Copyright (c) 2014-2020 Handong Global UniversityCopyright (c) 2021-2024 Hanbat National UniversityLicense: MIT. The full license text is available at:https://github.com/eventsim/pyjevsim/blob/main/LICENSEThis module contains definitions for pyjevsim's const and type. """fromenumimportEnum# Define an infinite valueInfinite=float("inf")
[docs]classAttributeType(Enum):"""Enum for attribute types."""ASPECT=1RUNTIME=2UNKNOWN_TYPE=-1
[docs]@staticmethoddefresolve_type_from_str(name):"""Resolves an attribute type from a string. Args: name (str): The name of the attribute type Returns: AttributeType: The resolved attribute type """if"ASPECT"==name.upper():returnAttributeType.ASPECTelif"RUNTIME"==name.upper():returnAttributeType.RUNTIMEelse:returnAttributeType.UNKNOWN_TYPE
[docs]@staticmethoddefresolve_type_from_enum(enum):"""Resolves an attribute type to a string. Args: enum (AttributeType): The attribute type enum Returns: str: The name of the attribute type """ifenum==AttributeType.ASPECT:return"ASPECT"elifenum==AttributeType.RUNTIME:return"RUNTIME"else:return"UNKNOWN"
[docs]classSimulationMode(Enum):"""Enum for simulation modes."""SIMULATION_IDLE=(0# Simulation Engine is instantiated but simulation is not running)SIMULATION_RUNNING=1# Simulation Engine is instantiated, simulation is running SIMULATION_TERMINATED=(2# Simulation Engine is instantiated but simulation is terminated)SIMULATION_PAUSE=3# Simulation Engine is instantiated, simulation paused SIMULATION_UNKNOWN=-1# Simulation Engine went to abnormal state
[docs]classModelType(Enum):"""Enum for model types."""BEHAVIORAL=0#BehaviorModel type : DEVS Atomic ModelSTRUCTURAL=1#StructuralModel type : DEVS Coupled ModelUTILITY=2
[docs]classExecutionType(Enum):"""Enum for execution types."""R_TIME=0#Real timeV_TIME=1#Virtual time
[docs]classSingletonType(object):"""A decorator for making a class a singleton."""def__call__(self,cls,*args,**kwargs):"""Creates or returns the singleton instance of the class. Args: cls (type): The class to be instantiated *args: Variable length argument list **kwargs: Arbitrary keyword arguments Returns: object: The singleton instance of the class """try:returncls.__instanceexceptAttributeError:cls.__instance=super(SingletonType,cls).__call__(*args,**kwargs)returncls.__instance