OpenAstra
 
Loading...
Searching...
No Matches
debugprint.hpp
1#ifndef DEBUGPRINT_H
2#define DEBUGPRINT_H
3
4#include <iostream>
5#include <string>
6
7#include "../utils/json.hpp"
8
9class DebugPrint
10{
11public:
12 DebugPrint()
13 : _string() {}
14
15 ~DebugPrint(){
16 std::cout << _string << std::endl;
17 }
18
19 DebugPrint& operator << ( char* value ){
20 _string += std::string( value );
21 return *this;
22 }
23
24 DebugPrint& operator << ( const char* value ){
25 _string += std::string( value );
26 return *this;
27 }
28
29 DebugPrint& operator << ( const std::string& value ){
30 _string += std::string( value );
31 return *this;
32 }
33
34 template<typename T>
35 DebugPrint& operator << ( const T& value ){
36 _string += std::to_string( value );
37 return *this;
38 }
39
40 DebugPrint& operator << ( const nlohmann::json::parse_error& error ) {
41 _string += std::string("JSON Parse Error: '") + error.what() + "' at byte " + std::to_string(error.byte) + " (" + std::to_string(error.id) + ")";
42 return *this;
43 }
44
45 DebugPrint& operator << ( const nlohmann::json& json ) {
46 _string += json.dump();
47 return *this;
48 }
49
50private:
51 std::string _string;
52};
53
54#endif // DEBUGPRINT_H