summaryrefslogtreecommitdiffstats
path: root/src/cppc4group.cpp
diff options
context:
space:
mode:
authorMarkus Mittendrein <git@maxmitti.tk>2019-08-19 13:42:48 +0200
committerMarkus Mittendrein <git@maxmitti.tk>2019-08-19 18:56:58 +0200
commit177c2d8c1ed33391711524948fef5313c8624c75 (patch)
tree6bf8d0e17b2f6c2d69d77b611213139adbc74b9d /src/cppc4group.cpp
parent228bce0f6612044a18569919798d7e89e18a29c8 (diff)
downloadcc4group-177c2d8c1ed33391711524948fef5313c8624c75.tar.gz
cc4group-177c2d8c1ed33391711524948fef5313c8624c75.zip
Allow the warning handling callback to be set to a custom callback
Diffstat (limited to 'src/cppc4group.cpp')
-rw-r--r--src/cppc4group.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/cppc4group.cpp b/src/cppc4group.cpp
index bacf1f7..99d5e41 100644
--- a/src/cppc4group.cpp
+++ b/src/cppc4group.cpp
@@ -2,6 +2,8 @@
#include "cc4group.h"
+#include <cstdarg>
+
CppC4Group::Data::Data() : data{nullptr}, size{0}
{
@@ -333,6 +335,36 @@ void CppC4Group::setTmpMemoryStrategy(const TmpMemoryCallback callback)
cc4group.setTmpMemoryStrategy(customTmpMemoryStrategy);
}
+namespace {
+
+ CppC4Group::WarningCallback cppc4group_warningCallback;
+ void CppC4Group_CustomWarningCallback(const CC4Group* const, const char* const format, ...)
+ {
+ va_list ap;
+ va_start(ap, format);
+ int size = std::vsnprintf(nullptr, 0, format, ap) + 1;
+ std::string message;
+ message.resize(size);
+ std::vsnprintf(message.data(), size, format, ap);
+ message.resize(size - 1);
+ va_end (ap);
+ cppc4group_warningCallback(message);
+ }
+}
+
+void CppC4Group::setWarningCallback(const CppC4Group::WarningCallback callback)
+{
+ if(callback == nullptr)
+ {
+ cc4group.setWarningCallback(nullptr);
+ }
+ else
+ {
+ cppc4group_warningCallback = callback;
+ cc4group.setWarningCallback(CppC4Group_CustomWarningCallback);
+ }
+}
+
bool CppC4Group::setMaker(const std::string& maker, const std::string& path, const bool recursive)
{
return cc4group.setMaker(p->g, maker.c_str(), path.c_str(), recursive);