summaryrefslogtreecommitdiffstats
path: root/Source/CTest/cmCTestBuildAndTestHandler.cxx
diff options
context:
space:
mode:
authorRegina Pfeifer <regina@mailbox.org>2019-01-25 20:31:33 (GMT)
committerRegina Pfeifer <regina@mailbox.org>2019-01-29 15:32:52 (GMT)
commitbcee24aecc1eaf6615eac9f24ae06acdf38845d3 (patch)
tree7a5ce493d66e1ff9a154bbd7503bd6e646624444 /Source/CTest/cmCTestBuildAndTestHandler.cxx
parent9620cb935a49e7b4955f5b1d0ffa2e93b4327591 (diff)
downloadCMake-bcee24aecc1eaf6615eac9f24ae06acdf38845d3.zip
CMake-bcee24aecc1eaf6615eac9f24ae06acdf38845d3.tar.gz
CMake-bcee24aecc1eaf6615eac9f24ae06acdf38845d3.tar.bz2
Use `std::function` for callbacks
Diffstat (limited to 'Source/CTest/cmCTestBuildAndTestHandler.cxx')
-rw-r--r--Source/CTest/cmCTestBuildAndTestHandler.cxx50
1 files changed, 21 insertions, 29 deletions
diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx
index 312d126..d6f0d18 100644
--- a/Source/CTest/cmCTestBuildAndTestHandler.cxx
+++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx
@@ -109,27 +109,6 @@ int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring,
return 0;
}
-void CMakeMessageCallback(const char* m, const char* /*unused*/,
- bool& /*unused*/, void* s)
-{
- std::string* out = static_cast<std::string*>(s);
- *out += m;
- *out += "\n";
-}
-
-void CMakeProgressCallback(const char* msg, float /*unused*/, void* s)
-{
- std::string* out = static_cast<std::string*>(s);
- *out += msg;
- *out += "\n";
-}
-
-void CMakeOutputCallback(const char* m, size_t len, void* s)
-{
- std::string* out = static_cast<std::string*>(s);
- out->append(m, len);
-}
-
class cmCTestBuildAndTestCaptureRAII
{
cmake& CM;
@@ -138,17 +117,30 @@ public:
cmCTestBuildAndTestCaptureRAII(cmake& cm, std::string& s)
: CM(cm)
{
- cmSystemTools::SetMessageCallback(CMakeMessageCallback, &s);
- cmSystemTools::SetStdoutCallback(CMakeOutputCallback, &s);
- cmSystemTools::SetStderrCallback(CMakeOutputCallback, &s);
- this->CM.SetProgressCallback(CMakeProgressCallback, &s);
+ cmSystemTools::SetMessageCallback(
+ [&s](const char* msg, const char* /*unused*/, bool& /*unused*/) {
+ s += msg;
+ s += "\n";
+ });
+
+ cmSystemTools::SetStdoutCallback(
+ [&s](const char* m, size_t len) { s.append(m, len); });
+
+ cmSystemTools::SetStderrCallback(
+ [&s](const char* m, size_t len) { s.append(m, len); });
+
+ this->CM.SetProgressCallback([&s](const char* msg, float /*unused*/) {
+ s += msg;
+ s += "\n";
+ });
}
+
~cmCTestBuildAndTestCaptureRAII()
{
- this->CM.SetProgressCallback(nullptr, nullptr);
- cmSystemTools::SetStderrCallback(nullptr, nullptr);
- cmSystemTools::SetStdoutCallback(nullptr, nullptr);
- cmSystemTools::SetMessageCallback(nullptr, nullptr);
+ this->CM.SetProgressCallback(nullptr);
+ cmSystemTools::SetStderrCallback(nullptr);
+ cmSystemTools::SetStdoutCallback(nullptr);
+ cmSystemTools::SetMessageCallback(nullptr);
}
};