/** * testpipes.cpp * Implemented by Blueprint Technologies, Inc. */ #include "pipesandfilters.h" #include void main( void ) { /** * Instantiate our pattern blueprint classes. */ DataSink* sink = new DataSink(); DataSource* source = new DataSource(); Pipe* pipe = new Pipe(); /** * Configure them. */ source -> setOutput( pipe ); pipe -> setObserver( sink ); sink -> setInput( pipe ); /** * Plug a couple of packets into the source, and they * will migrate across to the sink. */ Packet packet1, packet2; source -> add( packet1 ); source -> add( packet2 ); /** * Print out the number of packets in the sink. */ cout << "Sink: " << sink -> size() << endl; /** * Add a filter with a source and sink. */ DataSink* filterSink = new DataSink(); DataSource* filterSource = new DataSource(); Filter* filter = new Filter(); Pipe* pipe2 = new Pipe(); /** * Reconfigure all the objects for the pipeline. * Our object graph should look like this: * source -> pipe -> filterSink -> filter -> filterSource -> pipe2 -> sink * * NOTE: filterSink and filterSource and encapsulated inside filter. */ pipe -> setObserver( filterSink ); filterSink -> setInput( pipe ); filterSink -> setObserver( filter ); filter -> setDataSink( filterSink ); filter -> setDataSource( filterSource ); filterSource -> setOutput( pipe2 ); pipe2 -> setObserver( sink ); sink -> setInput( pipe2 ); /** * Add two more packets. */ source -> add( packet1 ); source -> add( packet2 ); /** * Print out the number of packets in the sink. */ cout << "Sink: " << sink -> size() << endl; };