Skip to content

Commit

Permalink
Correction to the behavior of Insert in pull mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainhalle committed Nov 10, 2023
1 parent 7eedba4 commit 364501b
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions Core/src/ca/uqac/lif/cep/tmf/Insert.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,61 @@ public Insert duplicate(boolean with_state)
{
return new Insert(m_times, m_pad);
}

/**
* @since 0.11
*/
@Override
public Object getState()
{
return m_sentPad;
return m_sentPad;
}

public Pullable getPullableOutput(int index)
{
if (m_outputPullables[index] == null)
{
m_outputPullables[index] = new InsertPullable(index);
}
return m_outputPullables[index];
}

/**
* A {@link Pullable} object specific to the behavior of {@link Insert}.
* It overrides the default behavior of {@link SynchronousProcessor}'s
* pullable object, which first pulls an input event from each input pipe
* before calling {@code compute}. In the case of {@link Insert}, input
* pipes are not pulled if the pad has not been emitted yet.
*/
protected class InsertPullable extends OutputPullable
{
/**
* Creates a new instance of the pullable object.
* @param index The index of the output pipe this pullable is associated
* with
*/
public InsertPullable(int index)
{
super(index);
}

@Override
public boolean hasNext()
{
if (m_sentPad)
{
return super.hasNext();
}
for (int i = 0; i < m_times; i++)
{
for (int j = 0; j < m_pad.length; j++)
{
m_outputQueues[j].add(m_pad[j]);
}
m_sentPad = true;
}
return true;
}
}

@Override
Expand Down

0 comments on commit 364501b

Please sign in to comment.