aboutsummaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-04-15 15:51:40 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-04-15 15:51:40 +0200
commitb25a939e2d8b045c083caf3264c4e5aac1cf88fb (patch)
tree37b862c82389ceddcf4624b5e26536390d6b8265 /cpp
parentb02c083a3545b6e6b36ab62680128edec619a804 (diff)
downloadnissy-core-b25a939e2d8b045c083caf3264c4e5aac1cf88fb.tar.gz
nissy-core-b25a939e2d8b045c083caf3264c4e5aac1cf88fb.zip
Better logging function
Now it is possible to provide some data together with the logging function. This is useful for example in C++, where I can now provide an arbitrary callable object as data, and a simple wrapper function that call the callable object as logging function.
Diffstat (limited to '')
-rw-r--r--cpp/examples/solve_h48h3k2.cpp2
-rw-r--r--cpp/nissy.cpp7
-rw-r--r--cpp/nissy.h2
3 files changed, 7 insertions, 4 deletions
diff --git a/cpp/examples/solve_h48h3k2.cpp b/cpp/examples/solve_h48h3k2.cpp
index 454d6dc..7f06376 100644
--- a/cpp/examples/solve_h48h3k2.cpp
+++ b/cpp/examples/solve_h48h3k2.cpp
@@ -8,7 +8,7 @@
8 8
9int main() { 9int main() {
10 // Get verbose output 10 // Get verbose output
11 nissy::set_logger([](const char* s) { std::cout << s; }); 11 nissy::set_logger([](const char* s, void *u) { std::cout << s; }, NULL);
12 12
13 // Get the scramble from the user 13 // Get the scramble from the user
14 std::cout << "Enter scramble: "; 14 std::cout << "Enter scramble: ";
diff --git a/cpp/nissy.cpp b/cpp/nissy.cpp
index 2a52ab1..944944b 100644
--- a/cpp/nissy.cpp
+++ b/cpp/nissy.cpp
@@ -24,7 +24,7 @@ extern "C" {
24 unsigned, unsigned, int, int, unsigned long long, const char *, 24 unsigned, unsigned, int, int, unsigned long long, const char *,
25 unsigned, char *, long long *); 25 unsigned, char *, long long *);
26 long long nissy_countmoves(const char *); 26 long long nissy_countmoves(const char *);
27 long long nissy_setlogger(void (*)(const char *)); 27 long long nissy_setlogger(void (*)(const char *, void *), void *);
28} 28}
29 29
30namespace nissy { 30namespace nissy {
@@ -227,5 +227,8 @@ namespace nissy {
227 return error{err}; 227 return error{err};
228 } 228 }
229 229
230 void set_logger(void (*log)(const char *)) { nissy_setlogger(log); } 230 void set_logger(void (*log)(const char *, void *), void *data)
231 {
232 nissy_setlogger(log, data);
233 }
231} 234}
diff --git a/cpp/nissy.h b/cpp/nissy.h
index ff74f12..db8ba5f 100644
--- a/cpp/nissy.h
+++ b/cpp/nissy.h
@@ -100,7 +100,7 @@ namespace nissy {
100 }; 100 };
101 101
102 error count_moves(const std::string&); 102 error count_moves(const std::string&);
103 void set_logger(void (*)(const char*)); 103 void set_logger(void (*)(const char *, void *), void *);
104} 104}
105 105
106#endif 106#endif

Generated with cgit - Back to sebastiano.tronto.net