mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 15:25:35 +08:00
71 lines
2.3 KiB
C++
71 lines
2.3 KiB
C++
/* Copyright (C) 2016
|
|
* swift project Community / Contributors
|
|
*
|
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
|
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
|
* contained in the LICENSE file.
|
|
*/
|
|
|
|
#include "blackmisc/jsonexception.h"
|
|
#include "blackmisc/statusmessage.h"
|
|
#include "blackmisc/logcategorylist.h"
|
|
#include "blackmisc/logmessage.h"
|
|
#include <QStringBuilder>
|
|
#include <QThreadStorage>
|
|
#include <vector>
|
|
|
|
namespace BlackMisc
|
|
{
|
|
//! \private
|
|
auto &jsonStack() noexcept
|
|
{
|
|
static QThreadStorage<std::vector<const CJsonScope *>> stack;
|
|
return stack.localData();
|
|
}
|
|
|
|
// pin vtables to this file
|
|
void CJsonException::anchor()
|
|
{ }
|
|
|
|
CStatusMessage CJsonException::toStatusMessage(const CLogCategoryList &categories, const QString &prefix) const
|
|
{
|
|
return CStatusMessage(categories).validationError(toString(prefix));
|
|
}
|
|
|
|
QString CJsonException::toString(const QString &prefix) const
|
|
{
|
|
static const QString s("%1 in '%2'");
|
|
static const QString sp("%1: %2 in '%3'");
|
|
if (prefix.isEmpty()) { return s.arg(what()).arg(getStackTrace()); }
|
|
return sp.arg(prefix).arg(what()).arg(getStackTrace());
|
|
}
|
|
|
|
void CJsonException::toLogMessage(const CLogCategoryList &categories, const QString &prefix) const
|
|
{
|
|
CLogMessage(categories).validationError(toString(prefix));
|
|
}
|
|
|
|
QString CJsonException::stackString()
|
|
{
|
|
QStringList list;
|
|
for (const auto scope : BlackMisc::as_const(jsonStack()))
|
|
{
|
|
list.push_back(scope->m_string ? *scope->m_string : scope->m_latin1); // clazy:exclude=reserve-candidates
|
|
if (scope->m_index >= 0) { list.back() += "[" % QString::number(scope->m_index) % "]"; }
|
|
}
|
|
return list.isEmpty() ? QStringLiteral("<document root>") : list.join('.');
|
|
}
|
|
|
|
void CJsonScope::push() const noexcept
|
|
{
|
|
jsonStack().push_back(this);
|
|
}
|
|
|
|
void CJsonScope::pop() const noexcept
|
|
{
|
|
Q_ASSERT(jsonStack().back() == this);
|
|
jsonStack().pop_back();
|
|
}
|
|
}
|