1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-02-23 21:27:14 +01:00
SqMod/vendor/POCO/Foundation/src/NestedDiagnosticContext.cpp
Sandu Liviu Catalin 4a6bfc086c Major plugin refactor and cleanup.
Switched to POCO library for unified platform/library interface.
Deprecated the external module API. It was creating more problems than solving.
Removed most built-in libraries in favor of system libraries for easier maintenance.
Cleaned and secured code with help from static analyzers.
2021-01-30 08:51:39 +02:00

130 lines
2.0 KiB
C++

//
// NestedDiagnosticContext.cpp
//
// Library: Foundation
// Package: Core
// Module: NestedDiagnosticContext
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/NestedDiagnosticContext.h"
#include "Poco/SingletonHolder.h"
#include "Poco/ThreadLocal.h"
namespace Poco {
NestedDiagnosticContext::NestedDiagnosticContext()
{
}
NestedDiagnosticContext::NestedDiagnosticContext(const NestedDiagnosticContext& ctx)
{
_stack = ctx._stack;
}
NestedDiagnosticContext::~NestedDiagnosticContext()
{
}
NestedDiagnosticContext& NestedDiagnosticContext::operator = (const NestedDiagnosticContext& ctx)
{
if (&ctx != this)
_stack = ctx._stack;
return *this;
}
void NestedDiagnosticContext::push(const std::string& info)
{
Context ctx;
ctx.info = info;
ctx.line = -1;
ctx.file = 0;
_stack.push_back(ctx);
}
void NestedDiagnosticContext::push(const std::string& info, int line, const char* filename)
{
Context ctx;
ctx.info = info;
ctx.line = line;
ctx.file = filename;
_stack.push_back(ctx);
}
void NestedDiagnosticContext::pop()
{
if (!_stack.empty())
_stack.pop_back();
}
int NestedDiagnosticContext::depth() const
{
return int(_stack.size());
}
std::string NestedDiagnosticContext::toString() const
{
std::string result;
for (const auto& i: _stack)
{
if (!result.empty())
result.append(":");
result.append(i.info);
}
return result;
}
void NestedDiagnosticContext::dump(std::ostream& ostr) const
{
dump(ostr, "\n");
}
void NestedDiagnosticContext::dump(std::ostream& ostr, const std::string& delimiter) const
{
for (const auto& i: _stack)
{
ostr << i.info;
if (i.file)
ostr << " (in \"" << i.file << "\", line " << i.line << ")";
ostr << delimiter;
}
}
void NestedDiagnosticContext::clear()
{
_stack.clear();
}
namespace
{
static ThreadLocal<NestedDiagnosticContext> ndc;
}
NestedDiagnosticContext& NestedDiagnosticContext::current()
{
return ndc.get();
}
} // namespace Poco