mirror of
https://bitbucket.org/Mattrixwv/projecteulercpp.git
synced 2025-12-07 01:23:57 -05:00
Updated how results are retrieved
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user