Skip to content

Commit 9968b79

Browse files
committed
Container/Stack: Adding Logger
1 parent 1f7d708 commit 9968b79

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

modules/Container/Stack.mpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ export module CppUtils.Container.Stack;
22

33
import std;
44
import CppUtils.Type;
5+
import CppUtils.Logger;
56

67
export namespace CppUtils::Container
78
{
89
class Stack final
910
{
1011
public:
12+
using Logger = Logger<"CppUtils">;
13+
1114
template<std::size_t I, class... Args>
1215
[[nodiscard]] static inline consteval auto getOffset() noexcept -> std::size_t
1316
{
@@ -115,10 +118,11 @@ export namespace CppUtils::Container
115118

116119
inline auto dump() const noexcept -> void
117120
{
118-
std::puts("Memory dump:");
121+
Logger::print<"debug">("Memory dump:");
122+
auto line = std::string{};
119123
for (auto i = 0uz; i < std::size(m_data);)
120124
{
121-
std::print("{:#04x} ", static_cast<unsigned char>(m_data[i]));
125+
line += std::format("{:#04x} ", static_cast<unsigned char>(m_data[i]));
122126
if (++i % sizeof(std::size_t) == 0)
123127
{
124128
auto int1 = 0;
@@ -127,16 +131,22 @@ export namespace CppUtils::Container
127131
std::memcpy(std::addressof(int1), std::data(m_data) + i - sizeof(int) * 2, sizeof(int));
128132
std::memcpy(std::addressof(int2), std::data(m_data) + i - sizeof(int), sizeof(int));
129133
std::memcpy(std::addressof(sizeT), std::data(m_data) + i - sizeof(std::size_t), sizeof(std::size_t));
130-
std::println(" ({} | {} -> {})", int1, int2, sizeT);
134+
Logger::print<"debug">("{} ({} | {} -> {})", line, int1, int2, sizeT);
135+
line.clear();
131136
}
132137
}
133-
if (std::size(m_data) % sizeof(std::size_t) != 0 and std::size(m_data) % sizeof(int) == 0)
138+
if (not std::empty(line))
134139
{
135-
auto value = 0;
136-
std::memcpy(std::addressof(value), std::data(m_data) + std::size(m_data) - sizeof(int), sizeof(int));
137-
std::println(" ({})", value);
140+
if (std::size(m_data) % sizeof(int) == 0)
141+
{
142+
auto value = 0;
143+
std::memcpy(std::addressof(value), std::data(m_data) + std::size(m_data) - sizeof(int), sizeof(int));
144+
Logger::print<"debug">("{:<40} ({})", line, value);
145+
}
146+
else
147+
Logger::print<"debug">("{}", line);
138148
}
139-
std::puts("");
149+
Logger::print<>("");
140150
}
141151

142152
private:

0 commit comments

Comments
 (0)