@@ -45,71 +45,63 @@ class ValidateSchema : public Operator {
45
45
46
46
47
47
static void error_load (void *ctx, const char *msg, ...) {
48
- std::string *t = reinterpret_cast <std::string *>(ctx);
49
- char buf[1024 ];
50
48
va_list args;
51
-
52
49
va_start (args, msg);
53
- int len = vsnprintf (buf, sizeof (buf) , msg, args);
50
+ callback_func (ctx, append_msg, PREFIX_ERROR , msg, args);
54
51
va_end (args);
55
-
56
- if (len > 0 ) {
57
- t->append (" XML Error: " + std::string (buf));
58
- }
59
52
}
60
53
61
54
62
55
static void warn_load (void *ctx, const char *msg, ...) {
63
- std::string *t = reinterpret_cast <std::string *>(ctx);
64
- char buf[1024 ];
65
56
va_list args;
66
-
67
57
va_start (args, msg);
68
- int len = vsnprintf (buf, sizeof (buf) , msg, args);
58
+ callback_func (ctx, append_msg, PREFIX_WARNING , msg, args);
69
59
va_end (args);
70
-
71
- if (len > 0 ) {
72
- t->append (" XML Warning: " + std::string (buf));
73
- }
74
60
}
75
61
76
62
77
63
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;
81
64
va_list args;
82
-
83
65
va_start (args, msg);
84
- int len = vsnprintf (buf, sizeof (buf) , msg, args);
66
+ callback_func (ctx, log_msg, PREFIX_ERROR , msg, args);
85
67
va_end (args);
86
-
87
- if (len > 0 ) {
88
- s = " XML Error: " + std::string (buf);
89
- }
90
- ms_dbg_a (t, 4 , s);
91
68
}
92
69
93
70
94
71
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;
98
72
va_list args;
99
-
100
73
va_start (args, msg);
101
- int len = vsnprintf (buf, sizeof (buf) , msg, args);
74
+ callback_func (ctx, log_msg, PREFIX_WARNING , msg, args);
102
75
va_end (args);
76
+ }
77
+
78
+ static void null_error (void *ctx, const char *msg, ...) { // cppcheck-suppress[constParameterPointer,constParameterCallback]
79
+ }
80
+
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);
103
85
104
86
if (len > 0 ) {
105
- s = " XML Warning: " + std::string (buf);
87
+ const auto msg = base_msg + std::string (buf);
88
+ pred (ctx, msg);
106
89
}
107
- ms_dbg_a (t, 4 , s);
108
90
}
109
91
110
- static void null_error (void *ctx, const char *msg, ...) { // cppcheck-suppress[constParameterPointer,constParameterCallback]
92
+ static void log_msg (void *ctx, const std::string &msg) {
93
+ auto t = reinterpret_cast <const Transaction *>(ctx);
94
+ ms_dbg_a (t, 4 , msg);
111
95
}
112
96
97
+ static void append_msg (void *ctx, const std::string &msg) {
98
+ auto s = reinterpret_cast <std::string*>(ctx);
99
+ s->append (msg);
100
+ }
101
+
102
+ static constexpr auto PREFIX_WARNING = " XML Warning: " ;
103
+ static constexpr auto PREFIX_ERROR = " XML Error: " ;
104
+
113
105
private:
114
106
std::string m_resource;
115
107
std::string m_err;
0 commit comments