mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 07:15:35 +08:00
Fix build with Clang on Windows
This commit is contained in:
@@ -218,6 +218,10 @@ win32:llvm {
|
||||
equals(WORD_SIZE,32): QMAKE_CXXFLAGS += --target=i686-pc-windows-gnu
|
||||
equals(WORD_SIZE,64): QMAKE_CXXFLAGS += --target=x86_64-pc-windows-gnu
|
||||
}
|
||||
else {
|
||||
CONFIG += c++latest
|
||||
QMAKE_CXXFLAGS_WARN_ON += -Wno-deprecated-declarations
|
||||
}
|
||||
|
||||
# Address Sanitizer
|
||||
# https://stackoverflow.com/a/48585886/1639256
|
||||
|
||||
@@ -71,6 +71,16 @@ namespace BlackMisc
|
||||
return ok;
|
||||
}
|
||||
|
||||
CAtomicFile::~CAtomicFile()
|
||||
{
|
||||
#if __cplusplus >= 201700L
|
||||
const bool ex = std::uncaught_exceptions() > 0;
|
||||
#else
|
||||
const bool ex = std::uncaught_exception();
|
||||
#endif
|
||||
if (ex) { QFile::close(); }
|
||||
}
|
||||
|
||||
void CAtomicFile::close()
|
||||
{
|
||||
if (! isOpen()) { return; }
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace BlackMisc
|
||||
CAtomicFile(const QString &filename) : QFile(filename) {}
|
||||
|
||||
//! \copydoc QFile::~QFile
|
||||
virtual ~CAtomicFile() override { if (std::uncaught_exception()) { QFile::close(); } }
|
||||
virtual ~CAtomicFile() override;
|
||||
|
||||
//! \copydoc QFile::open
|
||||
//! Just before opening the file, the filename is changed so we actually write to a temporary file.
|
||||
|
||||
@@ -358,7 +358,7 @@ namespace BlackMisc
|
||||
QFileInfoList result = dir.entryInfoList(nameFilters, QDir::Files);
|
||||
if (predicate)
|
||||
{
|
||||
result.erase(std::remove_if(result.begin(), result.end(), std::not1(predicate)), result.end());
|
||||
result.erase(std::remove_if(result.begin(), result.end(), [ = ](const auto &f) { return !predicate(f); }), result.end());
|
||||
}
|
||||
if (recursive)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "blackmisc/processctrl.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
|
||||
#include <QStringBuilder>
|
||||
#include <array>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
@@ -36,7 +36,7 @@ namespace BlackMisc
|
||||
QString command = '"' % QString(program).replace('/', '\\') % '"';
|
||||
if (!arguments.isEmpty())
|
||||
{
|
||||
command += " \"" % arguments.join('" "').replace('/', '\\') % '"';
|
||||
command += " \"" % arguments.join("\" \"").replace('/', '\\') % '"';
|
||||
}
|
||||
|
||||
DWORD flags = 0;
|
||||
|
||||
@@ -571,7 +571,12 @@ namespace BlackMisc
|
||||
{
|
||||
if (m_page)
|
||||
{
|
||||
if (std::uncaught_exception()) { m_page->abandonBatch(); }
|
||||
#if __cplusplus >= 201700L
|
||||
const bool ex = std::uncaught_exceptions() > 0;
|
||||
#else
|
||||
const bool ex = std::uncaught_exception();
|
||||
#endif
|
||||
if (ex) { m_page->abandonBatch(); }
|
||||
else { m_page->endBatch(); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,8 @@ namespace XSwiftBus
|
||||
{
|
||||
const int y = boxTop - (lineHeight + lineSpace) * (i + 1);
|
||||
const size_t ii = static_cast<size_t>(i);
|
||||
XPLMDrawString(m_messages[ii].m_rgb.data(), x + arrowWidth + arrowWidth / 2, y, const_cast<char *>(m_messages[ii].m_text.c_str()), nullptr, xplmFont_Basic);
|
||||
XPLMDrawString(m_messages[ii].m_rgb.data(), x + arrowWidth + arrowWidth / 2, y,
|
||||
const_cast<char *>(reinterpret_cast<const char *>(m_messages[ii].m_text.c_str())), nullptr, xplmFont_Basic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,13 +110,12 @@ namespace XSwiftBus
|
||||
CMessageBoxControl::CMessageBoxControl(int left, int right, int top) :
|
||||
m_messageBox(left, right, top),
|
||||
m_showCommand("org/swift-project/xswiftbus/show_messages", "Show XSwiftBus text messages", [this] { show(); }),
|
||||
m_hideCommand("org/swift-project/xswiftbus/hide_messages", "Hide XSwiftBus text messages", [this] { hide(); }),
|
||||
m_toggleCommand("org/swift-project/xswiftbus/toggle_messages", "Toggle XSwiftBus text messages", [this] { toggle(); }),
|
||||
m_scrollUpCommand("org/swift-project/xswiftbus/scroll_up", "Scroll up XSwiftBus text messages", [this] { scrollUp(); }),
|
||||
m_scrollDownCommand("org/swift-project/xswiftbus/scroll_down", "Scroll down XSwiftBus text messages", [this] { scrollDown(); }),
|
||||
m_scrollToTopCommand("org/swift-project/xswiftbus/scroll_top", "Scroll to top of XSwiftBus text messages", [this] { scrollToTop(); }),
|
||||
m_scrollToBottomCommand("org/swift-project/xswiftbus/scroll_bottom", "Scroll to bottom of XSwiftBus text messages", [this] { scrollToBottom(); }),
|
||||
m_debugCommand("org/swift-project/xswiftbus/debug", "", [this] { static int c = 0; this->addMessage({ "hello " + std::to_string(c++), 0, .75, 0 }); })
|
||||
m_hideCommand("org/swift-project/xswiftbus/hide_messages", "Hide XSwiftBus text messages", [this] { hide(); }),
|
||||
m_toggleCommand("org/swift-project/xswiftbus/toggle_messages", "Toggle XSwiftBus text messages", [this] { toggle(); }),
|
||||
m_scrollUpCommand("org/swift-project/xswiftbus/scroll_up", "Scroll up XSwiftBus text messages", [this] { scrollUp(); }),
|
||||
m_scrollDownCommand("org/swift-project/xswiftbus/scroll_down", "Scroll down XSwiftBus text messages", [this] { scrollDown(); }),
|
||||
m_scrollToTopCommand("org/swift-project/xswiftbus/scroll_top", "Scroll to top of XSwiftBus text messages", [this] { scrollToTop(); }),
|
||||
m_scrollToBottomCommand("org/swift-project/xswiftbus/scroll_bottom", "Scroll to bottom of XSwiftBus text messages", [this] { scrollToBottom(); })
|
||||
{
|
||||
show();
|
||||
}
|
||||
|
||||
@@ -22,16 +22,30 @@
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
//! \cond
|
||||
namespace Private
|
||||
{
|
||||
inline auto empty_u8string()
|
||||
{
|
||||
using namespace std::literals;
|
||||
return u8""s;
|
||||
}
|
||||
}
|
||||
//! \endcond
|
||||
|
||||
/*!
|
||||
* Class representing a single line of text to be drawn in a message box.
|
||||
*/
|
||||
struct CMessage
|
||||
{
|
||||
//! String type.
|
||||
using string = decltype(Private::empty_u8string());
|
||||
|
||||
//! Constructor.
|
||||
CMessage(const std::string &text, float r = 1, float g = 1, float b = 1) : m_text(text), m_rgb{{ r, g, b }} {}
|
||||
CMessage(const string &text, float r = 1, float g = 1, float b = 1) : m_text(text), m_rgb{{ r, g, b }} {}
|
||||
|
||||
//! Text.
|
||||
std::string m_text;
|
||||
string m_text;
|
||||
|
||||
//! Color.
|
||||
std::array<float, 3> m_rgb;
|
||||
@@ -148,7 +162,6 @@ namespace XSwiftBus
|
||||
CCommand m_scrollDownCommand;
|
||||
CCommand m_scrollToTopCommand;
|
||||
CCommand m_scrollToBottomCommand;
|
||||
CCommand m_debugCommand;
|
||||
};
|
||||
} //ns
|
||||
|
||||
|
||||
@@ -145,12 +145,13 @@ namespace XSwiftBus
|
||||
void CService::addTextMessage(const std::string &text, double red, double green, double blue)
|
||||
{
|
||||
if (text.empty()) { return; }
|
||||
static const std::string ellipsis = u8"\u2026";
|
||||
static const CMessage::string ellipsis = u8"\u2026";
|
||||
const int lineLength = m_messages.maxLineLength() - static_cast<int>(ellipsis.size());
|
||||
std::vector<std::string> wrappedLines;
|
||||
std::vector<CMessage::string> wrappedLines;
|
||||
for (size_t i = 0; i < text.size(); i += static_cast<size_t>(lineLength))
|
||||
{
|
||||
wrappedLines.push_back(text.substr(i, static_cast<size_t>(lineLength)) + ellipsis);
|
||||
wrappedLines.emplace_back(text.begin() + i, text.begin() + i + static_cast<size_t>(lineLength));
|
||||
wrappedLines.back() += ellipsis;
|
||||
}
|
||||
wrappedLines.back().erase(wrappedLines.back().size() - ellipsis.size());
|
||||
if (wrappedLines.back().empty()) { wrappedLines.pop_back(); }
|
||||
|
||||
@@ -161,8 +161,10 @@ namespace BlackMiscTest
|
||||
|
||||
void CTestStringUtils::testSimplify()
|
||||
{
|
||||
const QString input = QString::fromUtf8(u8"ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöùúûüýÿ");
|
||||
const QString output = QLatin1String("SZszYAAAAAACEEEEIIIINOOOOOUUUUYaaaaaaceeeeiiiinooooouuuuyy");
|
||||
const auto inputChars = u8"ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöùúûüýÿ";
|
||||
const auto outputChars = "SZszYAAAAAACEEEEIIIINOOOOOUUUUYaaaaaaceeeeiiiinooooouuuuyy";
|
||||
const QString input = QString::fromUtf8(reinterpret_cast<const char *>(inputChars));
|
||||
const QString output = QLatin1String(outputChars);
|
||||
QCOMPARE(simplifyAccents(input), output);
|
||||
QCOMPARE(simplifyByDecomposition(input), output);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user