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(), "]");
|
||||
}
|
||||
|
||||
// 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) //
|
||||
template<typename... Args>
|
||||
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 //
|
||||
inline void CreateLog(const std::filesystem::path& path)
|
||||
{
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace LXC::Util
|
||||
// Operator overloads //
|
||||
|
||||
explicit operator bool() const { return !m_FunctionFailed; }
|
||||
operator ResultType() { return Result(); }
|
||||
operator ResultType&() { return Result(); }
|
||||
|
||||
private:
|
||||
// Union to hold either the result or the error //
|
||||
|
||||
@@ -61,12 +61,8 @@ int main(int argc, char** argv)
|
||||
else
|
||||
{
|
||||
// Prints all of the tokens to the log //
|
||||
for (const auto& token : tokens.Result())
|
||||
{
|
||||
Util::Log(token);
|
||||
}
|
||||
|
||||
Lexer::LexerOutput lexerOutput = tokens.Result();
|
||||
Util::LogContainer("Lexer output", lexerOutput);
|
||||
}
|
||||
|
||||
// Turns the tokens into into an abstract syntax tree //
|
||||
|
||||
Reference in New Issue
Block a user