generated from mcmarius/oop-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added singleton timer class and more error cases
- Loading branch information
Showing
12 changed files
with
133 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Created by eciuc on 6/3/2024. | ||
// | ||
|
||
#include "GeometricError.h" | ||
#include <string> | ||
|
||
DegenerateTriangle::DegenerateTriangle(const std::string &message) : | ||
GeometricError(std::string ("Triunghi degenerat:") + message) {} | ||
|
||
DoubleClick::DoubleClick(const std::string &message) : | ||
GeometricError(message) {} | ||
|
||
CannotProcessClick::CannotProcessClick(const std::string &message) : | ||
GeometricError(message) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Created by eciuc on 6/3/2024. | ||
// | ||
|
||
#ifndef OOP_GEOMETRICERROR_H | ||
#define OOP_GEOMETRICERROR_H | ||
|
||
|
||
#include <stdexcept> | ||
|
||
class GeometricError : public std::runtime_error { | ||
using std::runtime_error::runtime_error; | ||
}; | ||
|
||
class DegenerateTriangle : public GeometricError{ | ||
This comment has been minimized.
Sorry, something went wrong. |
||
public: | ||
explicit DegenerateTriangle(const std::string &message) ; | ||
}; | ||
|
||
class DoubleClick : public GeometricError{ | ||
public: | ||
explicit DoubleClick(const std::string &message); | ||
}; | ||
|
||
class CannotProcessClick : public GeometricError{ | ||
public: | ||
explicit CannotProcessClick(const std::string &message); | ||
}; | ||
|
||
|
||
|
||
|
||
|
||
|
||
#endif //OOP_GEOMETRICERROR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// Created by eciuc on 6/10/2024. | ||
// | ||
|
||
#include "Stopwatch.h" | ||
|
||
void Stopwatch::start_timing() { | ||
start_moment = high_resolution_clock::now(); | ||
} | ||
|
||
high_resolution_clock::duration Stopwatch::elapsed_time() { | ||
return high_resolution_clock::now()-start_moment; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// Created by eciuc on 6/10/2024. | ||
// | ||
|
||
#ifndef OOP_STOPWATCH_H | ||
#define OOP_STOPWATCH_H | ||
|
||
#include <chrono> | ||
#include "GeometricError.h" | ||
|
||
using namespace std::chrono; | ||
class Stopwatch { | ||
private: | ||
static inline high_resolution_clock::time_point start_moment; | ||
static inline bool isrunning=false; | ||
Stopwatch() = default; | ||
static void start_timing(); | ||
static high_resolution_clock::duration elapsed_time(); | ||
public: | ||
Stopwatch(const Stopwatch&) = delete; | ||
Stopwatch& operator=(const Stopwatch&) = delete; | ||
static Stopwatch& get_app() { | ||
static Stopwatch stopwatch; | ||
return stopwatch; | ||
} | ||
static void discard_double_action(){ | ||
if(isrunning) | ||
{ | ||
auto interval=elapsed_time(); | ||
if(interval < 0.2s) | ||
{ | ||
start_timing(); | ||
double dur= static_cast<double>(interval.count())/1e9; | ||
throw DoubleClick("Action detected " + std::to_string (dur) + "s after previous action, discarding input"); | ||
} | ||
} | ||
start_timing(); | ||
isrunning = true; | ||
} | ||
}; | ||
|
||
|
||
#endif //OOP_STOPWATCH_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
E mai ok să aibă sufixul
Error
, sare mai ușor în ochi că e vorba de clasă de excepții; acum poți să lași așa, dar ca idee