Updated how results are retrieved

This commit is contained in:
2020-07-20 00:53:08 -04:00
parent 22871b71e9
commit 2616dabe6d
67 changed files with 132 additions and 434 deletions

View File

@@ -24,6 +24,7 @@
#ifndef PROBLEM_HPP
#define PROBLEM_HPP
#include <sstream>
#include <string>
#include "Stopwatch.hpp"
@@ -34,6 +35,7 @@ protected:
mee::Stopwatch timer; //Used to determine your algorithm's run time
bool solved; //Holds true after the problem has been solved
class Unsolved{}; //An exception class thrown if you try to access something before it has been solved
std::stringstream result; //Get the result of the problem
public:
//Constructors
Problem() : solved(false){
@@ -47,6 +49,7 @@ public:
virtual std::string getDescription() const{
return description;
}
//Get the time it took to run the algorithm as a string
virtual std::string getTime(){
//If the problem hasn't been solved throw an exception
if(!solved){
@@ -54,6 +57,7 @@ public:
}
return timer.getStr();
}
//Get a copy of the timer that was used to time the algorithm
virtual mee::Stopwatch getTimer(){
//If the problem hasn't been solved throw an exception
if(!solved){
@@ -63,12 +67,20 @@ public:
}
//Reset the problem so it can be run again
virtual void reset(){
result.str(std::string());
timer.reset();
solved = false;
}
//Return a string with the solution to the problem
virtual std::string getResults(){
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
return result.str();
}
//Pure virtual functions
virtual void solve() = 0; //Solve the problem
virtual std::string getString() const = 0; //Return a string with the solution to the problem
};
#endif //PROBLEM_HPP