Add appendIf(..) method and tests for MessageStringCollector
[alexxy/gromacs.git] / src / gromacs / utility / message_string_collector.cpp
similarity index 90%
rename from src/gromacs/utility/messagestringcollector.cpp
rename to src/gromacs/utility/message_string_collector.cpp
index 306838627d585e145ca5354f9fa4e52e9411925e..a956bd904889a58146b43aa480f2010ee51786c8 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012,2014,2016,2019, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2014,2016,2019,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -41,7 +41,7 @@
  */
 #include "gmxpre.h"
 
-#include "messagestringcollector.h"
+#include "message_string_collector.h"
 
 #include <vector>
 
@@ -101,6 +101,22 @@ void MessageStringCollector::append(const std::string& message)
     }
 }
 
+void MessageStringCollector::appendIf(bool condition, const char* message)
+{
+    if (condition)
+    {
+        append(std::string(message));
+    }
+}
+
+void MessageStringCollector::appendIf(bool condition, const std::string& message)
+{
+    if (condition)
+    {
+        append(message);
+    }
+}
+
 void MessageStringCollector::finishContext()
 {
     GMX_RELEASE_ASSERT(!impl_->contexts_.empty(), "finishContext() called without context");