Pomme/src/PommeDebug.cpp

43 lines
798 B
C++
Raw Normal View History

2020-11-11 20:06:52 +00:00
#include "PommeDebug.h"
2021-07-18 13:44:24 +00:00
#include <cstring>
2020-11-11 20:06:52 +00:00
#include <iostream>
void ImplementMe(const char* fn, std::string msg, int severity)
{
2021-07-18 13:44:24 +00:00
std::stringstream ss;
ss << "[TODO] \x1b[1m" << fn << "\x1b[22m";
2020-11-11 20:06:52 +00:00
2021-07-18 13:44:24 +00:00
if (!msg.empty())
ss << ": " << msg;
2020-11-11 20:06:52 +00:00
2021-07-18 13:44:24 +00:00
auto str = ss.str();
std::cerr << (severity > 0 ? "\x1b[31m" : "\x1b[33m") << str << "\x1b[0m\n";
2020-11-11 20:06:52 +00:00
if (severity >= 2)
2021-07-18 13:44:24 +00:00
throw std::runtime_error(str);
2020-11-11 20:06:52 +00:00
}
2021-04-17 10:35:29 +00:00
std::string Pomme::FourCCString(uint32_t fourCC, char filler)
2020-11-11 20:06:52 +00:00
{
2021-04-17 10:35:29 +00:00
char stringBuffer[5];
int shift = 24;
2020-11-11 20:06:52 +00:00
for (int i = 0; i < 4; i++)
{
2021-04-17 10:35:29 +00:00
char c = (fourCC >> shift) & 0xFF;
2021-07-18 13:44:24 +00:00
// Replace symbols to make suitable for use as filename
if (!isalnum(c) && !strchr("!#$%&'()+,-.;=@[]^_`{}", c))
2021-04-17 10:35:29 +00:00
c = filler;
stringBuffer[i] = c;
shift -= 8;
2020-11-11 20:06:52 +00:00
}
2021-04-17 10:35:29 +00:00
stringBuffer[4] = '\0';
return stringBuffer;
2020-11-11 20:06:52 +00:00
}