/ pdkmaster / dispatch / edge.py
edge.py
 1  # SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-or-later OR CERN-OHL-S-2.0+ OR Apache-2.0
 2  from ..technology import edge as _edg
 3  
 4  
 5  class EdgeDispatcher:
 6      """Dispatch to class method based on type of `_Edge` subclasses.
 7  
 8      This dispatcher follows the common way of working in the `dispatch` module.
 9      """
10      def __call__(self, edge: _edg.EdgeT, *args, **kwargs):
11          classname = edge.__class__.__name__.split(".")[-1]
12          return getattr(self, classname, self._pd_unhandled)(edge, *args, **kwargs)
13  
14      def _pd_unhandled(self, edge, *args, **kwargs):
15          raise RuntimeError(
16              "Internal error: unhandled dispatcher for object of type "
17              f"{edge.__class__.__name__}"
18          )
19  
20      def _Edge(self, edge: _edg.EdgeT, *args, **kwargs):
21          raise NotImplementedError(
22              f"No dispatcher implemented for object of type {edge.__class__.__name__}"
23          )
24  
25      def _DualEdgeOperation(self, op: _edg._DualEdgeOperation, *args, **kwargs):
26          return self._Edge(op, *args, **kwargs)
27  
28      def MaskEdge(self, edge: _edg.MaskEdge, *args, **kwargs):
29          return self._Edge(edge, *args, **kwargs)
30  
31      def Join(self, join: _edg.Join, *args, **kwargs):
32          return self._Edge(join, *args, **kwargs)
33  
34      def Intersect(self, intersect: _edg.Intersect, *args, **kwargs):
35          return self._Edge(intersect, *args, **kwargs)