input_controller.cpp 551 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "input_controller.h"
  2. #include <stdexcept>
  3. #define EMPTY_LINE_ERROR "Line is empty."
  4. using std::runtime_error;
  5. input_controller::input_controller()
  6. {
  7. }
  8. input_controller::~input_controller()
  9. {
  10. }
  11. bool input_controller::get_next_line()
  12. {
  13. return getline(*input, line).good();
  14. }
  15. string input_controller::get_command()
  16. {
  17. string cmd;
  18. stream = istringstream{ line };
  19. cmd = string{};
  20. if (!(stream >> cmd))
  21. throw runtime_error(EMPTY_LINE_ERROR);
  22. return cmd;
  23. }
  24. istringstream *input_controller::get_command_stream()
  25. {
  26. return &stream;
  27. }