Pcannon Debug 1.0.0-build
Simple yet powerful debug manager for C++
Loading...
Searching...
No Matches
Debug.hpp
Go to the documentation of this file.
1#pragma once
2
3#if __cplusplus >= 201103L
4#if __cplusplus < 201703L
5# ifdef __PD_NO_FULL_SUPPORT
6# undef __PD_NO_FULL_SUPPORT
7# endif
8# define __PD_NO_FULL_SUPPORT
9# warning "No full support for the current C++ standard (Full Support is in C++17)"
10#endif
11
12#include <string>
13#include <fstream>
14#include <utility>
15
16namespace pd
17{
18 /**
19 * @brief Set debug settings struct with set values, default are already set for the best output
20 */
21 typedef struct DebugSettings
22 {
23 bool timeStamp = true;
24 bool debugID = true;
25 bool timeZone = false;
26 bool output = true;
27 bool blockedSave = false;
28 bool custom = false;
30 bool logLevelIgnoreSave = false;
31
32 unsigned int logLevel = 0;
33
34 std::string filePath;
35 std::string startMsg;
36 std::string preStartMsg;
37 std::string endMsg;
38 std::string postEndMsg;
39 std::string totalEndMsg;
40 std::string totalCustom;
41
42 std::ios::openmode openMode = std::fstream::app | std::fstream::in | std::fstream::out;
44
45 class Debug
46 {
47 private:
48 std::string id;
49
50 std::fstream *file;
51
53
55 std::string constructError;
56
57 /**
58 * @brief Initialize the Debug object that is going (or was) to be constructed
59 * @return bool Did it fail? True = Success, False = Failiture
60 */
61 bool __init();
62
63 public:
64 /**
65 * @brief Construct the debugger with specified ID and settings
66 * Call the inner `__init()` function to Initialize
67 * @param _id Set the ID of this object
68 * @param _settings Set the settings of this object
69 */
70 Debug(const std::string &_id, const pd::DebugSettings &_settings);
71
72 /**
73 * @brief Call the `pd::Debug::close()` function to free all allocated memory
74 */
75 ~Debug();
76
77 /**
78 * @brief Free all the allocated memory and resources, return true if it succeeded, return false if it did not
79 * @return bool True if success, false if failiture
80 */
81 bool close();
82
83 /**
84 * @brief Construct debug information
85 * You can use it if it failed to construct properly to get the error message
86 * @return std::pair<bool, std::string> .first: Did it succeed? .second: Error reason
87 */
88 std::pair<bool, std::string> constructInfo();
89
90 /**
91 * @brief Log the message with specific custom type, message and log level
92 * @param _type Set the type of the debug message (Ex: Information, Success, Warning, Error, ...)
93 * @param _msg Set the message for debugging
94 * @param _level Set the debug level level of the log (default as 0, non-debug-level specific)
95 * @return The total string of the total debug message
96 */
97 std::string log(const std::string &_type, const std::string &_msg, unsigned int _level = 0);
98
99 /**
100 * @brief Return the ID of the created Debug object
101 * @return std::string The ID of this object
102 */
103 std::string getID() const;
104
105 /**
106 * @brief Get file for more control over the processing and for more actions
107 * @return std::fstream Allocated file to Debug object
108 */
109 std::fstream *getFile() const;
110
111 /**
112 * @brief Get the settings set for the created Debug object
113 * @return pd::DebugSettings Debug settings to return
114 */
116 };
117}
118#else
119# include "../inc/macros.hpp"
120# warn "Must use C++11 or later"
121#endif // __cplusplus
122
std::fstream * getFile() const
Get file for more control over the processing and for more actions.
Definition Debug.cpp:143
std::string constructError
Definition Debug.hpp:55
DebugSettings getSettings() const
Get the settings set for the created Debug object.
Definition Debug.cpp:146
~Debug()
Call the pd::Debug::close() function to free all allocated memory.
Definition Debug.cpp:51
std::string getID() const
Return the ID of the created Debug object.
Definition Debug.cpp:140
std::string log(const std::string &_type, const std::string &_msg, unsigned int _level=0)
Log the message with specific custom type, message and log level.
Definition Debug.cpp:56
const DebugSettings settings
Definition Debug.hpp:52
std::fstream * file
Definition Debug.hpp:50
bool __init()
Initialize the Debug object that is going (or was) to be constructed.
Definition Debug.cpp:17
std::string id
Definition Debug.hpp:48
Debug(const std::string &_id, const pd::DebugSettings &_settings)
Construct the debugger with specified ID and settings Call the inner __init() function to Initialize.
Definition Debug.cpp:42
bool constructed
Definition Debug.hpp:54
std::pair< bool, std::string > constructInfo()
Construct debug information You can use it if it failed to construct properly to get the error messag...
Definition Debug.cpp:137
bool close()
Free all the allocated memory and resources, return true if it succeeded, return false if it did not.
Definition Debug.cpp:123
Definition Debug.hpp:17
struct pd::DebugSettings DebugSettings
Set debug settings struct with set values, default are already set for the best output.
Set debug settings struct with set values, default are already set for the best output.
Definition Debug.hpp:22
std::string preStartMsg
Definition Debug.hpp:36
std::string postEndMsg
Definition Debug.hpp:38
std::string totalCustom
Definition Debug.hpp:40
std::string endMsg
Definition Debug.hpp:37
std::string totalEndMsg
Definition Debug.hpp:39
std::string filePath
Definition Debug.hpp:34
bool logLevelIgnoreSave
Definition Debug.hpp:30
bool logLevelIgnoreOutput
Definition Debug.hpp:29
std::ios::openmode openMode
Definition Debug.hpp:42
std::string startMsg
Definition Debug.hpp:35
unsigned int logLevel
Definition Debug.hpp:32