1 #pragma once
2 
3 #include <string>
4 #include <sstream>
5 
6 namespace wf
7 {
8 namespace log
9 {
10 /**
11  * Convert the given parameter to a string which can be logged.
12  * This function can be specialized for custom types.
13  */
14 template<class T>
to_string(T arg)15 std::string to_string(T arg)
16 {
17     std::ostringstream out;
18     out << arg;
19     return out.str();
20 }
21 
22 /** Specialization for boolean arguments - print true or false. */
23 template<>
24 std::string to_string(bool arg);
25 
26 /* Specialization for pointers - print the address */
27 template<class T>
to_string(T * arg)28 std::string to_string(T *arg)
29 {
30     if (!arg)
31     {
32         return "(null)";
33     }
34 
35     return to_string<T*>(arg);
36 }
37 
38 namespace detail
39 {
40 /**
41  * Convert each argument to a string and then concatenate them.
42  */
43 template<class First>
format_concat(First arg)44 std::string format_concat(First arg)
45 {
46     return wf::log::to_string(arg);
47 }
48 
49 template<class First, class... Args>
format_concat(First first,Args...args)50 std::string format_concat(First first, Args... args)
51 {
52     return format_concat(first) + format_concat(args...);
53 }
54 }
55 }
56 }
57