mmCEsim 0.3.0
mmWave Channel Estimation Simulation
error_code.h
Go to the documentation of this file.
1
12#ifndef _ERROR_CODE_H_
13#define _ERROR_CODE_H_
14
15#include "log_global.h"
16#include "meta.h"
17#include "term.h"
18#include <cassert>
19#include <iostream>
20#include <string>
21#include <type_traits>
22
29enum class Err : int {
30 SUCCESS = 0,
31 // error
32 CLI_OPTIONS = 100,
33 NO_GUI,
51 // warning
53};
54
61static inline int errorCode(const Err& e) noexcept { return static_cast<int>(e); }
62
69static inline std::string errorMsg(const Err& e) noexcept {
70 switch (e) {
71 case Err::SUCCESS: return "Success!";
72 case Err::CLI_OPTIONS: return "Command line options error.";
73 case Err::NO_GUI: return "No GUI App.";
74 case Err::INPUT_NOT_EXISTS: return "Input file does not exist.";
75 case Err::UNKOWN_CMD: return "Unknown command (use mmcesim -h for more information).";
77 return "Output file exists. To force overwriting, you can use option '--force' or '-f'.";
78 case Err::CANNOT_OPEN_OUTPUT_FILE: return "Cannot open output file.";
79 case Err::YAML_SYNTAX: return "YAML syntax error.";
80 case Err::YAML_DTYPE: return "YAML data type error.";
81 case Err::VERSION_STRING_ERROR: return "Invalid version string.";
82 case Err::TOO_MANY_TX: return "Too many transmitters.";
83 case Err::TOO_MANY_RX: return "Too many receivers.";
84 case Err::ASTYLE_ERROR: return "Astyle formatting error.";
85 case Err::COMPILE_ERROR: return "Simulation compilation error.";
86 case Err::SIMULATE_ERROR: return "Simulation running error.";
87 case Err::CONFIG_ERROR: return "Configuration error.";
89 return "Cannot copy from include directory. Please check if directory 'include/mmcesim/copy' exists.";
90 case Err::ALG_EXPORT_ESTIMATION: return "ALG export estimation error.";
91 case Err::ALG_EXPORT_GEN_BF: return "ALG export generation BF error.";
92 case Err::ALG_EXPORT_ALGORITHM: return "ALG export algorithm error.";
94 return "Version string not specified. Assume as application version " + _MMCESIM_VER_STR + ".";
95 default: return "Error!";
96 }
97}
98
106static inline bool isError(const Err& e) noexcept { return errorCode(e) >= 100 && errorCode(e) < 200; }
107
115static inline bool isWarning(const Err& e) noexcept { return errorCode(e) >= 200; }
116
126static inline bool isSuccess(const Err& e) noexcept { return e == Err::SUCCESS; }
127
133static inline void errorExit(const Err& e, bool show_error = true) noexcept {
134 assert(isError(e) && "check if it is really an error in errorExit");
135 if (show_error) {
136 auto msg = errorMsg(e);
137 Term::error(msg);
138 _log.err() << msg << std::endl;
139 }
140 exit(errorCode(e));
141}
142
143#endif
std::ofstream & err()
Write error message to the log file.
Definition: log.h:117
static void error(const T &msg)
Print error message.
Definition: term.h:178
static bool isSuccess(const Err &e) noexcept
Check if the error code corresponds to a warning.
Definition: error_code.h:126
Err
Error Code.
Definition: error_code.h:29
@ TOO_MANY_RX
@ ALG_EXPORT_ALGORITHM
@ TOO_MANY_TX
@ VERSION_NOT_SPECIFIED
@ ALG_EXPORT_ESTIMATION
@ CONFIG_ERROR
@ COMPILE_ERROR
@ CANNOT_OPEN_OUTPUT_FILE
@ OUTPUT_FILE_EXISTS
@ SIMULATE_ERROR
@ ALG_EXPORT_GEN_BF
@ YAML_DTYPE
@ ASTYLE_ERROR
@ CANNOT_COPY_FROM_INCLUDE
@ VERSION_STRING_ERROR
@ SUCCESS
@ INPUT_NOT_EXISTS
@ NO_GUI
@ CLI_OPTIONS
@ UNKOWN_CMD
@ YAML_SYNTAX
static bool isError(const Err &e) noexcept
Check if the error code corresponds to an error.
Definition: error_code.h:106
static bool isWarning(const Err &e) noexcept
Check if the error code corresponds to a warning.
Definition: error_code.h:115
static void errorExit(const Err &e, bool show_error=true) noexcept
Print error message and exit with exit code.
Definition: error_code.h:133
static std::string errorMsg(const Err &e) noexcept
Return the error message of the error code from class Err.
Definition: error_code.h:69
static int errorCode(const Err &e) noexcept
Return the integer of the error code from class Err.
Definition: error_code.h:61
Global Access of Log.
Log _log
The shared Log variable.
Definition: log.cpp:53
mmCEsim meta data
const std::string _MMCESIM_VER_STR
Definition: meta.h:33
Terminal Color and Style Control.