diff --git a/Common/LXC.h b/Common/LXC.h index 77c1243..b046e35 100644 --- a/Common/LXC.h +++ b/Common/LXC.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include diff --git a/Common/modules/IO.h b/Common/modules/IO.h index 1b6dae3..d7214ab 100644 --- a/Common/modules/IO.h +++ b/Common/modules/IO.h @@ -3,8 +3,10 @@ #include #include +#include #include #include +#include namespace LXC::Util { @@ -44,7 +46,7 @@ namespace LXC::Internal template concept AllLogable = (Logable && ...); // Checks if the type has a custom log method // - template concept HasLogStrFunc = requires(T obj) + template concept HasLogStrFunc = requires(T obj) { // Checks the type has a function LogStr that returns a string // { obj.LogStr() } -> std::same_as; @@ -153,25 +155,28 @@ namespace LXC::Util // Prints argument to the console with a new line character at the end // template - requires Internal::HasLogStrFunc || Internal::Logable + requires (Internal::HasLogStrFunc || Internal::Logable) && (!std::is_pointer_v) inline void PrintLn(T&& arg) { - if constexpr (std::is_pointer_v) - { - if (arg != nullptr) _LIKELY - PrintLn(*arg); - - else - Internal::WriteImpl(std::cout, "Nullptr to: [", typeid(std::remove_pointer_t).name(), "]"); - } - - else if constexpr (Internal::HasLogStrFunc) + if constexpr (Internal::HasLogStrFunc) Internal::WriteImpl(std::cout, arg.LogStr()); else Internal::WriteImpl(std::cout, arg); } + // Prints the value of a pointer to the console, prints an error if null // + template> + requires (Internal::HasLogStrFunc || Internal::Logable) && std::is_pointer_v + inline void PrintLn(T&& arg) + { + if (arg != nullptr) _LIKELY + PrintLn(*arg); + + else + Internal::WriteImpl(std::cout, "Nullptr to: [", typeid(Raw).name(), "]"); + } + // Logs all the arguments to the file (automatically flushes) // template requires Internal::AllLogable && (sizeof...(Args) > 1) @@ -184,22 +189,13 @@ namespace LXC::Util // Logs a singular argument to the log, calls Log() if it can on the object // template - requires Internal::HasLogStrFunc || Internal::Logable + requires (Internal::HasLogStrFunc || Internal::Logable) && (!std::is_pointer_v) inline void Log(T&& arg) { std::ofstream& log = Internal::Log(); if (log.is_open()) _UNLIKELY { - if constexpr (std::is_pointer_v) - { - if (arg != nullptr) _LIKELY - Log(*arg); - - else - Internal::WriteImpl(log, "[LXC] Nullptr to: [", typeid(std::remove_pointer_t).name(), "]"); - } - - else if constexpr (Internal::HasLogStrFunc) + if constexpr (Internal::HasLogStrFunc) Internal::WriteImpl(log, "[LXC] ", '{', arg.LogStr(), '}'); else @@ -207,6 +203,22 @@ namespace LXC::Util } } + // Prints the value of a pointer to the log, prints an error to the log if null // + template> + requires (Internal::HasLogStrFunc || Internal::Logable) && std::is_pointer_v + inline void Log(T&& arg) + { + std::ofstream& log = Internal::Log(); + if (log.is_open()) _UNLIKELY + { + if (arg != nullptr) _LIKELY + Log(*arg); + + else + Internal::WriteImpl(log, "[LXC] Nullptr to: [", typeid(Raw).name(), ']'); + } + } + // Intitalises the log with the given file name // inline void CreateLog(const std::filesystem::path& path) { diff --git a/Common/modules/Result.h b/Common/modules/Result.h index 69643ed..e55af12 100644 --- a/Common/modules/Result.h +++ b/Common/modules/Result.h @@ -104,7 +104,7 @@ namespace LXC::Util // Operator overloads // - operator bool() const { return !m_FunctionFailed; } + explicit operator bool() const { return !m_FunctionFailed; } operator ResultType() { return Result(); } private: diff --git a/LXC/LXC.cpp b/LXC/LXC.cpp index e0f8b07..1ca1ebe 100644 --- a/LXC/LXC.cpp +++ b/LXC/LXC.cpp @@ -65,6 +65,8 @@ int main(int argc, char** argv) { Util::Log(token); } + + Lexer::LexerOutput lexerOutput = tokens.Result(); } // Turns the tokens into into an abstract syntax tree //