Advertisement
Guest User

Commands

a guest
Nov 23rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. # MAKE SURE TO ADD IN THE UP OF THE FILE
  2. #include "../include/GlobalVariables.h"
  3.  
  4.  
  5. //#     History implementation
  6. // Constructor
  7. HistoryCommand::HistoryCommand(string args, const vector<BaseCommand *> & history)
  8.         :BaseCommand(args), history(history){}
  9. void HistoryCommand::execute(FileSystem & fs){
  10.     for(int i=0;i<history.size();i++)
  11.         cout << i << "\t" << history.at(i)->toString() << endl;
  12. }
  13. string HistoryCommand::toString(){
  14.     cout << "history" << endl;
  15. }
  16.  
  17. //#     ExecCommand implementation
  18. // Constructor
  19. ExecCommand::ExecCommand(string args, const vector<BaseCommand *> & history)
  20.         :BaseCommand(args), history(history){}
  21. void ExecCommand::execute(FileSystem & fs){
  22.     int index = stoi(getArgs()); // get int from string
  23.     if(index < history.size()){ // TODO: make sure it works for history.size input(and alike)
  24.         history.at(index)->execute(fs);
  25.     } else{ cout << "Command not found" << endl; }
  26. }
  27. string ExecCommand::toString(){
  28.     cout << "exec" << endl;
  29. }
  30.  
  31. //#  Verbose Command implementation
  32. VerboseCommand::VerboseCommand(string args): BaseCommand(args){}
  33. void VerboseCommand::execute(FileSystem & fs){
  34.     unsigned int val = stoi(getArgs()); // get int from string
  35.     if(val <= 3 && val >= 0) {
  36.         verbose = val;
  37.     }else{ cout << "Wrong verbose input" << endl;}
  38. }
  39. string VerboseCommand::toString(){
  40.     cout << "verbose" << endl;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement