Added Context abstract base class
This commit is contained in:
parent
249a07894a
commit
844586960a
1 changed files with 59 additions and 0 deletions
59
core/context/base.py
Normal file
59
core/context/base.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
from abc import ABC, abstractmethod
|
||||
from state.base import State
|
||||
from core.element import Element, String
|
||||
|
||||
|
||||
class Context(ABC):
|
||||
def __init__(self, state: State, model: Element, metamodel: Element):
|
||||
self.state = state
|
||||
self.model = model
|
||||
self.metamodel = metamodel
|
||||
|
||||
@abstractmethod
|
||||
def __enter__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def __exit__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def instantiate(self, type_name: String, instance_name: String):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def instantiate_value(self, type_name: String, instance_name: String, value: Element):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def instantiate_link(self, type_name: String, name: String, source: String, target: String):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_element(self, name: String):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def verify(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def list_elements(self):
|
||||
pass
|
||||
|
||||
def list_types(self):
|
||||
# can be implemented here since we assume that metamodel
|
||||
# is always in graph fo, i.e. in the MV-state graph.
|
||||
unsorted = []
|
||||
model_root = self.state.read_dict(self.metamodel.id, "Model")
|
||||
for elem_edge in self.state.read_outgoing(model_root):
|
||||
# get element name
|
||||
label_edge, = self.state.read_outgoing(elem_edge)
|
||||
_, label_node = self.state.read_edge(label_edge)
|
||||
label = self.state.read_value(label_node)
|
||||
# find element type
|
||||
elem_type_node = self.state.read_dict(label_node, "Type")
|
||||
elem_type = self.state.read_value(elem_type_node)
|
||||
unsorted.append(f"{label} : {elem_type if elem_type is not None else '_'}")
|
||||
for i in sorted(unsorted):
|
||||
print(i)
|
||||
Loading…
Add table
Add a link
Reference in a new issue