File size: 4,666 Bytes
8cf4ead
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifndef __CLIENT_LOGGING_HPP__
#define __CLIENT_LOGGING_HPP__
#include <iomanip>
#include <iostream>
#include <ostream>
#include <sstream>

namespace ManusSDK
{
	class ClientLog
	{
	public:
		//Simple
		static void debug(const char* p_String)
		{
			std::cout << "DEBUG: " << p_String << std::endl;
		}

		static void info(const char* p_String)
		{
			std::cout << "INFO: " << p_String << std::endl;
		}

		static void warn(const char* p_String)
		{
			std::cout << "WARN: " << p_String << std::endl;
		}

		static void error(const char* p_String)
		{
			std::cout << "ERROR: " << p_String << std::endl;
		}

		static void print(const char* p_String)
		{
			std::cout << p_String << std::endl;
		}

		//Templated
		template<typename... Args>
		static void debug(const char* p_Format, Args &&...p_Args)
		{
			std::string formatted_string = p_Format;
			replacePlaceholders(formatted_string, std::forward<Args>(p_Args)...);
			std::cout << "DEBUG: " << formatted_string << std::endl;
		}

		template<typename... Args>
		static void info(const char* p_Format, Args &&...p_Args)
		{
			std::string formatted_string = p_Format;
			replacePlaceholders(formatted_string, std::forward<Args>(p_Args)...);
			std::cout << "INFO: " << formatted_string << std::endl;
		}

		template<typename... Args>
		static void warn(const char* p_Format, Args &&...p_Args)
		{
			std::string formatted_string = p_Format;
			replacePlaceholders(formatted_string, std::forward<Args>(p_Args)...);
			std::cout << "WARN: " << formatted_string << std::endl;
		}

		template<typename... Args>
		static void error(const char* p_Format, Args &&...p_Args)
		{
			std::string formatted_string = p_Format;
			replacePlaceholders(formatted_string, std::forward<Args>(p_Args)...);
			std::cout << "ERROR: " << formatted_string << std::endl;
		}
		
		template<typename... Args>
		static void print(const char* p_Format, Args &&...p_Args)
		{
			std::string formatted_string = p_Format;
			replacePlaceholders(formatted_string, std::forward<Args>(p_Args)...);
			std::cout << formatted_string << std::endl;
		}

		template<typename... Args>
		static void printWithPadding(const char* p_Format, int p_Padding, Args &&...p_Args)
		{
			std::string formatted_string = p_Format;
			replacePlaceholdersWithPadding(formatted_string, p_Padding, std::forward<Args>(p_Args)...);
			std::cout << formatted_string << std::endl;
		}

	private:
		// Base case for recursion: no arguments left
		static void replacePlaceholders(std::string&) {
			// No more arguments, so nothing to replace
		}

		// Replace placeholders {} with actual values (only supports empty curly brackets, no formatting)
		template<typename T, typename... Args>
		static void replacePlaceholders(std::string& p_Format, T&& p_Value, Args&&... p_Args) {
			size_t pos = p_Format.find("{}");
			if (pos != std::string::npos) {
				p_Format.replace(pos, 2, to_string(std::forward<T>(p_Value)));
				replacePlaceholders(p_Format, std::forward<Args>(p_Args)...);
			}
		}

		// Base case for recursion: no arguments left
		static void replacePlaceholdersWithPadding(std::string&, int p_Padding) {
			// No more arguments, so nothing to replace
		}
		// Replace placeholders {} with actual values (only supports empty curly brackets, no formatting)
		template<typename T, typename... Args>
		static void replacePlaceholdersWithPadding(std::string& p_Format, int p_Padding, T&& p_Value, Args&&... p_Args) {
			size_t pos = p_Format.find("{}");
			if (pos != std::string::npos) {
				std::ostringstream oss;
				oss << std::setw(p_Padding) << to_string(std::forward<T>(p_Value));
				p_Format.replace(pos, 2, oss.str());
				replacePlaceholdersWithPadding(p_Format, p_Padding, std::forward<Args>(p_Args)...);
			}
		}

		// Utility to convert various types to string
		template<typename T>
		static std::string to_string(const T& p_Value) {
			std::ostringstream oss;
			oss << p_Value;
			return oss.str();
		}

		// Specialization for uint8_t
		static std::string to_string(const uint8_t& p_Value) {
			std::ostringstream oss;
			oss << static_cast<int>(p_Value);
			return oss.str();
		}

		// Specialization for uint16_t
		static std::string to_string(const uint16_t& p_Value) {
			std::ostringstream oss;
			oss << static_cast<int>(p_Value);
			return oss.str();
		}

		// Specialization for uint32_t
		static std::string to_string(const uint32_t& p_Value) {
			std::ostringstream oss;
			oss << std::hex << p_Value;
			return oss.str();
		}

		// Specialization for bool
		static std::string to_string(const bool& p_Value) {
			std::ostringstream oss;
			oss << std::setw(5) << (p_Value ? "true" : "false");
			return oss.str();
		}
	};
}

#endif