Yerbacon/src/headers/Yerbacon.hpp

71 lines
2.1 KiB
C++

#ifndef YERBACON_HPP
#define YERBACON_HPP
#ifndef YBCON_VERSION
#warning "YBCON_VERSION is unknown and will therefore be set to a default value"
#define YBCON_VERSION "UNKNOWN"
#endif
#ifndef YBCON_FLAGS
#define YBCON_FLAGS "none"
#endif
#ifndef YBCON_COMPILER
#define YBCON_COMPILER "unknown"
#endif
#ifdef __STDC_NO_THREADS__
#error "A valid std::threads implementation is required"
#endif
#include <version>
#if not defined(__cpp_lib_concepts) || not defined(__cpp_lib_integer_comparison_functions)
#error "The current standard library is incomplete"
#endif
#ifndef __cpp_using_enum
#error "The "using enum" syntax is not supported by this compiler"
#endif
#include <exception>
#include <string_view>
#include <string>
#include <optional>
#include <algorithm>
#include <iostream>
namespace Yerbacon {
consteval const char* getVersion() noexcept { return YBCON_VERSION; }
consteval const char* getBuildInfo() noexcept { return
"Build info:\n"
" Optimization flags: " YBCON_FLAGS "\n"
" Compiler: " YBCON_COMPILER;
}
static void exit(const std::initializer_list<const char*> reason) {
std::for_each(reason.begin(), reason.end(), [](const char* current_string){
std::cout << current_string;
});
std::cout << std::endl;
std::exit(EXIT_FAILURE);
}
inline void exit(const char* reason) { exit({reason}); }
class Exception: public std::exception {
std::string exceptionCause;
public:
[[nodiscard]] const char* what() const noexcept final {
return exceptionCause.data();
}
explicit Exception(const std::string_view& cause): exceptionCause(cause) {
if (!cause.ends_with('\n')) exceptionCause += '\n';
}
Exception(const std::string_view& cause, unsigned long line): Exception(('L' + std::to_string(line) + ": ").append(cause)) {}
};
}
#include <memory>
template<typename T, typename U>
constexpr T& pointerAs(const std::unique_ptr<U>& ptr) { return reinterpret_cast<T&>(*ptr); }
#undef YBCON_VERSION
#undef YBCON_FLAGS
#undef YBCON_COMPILER
#endif