Files
wc3re/common.hh
Matthias Blankertz 29e9acd734 Initial work on globals.iff
- iffexplore to decocde globals.iff
- font2png parses the font blobs found therein
2015-04-16 21:14:52 +02:00

63 lines
1.1 KiB
C++

#ifndef WC3RE__COMMON_HH__
#define WC3RE__COMMON_HH__
#include <string>
#include <cstring>
#include <cstdio>
#include <cerrno>
#include <memory>
using namespace std::string_literals;
class Exception {
public:
Exception() : msg_() {
}
Exception(std::string msg) : msg_(std::move(msg)) {
}
virtual ~Exception() {}
virtual std::string toString() const {
return "Exception: "s + msg_;
}
protected:
std::string msg_;
};
class FormatException : public Exception {
public:
FormatException(std::string msg) : Exception(std::move(msg)) {
}
std::string toString() const override {
return "FormatException: "s + msg_;
}
};
class POSIXException : public Exception {
public:
POSIXException(int err, std::string msg = ""): Exception(std::move(msg)), err_(err) {
}
int getErr() const {return err_;}
std::string toString() const override {
return "POSIXException: "s + msg_ + ": "s + std::strerror(err_);
}
private:
int err_;
};
struct FILEDeleter {
void operator()(FILE* file) const {
fclose(file);
}
};
using FILEUPtr = std::unique_ptr<FILE, FILEDeleter>;
#endif