Added container logging
This commit is contained in:
@@ -177,6 +177,29 @@ namespace LXC::Util
|
|||||||
Internal::WriteImpl<Util::Color::DEFAULT, true>(std::cout, "Nullptr to: [", typeid(Raw).name(), "]");
|
Internal::WriteImpl<Util::Color::DEFAULT, true>(std::cout, "Nullptr to: [", typeid(Raw).name(), "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prints a container to the console //
|
||||||
|
template<typename T, std::ranges::range Container, typename CargoType = std::ranges::range_value_t<Container>>
|
||||||
|
requires (Internal::HasLogStrFunc<T> || Internal::Logable<T>) && (!std::is_pointer_v<T>) &&
|
||||||
|
(Internal::HasLogStrFunc<CargoType> || Internal::Logable<CargoType>) && (!std::is_pointer_v<CargoType>)
|
||||||
|
inline void PrintContainer(T&& containerName, const Container& container)
|
||||||
|
{
|
||||||
|
// Prints a starting section for the container //
|
||||||
|
Internal::WriteImpl<Util::Color::DEFAULT, true>(std::cout, "[LXC] \"", containerName, "\":\n{");
|
||||||
|
|
||||||
|
// Iterates over each of the items in the container and prints them //
|
||||||
|
for (const auto& item : container)
|
||||||
|
{
|
||||||
|
if constexpr (Internal::HasLogStrFunc<CargoType>)
|
||||||
|
Internal::WriteImpl<Util::Color::DEFAULT, true>(std::cout, '\t', item.LogStr());
|
||||||
|
|
||||||
|
else
|
||||||
|
Internal::WriteImpl<Util::Color::DEFAULT, true>(std::cout, '\t', item);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prints the ending bracket //
|
||||||
|
Internal::WriteImpl<Util::Color::DEFAULT, true>(std::cout, '}');
|
||||||
|
}
|
||||||
|
|
||||||
// Logs all the arguments to the file (automatically flushes) //
|
// Logs all the arguments to the file (automatically flushes) //
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
requires Internal::AllLogable<Args...> && (sizeof...(Args) > 1)
|
requires Internal::AllLogable<Args...> && (sizeof...(Args) > 1)
|
||||||
@@ -219,6 +242,33 @@ namespace LXC::Util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prints the contents of a container to the log //
|
||||||
|
template<typename T, std::ranges::range Container, typename CargoType = std::ranges::range_value_t<Container>>
|
||||||
|
requires (Internal::HasLogStrFunc<T> || Internal::Logable<T>) && (!std::is_pointer_v<T>) &&
|
||||||
|
(Internal::HasLogStrFunc<CargoType> || Internal::Logable<CargoType>) && (!std::is_pointer_v<CargoType>)
|
||||||
|
inline void LogContainer(T&& containerName, const Container& container)
|
||||||
|
{
|
||||||
|
// Gets the log if it is open //
|
||||||
|
std::ofstream& log = Internal::Log();
|
||||||
|
if (!log.is_open()) _LIKELY { return; }
|
||||||
|
|
||||||
|
// Prints a starting section for the container //
|
||||||
|
Internal::WriteImpl<Util::Color::DEFAULT, true>(log, "[LXC] \"", containerName, "\":\n{");
|
||||||
|
|
||||||
|
// Iterates over each of the items in the container and prints them //
|
||||||
|
for (const auto& item : container)
|
||||||
|
{
|
||||||
|
if constexpr (Internal::HasLogStrFunc<CargoType>)
|
||||||
|
Internal::WriteImpl<Util::Color::DEFAULT, true>(log, '\t', item.LogStr());
|
||||||
|
|
||||||
|
else
|
||||||
|
Internal::WriteImpl<Util::Color::DEFAULT, true>(log, '\t', item);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prints the ending bracket //
|
||||||
|
Internal::WriteImpl<Util::Color::DEFAULT, true>(log, '}');
|
||||||
|
}
|
||||||
|
|
||||||
// Intitalises the log with the given file name //
|
// Intitalises the log with the given file name //
|
||||||
inline void CreateLog(const std::filesystem::path& path)
|
inline void CreateLog(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ namespace LXC::Util
|
|||||||
// Operator overloads //
|
// Operator overloads //
|
||||||
|
|
||||||
explicit operator bool() const { return !m_FunctionFailed; }
|
explicit operator bool() const { return !m_FunctionFailed; }
|
||||||
operator ResultType() { return Result(); }
|
operator ResultType&() { return Result(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Union to hold either the result or the error //
|
// Union to hold either the result or the error //
|
||||||
|
|||||||
@@ -60,13 +60,9 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Prints all of the tokensto the log //
|
// Prints all of the tokens to the log //
|
||||||
for (const auto& token : tokens.Result())
|
|
||||||
{
|
|
||||||
Util::Log(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
Lexer::LexerOutput lexerOutput = tokens.Result();
|
Lexer::LexerOutput lexerOutput = tokens.Result();
|
||||||
|
Util::LogContainer("Lexer output", lexerOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Turns the tokens into into an abstract syntax tree //
|
// Turns the tokens into into an abstract syntax tree //
|
||||||
|
|||||||
Reference in New Issue
Block a user