First commit from Arch
This commit is contained in:
26
include/FileReader.h
Normal file
26
include/FileReader.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
#include "Logger.h"
|
||||
|
||||
static std::vector<char> ReadFile(const std::string& FileName)
|
||||
{
|
||||
std::ifstream File(FileName, std::ios::ate | std::ios::binary);
|
||||
|
||||
if (!File.is_open())
|
||||
{
|
||||
Log::Error("Failed to open file: " + FileName);
|
||||
}
|
||||
|
||||
size_t FileSize = (size_t)File.tellg();
|
||||
std::vector<char> Buffer(FileSize);
|
||||
|
||||
File.seekg(0);
|
||||
File.read(Buffer.data(), FileSize);
|
||||
|
||||
File.close();
|
||||
|
||||
return Buffer;
|
||||
}
|
||||
64
include/Logger.cpp
Normal file
64
include/Logger.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#include "Logger.h"
|
||||
#include <iostream>
|
||||
|
||||
void Log::Message(Level Level, const std::string& Message, const std::source_location& Location)
|
||||
{
|
||||
std::string FullFunc = Location.function_name();
|
||||
std::string DisplayName = FullFunc; // Default to full function name
|
||||
|
||||
// Simple cleanup: try to extract just class::method
|
||||
size_t LastColon = FullFunc.rfind("::");
|
||||
if (LastColon != std::string::npos)
|
||||
{
|
||||
// Find the class name start
|
||||
size_t ClassStart = FullFunc.rfind(' ', LastColon);
|
||||
if (ClassStart != std::string::npos)
|
||||
{
|
||||
std::string ClassName = FullFunc.substr(ClassStart + 1, LastColon - ClassStart - 1);
|
||||
|
||||
// Find method name end (first parenthesis after last ::)
|
||||
size_t MethodEnd = FullFunc.find('(', LastColon);
|
||||
if (MethodEnd != std::string::npos)
|
||||
{
|
||||
std::string MethodName = FullFunc.substr(LastColon + 2, MethodEnd - LastColon - 2);
|
||||
DisplayName = ClassName + "::" + MethodName + "()";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string LevelString;
|
||||
switch (Level)
|
||||
{
|
||||
case Level::Info:
|
||||
LevelString = "INFO";
|
||||
break;
|
||||
case Level::Warning:
|
||||
LevelString = "WARNING";
|
||||
break;
|
||||
case Level::Error:
|
||||
LevelString = "ERROR";
|
||||
break;
|
||||
case Level::Debug:
|
||||
LevelString = "DEBUG";
|
||||
break;
|
||||
case Level::VkValidation:
|
||||
LevelString = "VALIDATION LAYER";
|
||||
break;
|
||||
case Level::DeviceSetup:
|
||||
LevelString = "DEVICE SETUP";
|
||||
break;
|
||||
default:
|
||||
LevelString = "UNKNOWN";
|
||||
break;
|
||||
}
|
||||
|
||||
std::string LogMessage = std::format("[{}] [{}] {}",
|
||||
LevelString, DisplayName, Message);
|
||||
|
||||
std::cout << LogMessage << std::endl;
|
||||
|
||||
if (Level == Level::Error)
|
||||
{
|
||||
throw std::runtime_error(LogMessage);
|
||||
}
|
||||
}
|
||||
58
include/Logger.h
Normal file
58
include/Logger.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <source_location>
|
||||
#include <format>
|
||||
|
||||
namespace Log
|
||||
{
|
||||
|
||||
enum class Level
|
||||
{
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
Debug,
|
||||
VkValidation,
|
||||
DeviceSetup
|
||||
};
|
||||
|
||||
// void Message(Level Level, const std::source_location& Location = std::source_location::current(), const std::string& Message);
|
||||
void Message(Level Level, const std::string& Message, const std::source_location& Location);
|
||||
|
||||
template <typename... Args>
|
||||
void Info(const std::string& Format, Args&&... Arguments, const std::source_location& Location = std::source_location::current())
|
||||
{
|
||||
Message(Level::Info, std::vformat(Format, std::make_format_args(Arguments...)), Location);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void Warning(const std::string& Format, Args&&... Arguments, const std::source_location& Location = std::source_location::current())
|
||||
{
|
||||
Message(Level::Warning, std::vformat(Format, std::make_format_args(Arguments...)), Location);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void Error(const std::string& Format, Args&&... Arguments, const std::source_location& Location = std::source_location::current())
|
||||
{
|
||||
Message(Level::Error, std::vformat(Format, std::make_format_args(Arguments...)), Location);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void Debug(const std::string& Format, Args&&... Arguments, const std::source_location& Location = std::source_location::current())
|
||||
{
|
||||
Message(Level::Warning, std::vformat(Format, std::make_format_args(Arguments...)), Location);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void Validation(const std::string& Format, Args&&... Arguments, const std::source_location& Location = std::source_location::current())
|
||||
{
|
||||
Message(Level::VkValidation, std::vformat(Format, std::make_format_args(Arguments...)), Location);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void DeviceSetup(const std::string& Format, Args&&... Arguments, const std::source_location& Location = std::source_location::current())
|
||||
{
|
||||
Message(Level::DeviceSetup, std::vformat(Format, std::make_format_args(Arguments...)), Location);
|
||||
}
|
||||
} // namespace Log
|
||||
Reference in New Issue
Block a user