diff options
Diffstat (limited to 'sysmap/src/io.h')
| -rw-r--r-- | sysmap/src/io.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/sysmap/src/io.h b/sysmap/src/io.h new file mode 100644 index 0000000..b498065 --- /dev/null +++ b/sysmap/src/io.h @@ -0,0 +1,41 @@ +#pragma once + +#include <spdlog/fmt/fmt.h> +#include <spdlog/spdlog.h> +#include <spdlog/sinks/basic_file_sink.h> +#include <spdlog/sinks/stdout_color_sinks.h> + +enum log_lvl { + trace = 0, + debug, + info, + warn, + error, + critical +}; + +namespace io { + template<log_lvl T, typename... Args> + void log(std::string_view msg, Args... params) { + spdlog::log(static_cast<spdlog::level::level_enum>(T), msg.data(), std::forward<Args>(params)...); + } + + static std::vector<u8> read_file(std::string_view name) { + std::ifstream file(name.data(), std::ios::binary); + if (!file.good()) { + return {}; + } + + std::vector<u8> out; + + file.seekg(0, std::ios::end); + std::streampos length = file.tellg(); + file.seekg(0, std::ios::beg); + + out.resize(length); + + file.read((char*)out.data(), length); + + return out; + } +};
\ No newline at end of file |