|
|
@@ -35,6 +35,12 @@ class BaseBlock:
|
|
|
#In wich CBD the baseblock is situated
|
|
|
self._parent = None
|
|
|
|
|
|
+ def containsOutput(self, output_name):
|
|
|
+ return output_name in self.__signals
|
|
|
+
|
|
|
+ def containsInput(self, input_name):
|
|
|
+ return input_name in self.__nameLinks
|
|
|
+
|
|
|
def getBlockName(self):
|
|
|
return self.__block_name
|
|
|
|
|
|
@@ -98,7 +104,6 @@ class BaseBlock:
|
|
|
"""
|
|
|
name_output = "OUT1" if name_output == None else name_output
|
|
|
if name_input != None:
|
|
|
- assert name_input in self.__nameLinks
|
|
|
self._linksIn[name_input] = InputLink(in_block, name_output)
|
|
|
else:
|
|
|
i = 1
|
|
|
@@ -259,7 +264,7 @@ class DelayBlock(BaseBlock):
|
|
|
(incoming_block, out_port_name) = self._linksIn["IN1"]
|
|
|
self.__values.append(incoming_block.getSignal(out_port_name)[curIteration-1])
|
|
|
self.appendToSignal(self.__values[curIteration-1].value)
|
|
|
-
|
|
|
+
|
|
|
class InputPortBlock(BaseBlock):
|
|
|
"""
|
|
|
The input port of a CBD
|
|
|
@@ -333,7 +338,7 @@ class NotBlock(BaseBlock):
|
|
|
|
|
|
def compute(self, curIteration):
|
|
|
result = 0 if self.getInputSignal(curIteration, "IN1").value else 1
|
|
|
- self.appendToSignal(result)
|
|
|
+ self.appendToSignal(result)
|
|
|
|
|
|
class OrBlock(BaseBlock):
|
|
|
"""
|
|
|
@@ -347,7 +352,7 @@ class OrBlock(BaseBlock):
|
|
|
result = 0
|
|
|
for i in range(1, self.__numberOfInputs+1):
|
|
|
result = result or self.getInputSignal(curIteration, "IN"+str(i)).value
|
|
|
- self.appendToSignal(result)
|
|
|
+ self.appendToSignal(result)
|
|
|
|
|
|
class AndBlock(BaseBlock):
|
|
|
"""
|
|
|
@@ -561,6 +566,13 @@ class CBD(BaseBlock):
|
|
|
from_block = self.getBlockByName(from_block)
|
|
|
if type(to_block) == str:
|
|
|
to_block = self.getBlockByName(to_block)
|
|
|
+ if input_port_name is not None:
|
|
|
+ # Validate existence of ports.
|
|
|
+ assert to_block.containsInput(input_port_name), "Inexistent input port %r on block %r" % (input_port_name, to_block.getBlockName())
|
|
|
+ assert input_port_name not in to_block.getLinksIn(), "Attempt to connect two signals on the same input port %r on block %r" % (input_port_name, to_block.getBlockName())
|
|
|
+ if output_port_name is not None:
|
|
|
+ # Validate existence of ports.
|
|
|
+ assert from_block.containsOutput(output_port_name), "Inexistent output port %r on block %r" % (output_port_name, from_block.getBlockName())
|
|
|
to_block.linkInput(from_block, input_port_name, output_port_name)
|
|
|
|
|
|
def __repr__(self):
|