Listing 1
// An operation done via a command line class CommandLineOperation { public: void Execute() { inParameters.SubstituteParametersInCommandLine(commandLine); outParameters.SubstituteParametersInCommandLine(commandLine); statusParameters.SubstituteParametersInCommandLine(commandLine); inParameters.Execute(statusTextConsumer); system(commandLine.c_str()); statusParameters.Execute(statusTextConsumer); outParameters.Execute(statusTextConsumer); } protected: CommandLineOperation( string command_line, IDataProvider& data_provider, IStatusTextConsumer& status_consumer ) : dataProvider(data_provider), statusTextConsumer(status_consumer), commandLine(command_line), inParameters("provide data"), statusParameters("consume status"), outParameters("consume data") { } void SetPossibleInParameters() { inParameters.Add(new InEnvParameter(dataProvider)); inParameters.Add(new InBdyParameter(dataProvider)); inParameters.Add(new InXmlBdyParameter(dataProvider)); inParameters.Add(new InMsgParameter(dataProvider)); inParameters.Add(new InAttachDirParameter(dataProvider)); } void SetPossibleStatusParameters() { statusParameters.Add(new StatusParameter(statusTextConsumer)); } protected: IDataProvider& dataProvider; IStatusTextConsumer& statusTextConsumer; string commandLine; Parameters inParameters; Parameters statusParameters; Parameters outParameters; }; // An Update operation done via a command line class CommandLineUpdateOperation : public CommandLineOperation { public: CommandLineUpdateOperation( string command_line, IDataProvider& data_provider, IStatusTextConsumer& status_consumer ) : CommandLineOperation(command_line, data_provider, status_consumer) { SetPossibleInParameters(); SetPossibleStatusParameters(); } }; // A Generate operation done via a command line class CommandLineGenerateOperation : public CommandLineOperation { public: CommandLineGenerateOperation( string command_line, IDataProvider& data_provider, IDataConsumer& data_consumer, IStatusTextConsumer& status_consumer ) : CommandLineOperation(command_line, data_provider, status_consumer), dataConsumer(data_consumer) { SetPossibleInParameters(); SetPossibleOutParameters(); SetPossibleStatusParameters(); } private: void SetPossibleOutParameters() { outParameters.Add(new OutEnvParameter(dataConsumer)); outParameters.Add(new OutBdyParameter(dataConsumer)); outParameters.Add(new OutXmlBdyParameter(dataConsumer)); outParameters.Add(new OutMsgParameter(dataConsumer)); outParameters.Add(new OutAttachDirParameter(dataConsumer)); } private: IDataConsumer& dataConsumer; }; }