pmt: reformat code, etc.
This commit is contained in:
@@ -82,8 +82,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// A class for function management.
|
// A class for function management.
|
||||||
template <class _Type>
|
template <class _Type> class basic_manager {
|
||||||
class basic_manager {
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::unique_ptr<_Type>> _functions;
|
std::vector<std::unique_ptr<_Type>> _functions;
|
||||||
|
|
||||||
@@ -127,8 +126,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool handleAll() const {
|
[[nodiscard]] bool handleAll() const {
|
||||||
LOGN(PMTF, INFO) << "running caught commands in command-line."
|
LOGN(PMTF, INFO) << "running caught commands in command-line." << std::endl;
|
||||||
<< std::endl;
|
|
||||||
for (const auto &func : _functions) {
|
for (const auto &func : _functions) {
|
||||||
if (func->isUsed()) {
|
if (func->isUsed()) {
|
||||||
LOGN(PMTF, INFO) << func->name()
|
LOGN(PMTF, INFO) << func->name()
|
||||||
|
|||||||
@@ -60,17 +60,29 @@ constexpr int YES = 1;
|
|||||||
constexpr int NO = 0;
|
constexpr int NO = 0;
|
||||||
|
|
||||||
namespace Helper {
|
namespace Helper {
|
||||||
|
// Throwable error class
|
||||||
|
class Error final : public std::exception {
|
||||||
|
private:
|
||||||
|
std::string _message;
|
||||||
|
std::ostringstream _oss;
|
||||||
|
|
||||||
|
public:
|
||||||
|
__attribute__((format(printf, 2, 3))) explicit Error(const char *format, ...);
|
||||||
|
|
||||||
|
[[nodiscard]] const char *what() const noexcept override;
|
||||||
|
};
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
class Logger final {
|
class Logger final {
|
||||||
private:
|
private:
|
||||||
LogLevels _level;
|
LogLevels _level;
|
||||||
std::ostringstream _oss;
|
std::ostringstream _oss;
|
||||||
const char *_funcname, *_logFile, *_program_name, *_file;
|
const char *_function_name, *_logFile, *_program_name, *_file;
|
||||||
int _line;
|
int _line;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Logger(LogLevels level, const char *func, const char *file, const char *name,
|
Logger(LogLevels level, const char *func, const char *file, const char *name,
|
||||||
const char *sfile, int line);
|
const char *source_file, int line);
|
||||||
|
|
||||||
~Logger();
|
~Logger();
|
||||||
|
|
||||||
@@ -82,17 +94,6 @@ public:
|
|||||||
Logger &operator<<(std::ostream &(*msg)(std::ostream &));
|
Logger &operator<<(std::ostream &(*msg)(std::ostream &));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Throwable error class
|
|
||||||
class Error final : public std::exception {
|
|
||||||
private:
|
|
||||||
std::string _message;
|
|
||||||
|
|
||||||
public:
|
|
||||||
__attribute__((format(printf, 2, 3))) explicit Error(const char *format, ...);
|
|
||||||
|
|
||||||
[[nodiscard]] const char *what() const noexcept override;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Close file descriptors and delete allocated array memory
|
// Close file descriptors and delete allocated array memory
|
||||||
class garbageCollector {
|
class garbageCollector {
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ Error::Error(const char *format, ...) {
|
|||||||
const char *Error::what() const noexcept { return _message.data(); }
|
const char *Error::what() const noexcept { return _message.data(); }
|
||||||
|
|
||||||
Logger::Logger(const LogLevels level, const char *func, const char *file,
|
Logger::Logger(const LogLevels level, const char *func, const char *file,
|
||||||
const char *name, const char *sfile, const int line)
|
const char *name, const char *source_file, const int line)
|
||||||
: _level(level), _funcname(func), _logFile(file), _program_name(name),
|
: _level(level), _function_name(func), _logFile(file), _program_name(name),
|
||||||
_file(sfile), _line(line) {}
|
_file(source_file), _line(line) {}
|
||||||
|
|
||||||
Logger::~Logger() {
|
Logger::~Logger() {
|
||||||
if (LoggingProperties::DISABLE) return;
|
if (LoggingProperties::DISABLE) return;
|
||||||
@@ -52,7 +52,7 @@ Logger::~Logger() {
|
|||||||
snprintf(str, sizeof(str), "<%c> [ <prog %s> <on %s:%d> %s %s] %s(): %s",
|
snprintf(str, sizeof(str), "<%c> [ <prog %s> <on %s:%d> %s %s] %s(): %s",
|
||||||
static_cast<char>(_level), _program_name,
|
static_cast<char>(_level), _program_name,
|
||||||
basename(const_cast<char *>(_file)), _line, currentDate().data(),
|
basename(const_cast<char *>(_file)), _line, currentDate().data(),
|
||||||
currentTime().data(), _funcname, _oss.str().data());
|
currentTime().data(), _function_name, _oss.str().data());
|
||||||
|
|
||||||
if (!isExists(_logFile)) {
|
if (!isExists(_logFile)) {
|
||||||
if (const int fd =
|
if (const int fd =
|
||||||
|
|||||||
Reference in New Issue
Block a user