COMP 2710 Software Construction Project 2 Main Function

  • Slides: 19
Download presentation
COMP 2710 Software Construction Project 2 – Main Function Tool, Report, and Configuration Classes

COMP 2710 Software Construction Project 2 – Main Function Tool, Report, and Configuration Classes Dr. Xiao Qin Auburn University http: //www. eng. auburn. edu/~xqin@auburn. edu

Main Function Option 1 int main() { Tool Command. Line Configuration Report cmd_t flag_t

Main Function Option 1 int main() { Tool Command. Line Configuration Report cmd_t flag_t tool; cmdline; conf; report; type; flag; . . . 1 -2

Main Function Option 1 (cont. ) tool. init(? ? ? ); //what arguments should

Main Function Option 1 (cont. ) tool. init(? ? ? ); //what arguments should we have? cmdline. get_command(); //user command input while ((type = cmdline. get_type())!= EXIT) { switch (type) { case RUN: tool. run(config, report); break; case SET: config. set(cmdline); break; case PRINT: flag = cmdline. get_flag(); if (flag == CONF) config. print_conf(); else if (flag == REPORT) report. print_report(); else count << “Error: invalid flag!n”; 1 -3 break;

Main Function Option 1 (cont. ) case SAVE: config. save_conf(); break; case HELP: default:

Main Function Option 1 (cont. ) case SAVE: config. save_conf(); break; case HELP: default: tool. help(); } //end switch cmdline. get_command(); //user command input } //end while tool. exit(); return 0; } 1 -4

Main Function Option 2 same as option 1 int main() { Tool Command. Line

Main Function Option 2 same as option 1 int main() { Tool Command. Line Configuration Report cmd_t flag_t tool; cmdline; conf; report; type; flag; . . . 1 -5

Main Function Option 2 tool. init(? ? ? ); cmdline. get_command(); //user command input

Main Function Option 2 tool. init(? ? ? ); cmdline. get_command(); //user command input while ((type = cmdline. get_type())!= EXIT) { //respond the command based on type tool. respond_cmd(cmdline, config, report); cmdline. get_command(); //user command input } tool. exit(); return 0; } 1 -6

Option 2: How to implement respond_cmd()? Tool: : respond_cmd(Command. Line cmd Configuration &conf, Report

Option 2: How to implement respond_cmd()? Tool: : respond_cmd(Command. Line cmd Configuration &conf, Report &rpt) cmd_t type; type = cmd. get_type(); //no user command input switch (type) { //why not tool. run? case RUN: run(conf, rpt); break; case SET: conf. set(cmd); break; case PRINT: flag = cmd. get_flag(); if (flag == CONF) conf. print_conf(); //Why not config. print? else if (flag == REPORT) rpt. print_report(); else count << “Error: invalid flag!n”; 1 -7 break;

Option 2: How to implement respond_cmd()? case SAVE: conf. save_conf(); break; case HELP: default:

Option 2: How to implement respond_cmd()? case SAVE: conf. save_conf(); break; case HELP: default: help(); //Why not tool. help()? } //end switch } //end Tool: respond_cmd 1 -8

Main Function Option 3 Options 1 and 2: int main() { Tool tool; Command.

Main Function Option 3 Options 1 and 2: int main() { Tool tool; Command. Line cmdline; Configuration conf; Report report; cmd_t type; flag_t flag; Option 3: int main() { Tool tool; . . . 1 -9

Main Function Option 3 (cont. ) int main() { Tool tool; tool. init(? ?

Main Function Option 3 (cont. ) int main() { Tool tool; tool. init(? ? ? ); //Do we still need any argument? tool. start(); //Can you implement start()? tool. exit(); return 0; } 1 -10

Option 3: How to implement Tool: : start()? void Tool: : start() { cmd_t

Option 3: How to implement Tool: : start()? void Tool: : start() { cmd_t type; //user command input. Who owns cmdline? cmdline. get_command(); while ((type = cmdline. get_type())!= EXIT) { //respond the command based on type //Who owns respond_cmd()? Why no argument? //Can respond_cmd access cmdline, config, report? respond_cmd(? ? ? ); cmdline. get_command(); //user command input } } 1 -11

Option 3: How to reimplement respond_cmd()? Tool: : respond_cmd(void) cmd_type = cmdline. get_type(); //why

Option 3: How to reimplement respond_cmd()? Tool: : respond_cmd(void) cmd_type = cmdline. get_type(); //why no user input? switch (type) { //option 2: run(conf, rpt); case RUN: run(); break; //option 2: conf. set(cmd); case SET: config. set(cmdline); break; case PRINT: flag_t flag = cmdline. get_flag(); if (flag == CONF) //option 2: conf. print_conf(); config. print_conf(); else if (flag == REPORT) report. print_report(); else count << “Error: invalid flag!n”; break; 1 -12. . .

Option 3: The Tool Class – Initial Design class Tool { private: Configuration Config;

Option 3: The Tool Class – Initial Design class Tool { private: Configuration Config; How to improve this class? Report report; Command. Line Cmdline; Which functions should be public: private? init(); void respond_cmd(); void run(); //sample diskstats void help(); void start(); void exit(); }; 1 -13

Option 3: The Tool Class – Final Design class Tool { private: Configuration Config;

Option 3: The Tool Class – Final Design class Tool { private: Configuration Config; Report report; Command. Line Cmdline; void respond_cmd(); void run(); //sample diskstats void help(); public: init(); void start(); void exit(); }; 1 -14

The Report Class – A building block: Record struct Record { double blk_read; double

The Report Class – A building block: Record struct Record { double blk_read; double blk_read_s; //add the other four item below. . . }; 1 -15

The Report Class class Report { private: vector<Record> record. List; string report. Path; //optional:

The Report Class class Report { private: vector<Record> record. List; string report. Path; //optional: path of the report public: Report(); void add_record(Record new. Record); Record get. Record(int key); void remove_record(int key); //optional void print_report(); //used by Tool. respond_cmd() bool save_report(); //used by Tool. respond_cmd() bool load_report(); //used by Tool. init() void set_report_path(string rpt. Path); //optional string get_report_path(); //optional }; 1 -16

The Configuration Class class Configuration { private: interval; int count; bool blk. Read. Flag;

The Configuration Class class Configuration { private: interval; int count; bool blk. Read. Flag; bool blk. Read. SFlag; bool kb. Read. SFlag; bool blk. Wrtn. SFlag; bool kb. Wrtn. SFlag; bool changed; public: . . . 1 -17

The Configuration Class – Initial Design class Configuration {. . . public: void print_conf();

The Configuration Class – Initial Design class Configuration {. . . public: void print_conf(); //used by Tool. respond_cmd() void save_conf(); void load_conf(); How to improve this class? u_int get_interval(); void set_interval(u_int time); u_int get_count(); void set_count(u_int count); bool get_blkread_flag(); void set_blkread_flag(bool flag); . . . Do we need these functions? }; 1 -18

The Configuration Class – Final Design class Configuration {. . . public: //print_conf() used

The Configuration Class – Final Design class Configuration {. . . public: //print_conf() used by Tool: : respond_cmd() void print_conf(); void save_conf(); void load_conf(); //set() is used by Tool: : respond_cmd() set(Command. Line cmdline); }; 1 -19