Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: SimulatorLog: add GetFullLog #198

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions SimulatorCore/SimulatorLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,39 @@ std::string CSimulatorLog::Read()
return m_log[iPos].text;
}

std::string CSimulatorLog::GetFullLog() const
{
std::string result;

// Iterate through all valid entries up to write position
for (size_t i = 0; i < m_iWritePos && i < MAX_LOG_SIZE; ++i)
{
const size_t iPos = i % MAX_LOG_SIZE;
if (!m_log[iPos].text.empty())
{
if (!result.empty())
result += "\n";

// Add color-specific prefix
switch (m_log[iPos].color)
{
case ELogColor::RED:
result += "Error! ";
break;
case ELogColor::ORANGE:
result += "Warning! ";
break;
case ELogColor::DEFAULT:
default:
break;
}
result += m_log[iPos].text;
}
}

return result;
}

CSimulatorLog::ELogColor CSimulatorLog::GetReadColor() const
{
return m_log[m_iReadPos % MAX_LOG_SIZE].color;
Expand Down
2 changes: 2 additions & 0 deletions SimulatorCore/SimulatorLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class CSimulatorLog

// Returns message from the current read position and advances this position. Returns empty string if the end of log is reached.
std::string Read();
// Returns the complete log as a single string, containing all valid messages from start to current write position
std::string GetFullLog() const;
// Returns color from the current read position.
ELogColor GetReadColor() const;

Expand Down