actorlib/structuring/Cast: support inversion

This commit is contained in:
Sebastien Bourdeauducq 2013-03-25 15:54:09 +01:00
parent c4c4765a4e
commit 77a0f0a3bb
1 changed files with 7 additions and 1 deletions

View File

@ -8,14 +8,20 @@ def _rawbits_layout(l):
return l return l
class Cast(CombinatorialActor): class Cast(CombinatorialActor):
def __init__(self, layout_from, layout_to): def __init__(self, layout_from, layout_to, reverse_from=False, reverse_to=False):
self.reverse_from = reverse_from
self.reverse_to = reverse_to
CombinatorialActor.__init__(self, CombinatorialActor.__init__(self,
("sink", Sink, _rawbits_layout(layout_from)), ("sink", Sink, _rawbits_layout(layout_from)),
("source", Source, _rawbits_layout(layout_to))) ("source", Source, _rawbits_layout(layout_to)))
def get_process_fragment(self): def get_process_fragment(self):
sigs_from = self.token("sink").flatten() sigs_from = self.token("sink").flatten()
if self.reverse_from:
sigs_from = list(reversed(sigs_from))
sigs_to = self.token("source").flatten() sigs_to = self.token("source").flatten()
if self.reverse_to:
sigs_to = list(reversed(sigs_to))
if sum(len(s) for s in sigs_from) != sum(len(s) for s in sigs_to): if sum(len(s) for s in sigs_from) != sum(len(s) for s in sigs_to):
raise TypeError raise TypeError
return Fragment([ return Fragment([