mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-30 00:23:14 +00:00
6dd3558db9
Add Log.h (in IfcViewerCore) — a tiny stream-style logger that backs fprintf(stderr,...), with overloads for the common primitives + char strings. Mimics qInfo()/qWarning()'s syntax surface enough that mass-replacing qInfo()→Log::info() and qWarning()→Log::warn() keeps existing call sites parsing unchanged; .noquote() / .nospace() exist as compat no-ops so chained qInfo().noquote()<<x<<y patterns survive. QString streaming is a transitional concern — the QString → std::string sweep (#80) hasn't landed yet, so ViewportWindow and friends still construct QStrings for log payloads. LogQt.h (in IfcViewer, not Core) adds the QString / QStringView operator<< overloads so those streaming sites work without source changes during the in-flight Qt removal. When #80 retires QString, LogQt.h drops out. ViewportWindow.cpp: 132 qInfo/qWarning callsites converted. The two printf-style qInfo("fmt %s", ...) callsites get fprintf with explicit [info]/[warn] prefixes to keep the output discoverable. Also de-Qt'd: AreaMeasurement.cpp — 1 qInfo("fmt", …) → fprintf SceneLoader.cpp — 4 qDebug + 1 qWarning printf-style → fprintf GeometryStreamer.cpp — 2 qDebug printf-style → fprintf ifcviewer-minimal/main.cpp — 2 qWarning << → Log::warn Drops <QDebug> from each. Closes #82. Builds: desktop / bonsai / web all green. Tests 100/100 pass.
68 lines
2.9 KiB
C++
68 lines
2.9 KiB
C++
/********************************************************************************
|
|
* *
|
|
* This file is part of IfcOpenShell. *
|
|
* *
|
|
* IfcOpenShell is free software: you can redistribute it and/or modify *
|
|
* it under the terms of the Lesser GNU General Public License as published by *
|
|
* the Free Software Foundation, either version 3.0 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
* IfcOpenShell is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* Lesser GNU General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the Lesser GNU General Public License *
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
* *
|
|
********************************************************************************/
|
|
|
|
#ifndef IFCVIEWER_LOG_QT_H
|
|
#define IFCVIEWER_LOG_QT_H
|
|
|
|
// Qt-only adjunct to Log.h. Lets the Qt-using TUs (ViewportWindow,
|
|
// OverlayRenderer, Federation, SceneLoader …) keep streaming QString
|
|
// values through Log::info()/warn() during the in-flight Qt removal —
|
|
// once the QString → std::string sweep (#80) lands these TUs stop
|
|
// constructing QStrings in log statements and this header goes away.
|
|
//
|
|
// Lives in src/ifcviewer/ (NOT in IfcViewerCore), so the web build /
|
|
// any future Qt-free ViewportCore TU never includes it and never pulls
|
|
// in QString.
|
|
|
|
#include "Log.h"
|
|
|
|
#include <QByteArray>
|
|
#include <QString>
|
|
|
|
namespace Log {
|
|
|
|
// The chain `Log::info() << "tag" << qstr` produces a prvalue Stream
|
|
// that's then chained through Stream& returned by the member
|
|
// operator<<. So both lvalue-ref and rvalue-ref overloads are needed
|
|
// for QString to bind regardless of where it appears in the chain.
|
|
|
|
inline Stream& operator<<(Stream& s, const QString& qs) {
|
|
const QByteArray utf8 = qs.toUtf8();
|
|
std::fwrite(utf8.constData(), 1, std::size_t(utf8.size()), stderr);
|
|
return s;
|
|
}
|
|
inline Stream&& operator<<(Stream&& s, const QString& qs) {
|
|
s << qs;
|
|
return std::move(s);
|
|
}
|
|
|
|
inline Stream& operator<<(Stream& s, QStringView qsv) {
|
|
const QByteArray utf8 = qsv.toUtf8();
|
|
std::fwrite(utf8.constData(), 1, std::size_t(utf8.size()), stderr);
|
|
return s;
|
|
}
|
|
inline Stream&& operator<<(Stream&& s, QStringView qsv) {
|
|
s << qsv;
|
|
return std::move(s);
|
|
}
|
|
|
|
} // namespace Log
|
|
|
|
#endif // IFCVIEWER_LOG_QT_H
|