include/common.h
branchpyrit
changeset 98 64638385798a
parent 95 ca7d4c665531
child 100 c005054bf4c1
equal deleted inserted replaced
97:2a853d284a6a 98:64638385798a
    57 #define NORETURN __declspec(noreturn)
    57 #define NORETURN __declspec(noreturn)
    58 #else
    58 #else
    59 #define NORETURN __attribute__((noreturn))
    59 #define NORETURN __attribute__((noreturn))
    60 #endif
    60 #endif
    61 
    61 
    62 /* verbosity level:
    62 /**
    63 0: only errors and warnings (E, W)
    63  * verbosity level
    64 1: major status messages (*)
    64  *
    65 2: minor status, progress (-)
    65  * - 0: only errors and warnings (E, W)
    66 3: debug messages (D)
    66  * - 1: major status messages (*)
    67 4: thread debug
    67  * - 2: minor status, progress (-)
    68 default = 2
    68  * - 3: debug messages (D)
    69 */
    69  * - 4: thread debug
       
    70  *
       
    71  * default is 2
       
    72  */
    70 extern int pyrit_verbosity;
    73 extern int pyrit_verbosity;
    71 
    74 
       
    75 /**
       
    76  * print status or debugging message
       
    77  * @param[in] vlevel    verbosity level of the message
       
    78  * @see pyrit_verbosity
       
    79  */
    72 void dbgmsg(const int vlevel, const char *format, ...);
    80 void dbgmsg(const int vlevel, const char *format, ...);
    73 
    81 
       
    82 /** template for minimum of three numbers */
    74 template<typename Type> const Type &min3(const Type &a, const Type &b, const Type &c)
    83 template<typename Type> const Type &min3(const Type &a, const Type &b, const Type &c)
    75 {
    84 {
    76 	if (a <= b)
    85 	if (a <= b)
    77 	{
    86 	{
    78 		if (a <= c)
    87 		if (a <= c)
    87 		else
    96 		else
    88 			return c;
    97 			return c;
    89 	}
    98 	}
    90 }
    99 }
    91 
   100 
       
   101 /** template for maximum of three numbers */
    92 template<typename Type> const Type &max3(const Type &a, const Type &b, const Type &c)
   102 template<typename Type> const Type &max3(const Type &a, const Type &b, const Type &c)
    93 {
   103 {
    94 	if (a >= b)
   104 	if (a >= b)
    95 	{
   105 	{
    96 		if (a >= c)
   106 		if (a >= c)
   105 		else
   115 		else
   106 			return c;
   116 			return c;
   107 	}
   117 	}
   108 }
   118 }
   109 
   119 
       
   120 /** trim whitespace from beginning and end of string */
   110 inline void trim(string& s)
   121 inline void trim(string& s)
   111 {
   122 {
   112 	const char *ws = " \n";
   123 	const char *ws = " \n";
   113 	string::size_type pos = s.find_last_not_of(ws);
   124 	string::size_type pos = s.find_last_not_of(ws);
   114 	if (pos != string::npos)
   125 	if (pos != string::npos)