Files
textmate/Frameworks/OakDebug/src/OakDebugLog.cc
Allan Odgaard 69c83e56df The ‘const’ keyword should be to the right of its type
The standard doesn’t care which side the keyword is placed on, but placing it on the right makes it easier to read types.

E.g. reading “int const* const” from right to left we get “const pointer to const integer”.
2014-03-31 08:27:19 +07:00

74 lines
1.5 KiB
C++

#include "OakDebug.h"
#ifndef NDEBUG
#include <oak/oak.h>
static std::mutex RegistryMutex;
std::map<std::string, bool>& OakDebugBaseClass::registry ()
{
static std::map<std::string, bool>* Registry = NULL;
static bool didLoad = false;
if(didLoad == false)
{
Registry = new std::map<std::string, bool>;
char* tok;
char* debug;
if(debug = getenv("DebugFlags"))
{
while(tok = strtok(debug, ", ;"))
{
(*Registry)[tok] = true;
debug = NULL;
}
}
didLoad = true;
}
return *Registry;
}
std::string OakDebugBaseClass::sectionName (std::string const& title)
{
size_t separatorIndex = title.find("_");
if(separatorIndex != std::string::npos && separatorIndex != title.size() - 1)
return title.substr(0, separatorIndex).c_str();
else
return title;
}
std::vector<std::string> OakDebugBaseClass::sectionNames ()
{
std::map<std::string, size_t> sectionNames;
std::lock_guard<std::mutex> lock(RegistryMutex);
for(auto pair : registry())
sectionNames[sectionName(pair.first)]++;
std::vector<std::string> res;
for(auto pair : sectionNames)
{
if(pair.second > 1)
res.push_back(pair.first);
}
return res;
}
bool OakDebugBaseClass::checkForDebugVar (char const* name)
{
std::lock_guard<std::mutex> lock(RegistryMutex);
return registry()["All"] || registry()[name];
}
void OakPrintF (char const* file, char const* function, int line, char const* format, ...)
{
fprintf(stderr, "%s\t%s\t%d\t", file, function, line);
va_list ap;
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
}
#endif