WIP
This commit is contained in:
30
common.hh
30
common.hh
@@ -12,15 +12,23 @@
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
|
||||
using namespace gl;
|
||||
using namespace std::string_literals;
|
||||
|
||||
class Exception {
|
||||
public:
|
||||
Exception() {
|
||||
Exception() : msg_() {
|
||||
}
|
||||
|
||||
Exception(std::string msg) : msg_(msg) {
|
||||
}
|
||||
|
||||
virtual ~Exception() {}
|
||||
|
||||
virtual std::string toString() const = 0;
|
||||
virtual std::string toString() const {
|
||||
return "Exception: "s + msg_;
|
||||
}
|
||||
protected:
|
||||
std::string msg_;
|
||||
};
|
||||
|
||||
class POSIXException : public Exception {
|
||||
@@ -31,7 +39,7 @@ public:
|
||||
int getErr() const {return err_;}
|
||||
|
||||
std::string toString() const override {
|
||||
return std::string("POSIXException: ") + std::strerror(err_);
|
||||
return "POSIXException: "s + std::strerror(err_);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -66,7 +74,7 @@ public:
|
||||
}
|
||||
|
||||
std::string toString() const override {
|
||||
return "GLException: " + errToString() + "(" + std::to_string(static_cast<int>(err_)) + ")";
|
||||
return "GLException: "s + errToString() + "(" + std::to_string(static_cast<int>(err_)) + ")";
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -75,28 +83,22 @@ private:
|
||||
|
||||
class SDLException : public Exception {
|
||||
public:
|
||||
SDLException() : Exception(), msg_(SDL_GetError()) {
|
||||
SDLException() : Exception(SDL_GetError()) {
|
||||
}
|
||||
|
||||
std::string toString() const override {
|
||||
return "SDLException: " + msg_;
|
||||
return "SDLException: "s + msg_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string msg_;
|
||||
};
|
||||
|
||||
class TTFException : public Exception {
|
||||
public:
|
||||
TTFException() : Exception(), msg_(TTF_GetError()) {
|
||||
TTFException() : Exception(TTF_GetError()) {
|
||||
}
|
||||
|
||||
std::string toString() const override {
|
||||
return "TTFException: " + msg_;
|
||||
return "TTFException: "s + msg_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string msg_;
|
||||
};
|
||||
|
||||
static void checkGlError() {
|
||||
|
||||
Reference in New Issue
Block a user