From 82edd98300b9d050dd28fdfa1e6ea7b18ecca22c Mon Sep 17 00:00:00 2001 From: Vitaly Stakhovsky Date: Wed, 6 Feb 2019 15:00:00 -0500 Subject: [PATCH] cmSystemTools: MessageCallback and Message() accept std::string argument --- Source/CTest/cmCTestBuildAndTestHandler.cxx | 2 +- Source/CursesDialog/ccmake.cxx | 2 +- Source/CursesDialog/cmCursesForm.h | 4 +++- Source/CursesDialog/cmCursesMainForm.cxx | 3 ++- Source/CursesDialog/cmCursesMainForm.h | 2 +- Source/QtDialog/QCMake.cxx | 6 ++--- Source/QtDialog/QCMake.h | 2 +- Source/cmServer.cxx | 7 +++--- Source/cmServer.h | 2 +- Source/cmSystemTools.cxx | 6 ++--- Source/cmSystemTools.h | 8 ++----- Source/cmakemain.cxx | 25 ++++++++++++--------- 12 files changed, 35 insertions(+), 34 deletions(-) diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx index 2fd4c7ab32..3856569ea0 100644 --- a/Source/CTest/cmCTestBuildAndTestHandler.cxx +++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx @@ -118,7 +118,7 @@ public: : CM(cm) { cmSystemTools::SetMessageCallback( - [&s](const char* msg, const char* /*unused*/) { + [&s](const std::string& msg, const char* /*unused*/) { s += msg; s += "\n"; }); diff --git a/Source/CursesDialog/ccmake.cxx b/Source/CursesDialog/ccmake.cxx index f2982a62ca..745c6bb67e 100644 --- a/Source/CursesDialog/ccmake.cxx +++ b/Source/CursesDialog/ccmake.cxx @@ -150,7 +150,7 @@ int main(int argc, char const* const* argv) } cmSystemTools::SetMessageCallback( - [myform](const char* message, const char* title) { + [myform](const std::string& message, const char* title) { myform->AddError(message, title); }); diff --git a/Source/CursesDialog/cmCursesForm.h b/Source/CursesDialog/cmCursesForm.h index ddb67deeb3..78429059ed 100644 --- a/Source/CursesDialog/cmCursesForm.h +++ b/Source/CursesDialog/cmCursesForm.h @@ -9,6 +9,8 @@ #include "cmsys/FStream.hxx" +#include + class cmCursesForm { public: @@ -34,7 +36,7 @@ public: // Description: // During a CMake run, an error handle should add errors // to be displayed afterwards. - virtual void AddError(const char*, const char*) {} + virtual void AddError(const std::string&, const char*) {} // Description: // Turn debugging on. This will create ccmakelog.txt. diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx index 8ca7802f1f..f6a1a5795f 100644 --- a/Source/CursesDialog/cmCursesMainForm.cxx +++ b/Source/CursesDialog/cmCursesMainForm.cxx @@ -647,7 +647,8 @@ int cmCursesMainForm::Generate() return 0; } -void cmCursesMainForm::AddError(const char* message, const char* /*unused*/) +void cmCursesMainForm::AddError(const std::string& message, + const char* /*unused*/) { this->Errors.emplace_back(message); } diff --git a/Source/CursesDialog/cmCursesMainForm.h b/Source/CursesDialog/cmCursesMainForm.h index cc6482fd3a..c09ce2a92e 100644 --- a/Source/CursesDialog/cmCursesMainForm.h +++ b/Source/CursesDialog/cmCursesMainForm.h @@ -81,7 +81,7 @@ public: * During a CMake run, an error handle should add errors * to be displayed afterwards. */ - void AddError(const char* message, const char* title) override; + void AddError(const std::string& message, const char* title) override; /** * Used to do a configure. If argument is specified, it does only the check diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index a073c3064a..6442d05bab 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -25,7 +25,7 @@ QCMake::QCMake(QObject* p) cmSystemTools::SetRunCommandHideConsole(true); cmSystemTools::SetMessageCallback( - [this](const char* msg, const char* title) { + [this](std::string const& msg, const char* title) { this->messageCallback(msg, title); }); cmSystemTools::SetStdoutCallback( @@ -359,9 +359,9 @@ void QCMake::progressCallback(const char* msg, float percent) QCoreApplication::processEvents(); } -void QCMake::messageCallback(const char* msg, const char* /*title*/) +void QCMake::messageCallback(std::string const& msg, const char* /*title*/) { - emit this->errorMessage(QString::fromLocal8Bit(msg)); + emit this->errorMessage(QString::fromStdString(msg)); QCoreApplication::processEvents(); } diff --git a/Source/QtDialog/QCMake.h b/Source/QtDialog/QCMake.h index ef4d2a1a1e..8492606995 100644 --- a/Source/QtDialog/QCMake.h +++ b/Source/QtDialog/QCMake.h @@ -169,7 +169,7 @@ protected: bool interruptCallback(); void progressCallback(const char* msg, float percent); - void messageCallback(const char* msg, const char* title); + void messageCallback(std::string const& msg, const char* title); void stdoutCallback(std::string const& msg); void stderrCallback(std::string const& msg); diff --git a/Source/cmServer.cxx b/Source/cmServer.cxx index e740c0519b..719e6b13b0 100644 --- a/Source/cmServer.cxx +++ b/Source/cmServer.cxx @@ -97,7 +97,7 @@ void cmServer::ProcessRequest(cmConnection* connection, } cmSystemTools::SetMessageCallback( - [&request](const char* msg, const char* title) { + [&request](const std::string& msg, const char* title) { reportMessage(msg, title, request); }); @@ -165,15 +165,14 @@ void cmServer::reportProgress(const char* msg, float progress, } } -void cmServer::reportMessage(const char* msg, const char* title, +void cmServer::reportMessage(const std::string& msg, const char* title, const cmServerRequest& request) { - assert(msg); std::string titleString; if (title) { titleString = title; } - request.ReportMessage(std::string(msg), titleString); + request.ReportMessage(msg, titleString); } cmServerResponse cmServer::SetProtocolVersion(const cmServerRequest& request) diff --git a/Source/cmServer.h b/Source/cmServer.h index e1ed27a0c1..3edc887652 100644 --- a/Source/cmServer.h +++ b/Source/cmServer.h @@ -121,7 +121,7 @@ public: private: static void reportProgress(const char* msg, float progress, const cmServerRequest& request); - static void reportMessage(const char* msg, const char* title, + static void reportMessage(const std::string& msg, const char* title, const cmServerRequest& request); // Handle requests: diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 1d20e2f1ad..ec38b65312 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -323,16 +323,16 @@ void cmSystemTools::Stdout(const std::string& s) } } -void cmSystemTools::Message(const char* m1, const char* title) +void cmSystemTools::Message(const std::string& m, const char* title) { if (s_DisableMessages) { return; } if (s_MessageCallback) { - s_MessageCallback(m1, title); + s_MessageCallback(m, title); return; } - std::cerr << m1 << std::endl << std::flush; + std::cerr << m << std::endl << std::flush; } void cmSystemTools::ReportLastSystemError(const char* msg) diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 0f92fe2575..75860bc631 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -56,7 +56,7 @@ public: */ static std::string TrimWhitespace(const std::string& s); - using MessageCallback = std::function; + using MessageCallback = std::function; /** * Set the function used by GUIs to display error messages * Function gets passed: message as a const char*, @@ -74,11 +74,7 @@ public: /** * Display a message. */ - static void Message(const char* m, const char* title = nullptr); - static void Message(const std::string& m, const char* title = nullptr) - { - Message(m.c_str(), title); - } + static void Message(const std::string& m, const char* title = nullptr); using OutputCallback = std::function; diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 890b74e0f2..a49246bfc6 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -142,8 +142,8 @@ static std::string cmakemainGetStack(cmake* cm) return msg; } -static void cmakemainMessageCallback(const char* m, const char* /*unused*/, - cmake* cm) +static void cmakemainMessageCallback(const std::string& m, + const char* /*unused*/, cmake* cm) { std::cerr << m << cmakemainGetStack(cm) << std::endl << std::flush; } @@ -319,9 +319,10 @@ int do_cmake(int ac, char const* const* av) cmake cm(role, mode); cm.SetHomeDirectory(""); cm.SetHomeOutputDirectory(""); - cmSystemTools::SetMessageCallback([&cm](const char* msg, const char* title) { - cmakemainMessageCallback(msg, title, &cm); - }); + cmSystemTools::SetMessageCallback( + [&cm](const std::string& msg, const char* title) { + cmakemainMessageCallback(msg, title, &cm); + }); cm.SetProgressCallback([&cm](const char* msg, float prog) { cmakemainProgressCallback(msg, prog, &cm); }); @@ -499,9 +500,10 @@ static int do_build(int ac, char const* const* av) } cmake cm(cmake::RoleInternal, cmState::Unknown); - cmSystemTools::SetMessageCallback([&cm](const char* msg, const char* title) { - cmakemainMessageCallback(msg, title, &cm); - }); + cmSystemTools::SetMessageCallback( + [&cm](const std::string& msg, const char* title) { + cmakemainMessageCallback(msg, title, &cm); + }); cm.SetProgressCallback([&cm](const char* msg, float prog) { cmakemainProgressCallback(msg, prog, &cm); }); @@ -541,9 +543,10 @@ static int do_open(int ac, char const* const* av) } cmake cm(cmake::RoleInternal, cmState::Unknown); - cmSystemTools::SetMessageCallback([&cm](const char* msg, const char* title) { - cmakemainMessageCallback(msg, title, &cm); - }); + cmSystemTools::SetMessageCallback( + [&cm](const std::string& msg, const char* title) { + cmakemainMessageCallback(msg, title, &cm); + }); cm.SetProgressCallback([&cm](const char* msg, float prog) { cmakemainProgressCallback(msg, prog, &cm); });