ocra-recipes
Doxygen documentation for the ocra-recipes repository
ErrorsHelper.h
Go to the documentation of this file.
1 #ifndef _ERRORSHELPER_H_
2 #define _ERRORSHELPER_H_
3 
4 #include <iostream>
5 
6 inline std::string fullMethodName(const std::string& prettyFunction)
7 {
8  size_t colons = prettyFunction.find("::");
9  size_t begin = prettyFunction.substr(0,colons).rfind(" ") + 1;
10  size_t end = prettyFunction.rfind("(") - begin;
11 
12  return "[" + prettyFunction.substr(begin,end) + "()" "]";
13 }
14 
15 #define __FULL_METHOD_NAME__ fullMethodName(__PRETTY_FUNCTION__)
16 
17 // Colors code is as follows:
18 // \33 at the beginning and the end correspond to the octal for ESC which must always be present.
19 // 1 stands for BOLD
20 // 30 + n is the code for the text color.
21 // 40 + n is the code for the background color.
22 // 90 + n for high intensity text color.
23 // n: 0 - black
24 // 1 - red
25 // 2 - green
26 // 3 - yellow
27 // 4 - blue
28 // 5 - magenta
29 // 6 - cyan
30 // 7 - white
31 
32 #define OCRA_ERROR(msg) \
33 std::cout << "\033[1;93;41m[ERROR]" << __FULL_METHOD_NAME__ << "\033[0m" << std::endl << msg << std::endl;
34 
35 #define OCRA_WARNING(msg) \
36 std::cout << "\033[1;97;42m[WARNING]" << __FULL_METHOD_NAME__ << "\033[0m" << std::endl << msg << std::endl;
37 
38 #define OCRA_INFO(msg) \
39 std::cout << "\033[1;97;40m[INFO]" << __FULL_METHOD_NAME__ << "\033[0m" << std::endl << msg << std::endl;
40 
41 #endif
std::string fullMethodName(const std::string &prettyFunction)
Definition: ErrorsHelper.h:6