@@ -45,71 +45,61 @@ class ValidateSchema : public Operator {
4545
4646
4747 static void error_load (void *ctx, const char *msg, ...) {
48- std::string *t = reinterpret_cast <std::string *>(ctx);
49- char buf[1024 ];
5048 va_list args;
51-
5249 va_start (args, msg);
53- int len = vsnprintf (buf, sizeof (buf) , msg, args);
50+ callback_func (ctx, append_msg, PREFIX_ERROR , msg, args);
5451 va_end (args);
55-
56- if (len > 0 ) {
57- t->append (" XML Error: " + std::string (buf));
58- }
5952 }
6053
6154
6255 static void warn_load (void *ctx, const char *msg, ...) {
63- std::string *t = reinterpret_cast <std::string *>(ctx);
64- char buf[1024 ];
6556 va_list args;
66-
6757 va_start (args, msg);
68- int len = vsnprintf (buf, sizeof (buf) , msg, args);
58+ callback_func (ctx, append_msg, PREFIX_WARNING , msg, args);
6959 va_end (args);
70-
71- if (len > 0 ) {
72- t->append (" XML Warning: " + std::string (buf));
73- }
7460 }
7561
7662
7763 static void error_runtime (void *ctx, const char *msg, ...) {
78- const Transaction *t = reinterpret_cast <Transaction *>(ctx);
79- char buf[1024 ];
80- std::string s;
8164 va_list args;
82-
8365 va_start (args, msg);
84- int len = vsnprintf (buf, sizeof (buf) , msg, args);
66+ callback_func (ctx, log_msg, PREFIX_ERROR , msg, args);
8567 va_end (args);
86-
87- if (len > 0 ) {
88- s = " XML Error: " + std::string (buf);
89- }
90- ms_dbg_a (t, 4 , s);
9168 }
9269
9370
9471 static void warn_runtime (void *ctx, const char *msg, ...) {
95- const Transaction *t = reinterpret_cast <Transaction *>(ctx);
96- char buf[1024 ];
97- std::string s;
9872 va_list args;
99-
10073 va_start (args, msg);
101- int len = vsnprintf (buf, sizeof (buf) , msg, args);
74+ callback_func (ctx, log_msg, PREFIX_WARNING , msg, args);
10275 va_end (args);
76+ }
10377
104- if (len > 0 ) {
105- s = " XML Warning: " + std::string (buf);
106- }
107- ms_dbg_a (t, 4 , s);
78+ static void null_error (void *, const char *, ...) { // cppcheck-suppress[constParameterPointer,constParameterCallback]
10879 }
10980
110- static void null_error (void *ctx, const char *msg, ...) { // cppcheck-suppress[constParameterPointer,constParameterCallback]
81+ template <typename Pred>
82+ static void callback_func (void *ctx, Pred pred, const char *base_msg, const char *msg, va_list args) {
83+ char buf[1024 ];
84+ const auto len = vsnprintf (buf, sizeof (buf), msg, args);
85+
86+ if (len > 0 )
87+ pred (ctx, base_msg + std::string (buf));
11188 }
11289
90+ static void log_msg (void *ctx, const std::string &msg) {
91+ auto t = reinterpret_cast <Transaction *>(ctx);
92+ ms_dbg_a (t, 4 , msg);
93+ }
94+
95+ static void append_msg (void *ctx, const std::string &msg) {
96+ auto s = reinterpret_cast <std::string*>(ctx);
97+ s->append (msg);
98+ }
99+
100+ static constexpr auto PREFIX_WARNING = " XML Warning: " ;
101+ static constexpr auto PREFIX_ERROR = " XML Error: " ;
102+
113103 private:
114104 std::string m_resource;
115105 std::string m_err;
0 commit comments