Concat, upon receiving the EXECUTE signal from the CAT, will concatenate the two strings that are currently on it's input ports, and write the result to it's output port.
class Concat : public ComponentBase {
public:
Concat();
protected:
RETVAL handleInput(int request);
private:
InputPort<ConcatParams> parameterPort;
InputPort<PortString> iPort1;
InputPort<PortString> iPort2;
OutputPort<PortString> oPort;
ConcatParams params;
};
class MakeConcat : public ComponentCreator {
public:
ComponentBase* create { return new Concat(); }
};
Concat::Concat() : parameterPort(&event,Request::CONFIG),
iPort1(&event,Request::EXECUTE),
iPort2(&event,Request::EXECUTE)
{
setReadme("Concat: When executed, outputs the concatenation of the inputs repeated the specified number of times");
setName("Concat");
parameterPort.setName("Concat Parameters");
parameterPort.setReadme("The number of times to repeat the concatenation.");
iPort[1].setName("Input String #1");
iPort[1].setReadme("The first string to be concatenated.");
iPort[2].setName("Input String #2");
iPort[2].setReadme("The second string to be concatenated.");
oPort.setName("Output String");
oPort.setReadme("The string from the input port");
addInputPort(parameterPort);
addInputPort(iPort1);
addInputPort(iPort2);
addOutputPort(iPort);
InputPort<ConcatParams>::addExemplar();
InputPort<PortString>::addExemplar();
}
RETVAL Concat::handleInput(int request)
{
if (request == Request::CONFIG) {
if (!parameterPort.dataReady()) {
cerr << "Nothing on the parameterPort!" << endl;
return RETVAL::ERROR;
}
concatParams.read(params);
return RETVAL::OK;
}
PortString s1,s2;
// normally, we might check to see if dataReady on the input ports, but
// in this case, it is OK if one is empty (it will we interpreted as the
// empty string
iPort1.read(s1);
iPort2.read(s2);
ostrstream t;
for (int i=0; i<params.times; i++)
t << s1 << s2;
t << '\0';
oPort->write((PortString)t.str());
executePort.add(outputPort.list[0]);
return RETVAL::OK;
}
Last updated: Tue Jan 26 16:38:26 1999