Skip to content

Commit

Permalink
Added std::array logging capabilities; added Logger::Hex tool for hex…
Browse files Browse the repository at this point in the history
…ing stuff
  • Loading branch information
Epixu committed Sep 3, 2024
1 parent e850f54 commit fbe5cdb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions source/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ namespace Langulus::Logger
LANGULUS_API(LOGGER) ScopedTabs operator << (Tabs&&) noexcept;

Interface& operator << (const CT::Sparse auto&) noexcept;
template<class T, size_t N>
Interface& operator << (const ::std::array<T, N>&) noexcept;
Interface& operator << (const ::Langulus::Logger::Formattable auto&) noexcept;
};

Expand Down Expand Up @@ -544,6 +546,19 @@ namespace Langulus::Logger
LANGULUS_API(LOGGER) void Clear() const noexcept;
};

/// Generate hexadecimal string from a given value
/// @param format - the template string
/// @param args... - the arguments
/// @return the instantiated template
auto Hex(const auto& from) {
::std::array<char, sizeof(from) * 2> result {};
auto from_bytes = reinterpret_cast<const std::byte*>(&from);
auto to_bytes = result.data();
for (Offset i = 0; i < sizeof(from); ++i)
fmt::format_to_n(to_bytes + i * 2, 2, "{:X}", from_bytes[i]);
return result;
}

} // namespace Langulus::Logger

#define LANGULUS_FUNCTION_NAME() \
Expand Down
6 changes: 6 additions & 0 deletions source/Logger.inl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ namespace Langulus::Logger
}
}

/// Log any character array
template<class T, size_t N> LANGULUS(INLINED)
A::Interface& A::Interface::operator << (const ::std::array<T, N>& a) noexcept {
return operator << (TextView {a.data(), N});
}

/// Stringify anything that has a valid fmt formatter
/// @param anything - type to stringify
/// @return a reference to the logger for chaining
Expand Down

0 comments on commit fbe5cdb

Please sign in to comment.