next up previous
Next: ExampleXorElement Up: Case Study Previous: ExampleReader

ExampleWriter

The header file for the reader looks like this:

#include "ProcessWriter.h"

class BoolPort;

class ExampleWriter : public ProcessWriter
{
public:
   ExampleWriter( );
   virtual ~ExampleWriter( );
protected:
   virtual ProcStatus process( );
   virtual bool inputValid( const string& name, DataPort* in, const int idNum );
   virtual void writeOutput( ofstream& file, const FormatType type );
private:
// Inputs
   BoolPort* m_inputA;
   BoolPort* m_inputB;
   BoolPort* m_resultSimple;
   BoolPort* m_resultCompound;
// Other members
   bool m_firstWrite;
};
The writer has a few more methods than the reader. The four member ports are now inputs rather than outputs, so do not have to be created in the constructor - in fact the constructor and destructor are pretty much trivial. However, in order to be connected, the class has to override the inputValid method to check connection requests to each of its four inputs. This is actually the most complex method - it checks that any request contains the right type of port (a BoolPort in each case), then the the name (and optional number if needed) are correct, and if so, the relevant port member is set to point at the new input port.


Processing is actually done in two stages. There is the usual process step for a ProcessElement. For most writers, there is no further processing to be done, but it is possible that an intermediate processing step might also be a writer, so it is allowed to do processing and setting of output ports here. In this case, and as a general recommendation for writers, all that is done is to check that the inputs are valid. If not, an error will be generated by returning procFail. The other part of the processing is done in the method writeOutput - this is where the new data actually is written. In this case a simple truth table for the two gates is printed to the output file.


next up previous
Next: ExampleXorElement Up: Case Study Previous: ExampleReader
M.P.J.Landon 2003-05-15