18 #ifndef __utlCoreMacro_h    19 #define __utlCoreMacro_h    30 #if defined(unix)        || defined(__unix)      || defined(__unix__)       \    31  || defined(linux)       || defined(__linux)     || defined(__linux__)      \    32  || defined(sun)         || defined(__sun)                                  \    33  || defined(BSD)         || defined(__OpenBSD__) || defined(__NetBSD__)     \    34  || defined(__FreeBSD__) || defined __DragonFly__                           \    35  || defined(sgi)         || defined(__sgi)                                  \    36  || defined(__MACOSX__)  || defined(__APPLE__)                              \    37  || defined(__CYGWIN__)                        39 #elif defined(_MSC_VER) || defined(WIN32)  || defined(_WIN32) || defined(__WIN32__) \    40    || defined(WIN64)    || defined(_WIN64) || defined(__WIN64__)    45 #elif !(UTL_OS==0 || UTL_OS==1 || UTL_OS==2)    46 #error UTL: Invalid configuration variable 'UTL_OS'.    47 #error (correct values are '0 = unknown OS', '1 = Unix-like OS', '2 = Microsoft Windows').    57 #define M_PI 3.14159265358979323846264338328    62 #ifndef ONE_OVER_4_PI_2    63 #define ONE_OVER_4_PI_2  0.025330295910584442860969865802431910     66 #if defined(__BORLANDC__)    67   #define __utl_LOCATION__ __FUNC__    68 #elif defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(CSWIG)    69   #define __utl_LOCATION__ __FUNCSIG__    70 #elif defined(__GNUC__)    71   #define __utl_LOCATION__ __PRETTY_FUNCTION__    73   #define __utl_LOCATION__ __FUNCTION__    76 #define UTL_ALWAYS_INLINE inline __attribute__((always_inline))   117   static const std::string t_normal(
"\033[0;0;0m");
   118   static const std::string t_black(
"\033[0;30;59m");
   119   static const std::string t_white(
"\033[0;37;59m");
   120   static const std::string t_bold(
"\033[1m");
   121   static const std::string t_red(
"\033[1;31;59m");
   122   static const std::string t_green(
"\033[0;32;59m");
   123   static const std::string t_yellow(
"\033[0;33;59m");
   124   static const std::string t_blue(
"\033[0;34;59m");
   125   static const std::string t_purple(
"\033[0;35;59m");
   126   static const std::string t_cyan(
"\033[0;36;59m");
   127   bool isTerminal = isatty(fileno(stdout)) != 0;
   129   static const bool isTerminal = 
false;
   137     case COLOR_RED : 
return t_red+str+t_normal;
   146     default :  
return t_normal+str+t_normal;
   155 #define __UTL_FATAL_STRING  utl::GetColoredString("Fatal", COLOR_RED)   156 #define __UTL_ERROR_STRING  utl::GetColoredString("Error", COLOR_RED)   157 #define __UTL_WARNING_STRING  utl::GetColoredString("Warning", COLOR_RED)   158 #define __UTL_DEBUG_STRING  utl::GetColoredString("Debug", COLOR_CYAN)   159 #define __UTL_LOG_STRING  utl::GetColoredString("Log", COLOR_BOLD)   160 #define __UTL_BOLD(str) utl::GetColoredString(str, COLOR_BOLD)   161 #define __UTL_EXPSTR(str) utl::GetColoredString(str, COLOR_GREEN)   173 #define __UTL_FATAL_STRING  "Fatal"   174 #define __UTL_ERROR_STRING  "Error"   175 #define __UTL_WARNING_STRING  "Warning"   176 #define __UTL_DEBUG_STRING  "Debug"   177 #define __UTL_LOG_STRING  "Log"   178 #define __UTL_BOLD(str) str   179 #define __UTL_EXPSTR(str) str   184 #define __UTL_Print_LOCATION  "In "<< __UTL_BOLD("File") << ": " <<__FILE__<< ", "<<__UTL_BOLD("Line")<<": " << __LINE__   << ", "<<__UTL_BOLD("Function")<<": " << __utl_LOCATION__ <<  "\n"    228 #if __cplusplus >= 201103L   238 #define utlNumberOfArgs(...)   utl::GetNumberOfArgs(__VA_ARGS__)    242 #define PrintVar(cond, os, ...)                                                                          \   246     if (utlNumberOfArgs(__VA_ARGS__)>1)                                                                  \   247       { os << "(" << #__VA_ARGS__ << ") = ";  utl::PrintOS(os, __VA_ARGS__);   }                         \   249       { os << #__VA_ARGS__ << " = ";  utl::PrintOS(os, __VA_ARGS__);   }                                 \   254 #define utlVLogOS_IF(cond, level, os)                                     \   257   if ((level<=utl::LogLevel) && (cond))                                   \   258     { os << std::endl << std::flush; }                                    \   262 #define utlVLogOS(level, os)                            utlVLogOS_IF(true, level, os)   263 #define utlVLog_IF(cond, level, expr)                   utlVLogOS_IF(cond, level, std::cout << expr)   264 #define utlVLog(level, expr)                            utlVLogOS_IF(true, level, std::cout << expr)   266 #define utlLogOS_IF(cond, os)                           utlVLogOS_IF(cond, 0, os)   267 #define utlLogOS(os)                                    utlVLogOS_IF(true, 0, os)   268 #define utlLog_IF(cond, expr)                           utlVLogOS_IF(cond, 0, std::cout << expr)   269 #define utlLog(expr)                                    utlVLogOS_IF(true, 0, std::cout << expr)   272 #define utlVLogOSVar_IF(cond, level, os, ...)                                                            \   274 { if ( level<=utl::LogLevel )                                                                            \   275      {  PrintVar(cond, os, __VA_ARGS__);  }                                                              \   279 #define utlVLogOSVar(level, os, ...)                    utlVLogOSVar_IF(true, level, os,        __VA_ARGS__)   280 #define utlVLogVar_IF(cond, level, ...)                 utlVLogOSVar_IF(cond, level, std::cout, __VA_ARGS__)   281 #define utlVLogVar(level, ...)                          utlVLogOSVar_IF(true, level, std::cout, __VA_ARGS__)   284 #define utlLogOSVar_IF(cond, os, ...)                   utlVLogOSVar_IF(cond, 0, os,        __VA_ARGS__)   285 #define utlLogOSVar(os, ...)                            utlVLogOSVar_IF(true, 0, os,        __VA_ARGS__)   286 #define utlLogVar_IF(cond, ...)                         utlVLogOSVar_IF(cond, 0, std::cout, __VA_ARGS__)   287 #define utlLogVar(...)                                  utlVLogOSVar_IF(true, 0, std::cout, __VA_ARGS__)   291 #define utlVLogOSPosition_IF(cond,level, os)                                                                                   \   293 {  if ((level<=utl::LogLevel) && (cond))                                                                                       \   294     { os << "\n"<<__UTL_BOLD("Work Flow")<<": "<< __UTL_Print_LOCATION << std::flush;                                          \   298 #define utlVLogPosition(level)   utlVLogOSPosition_IF(true, level, std::cout)       303 #define utlOSPrintVar(cond, os, ...)                          PrintVar(cond,      os,   __VA_ARGS__)   304 #define utlPrintVar(cond, ...)                                PrintVar(cond, std::cout, __VA_ARGS__)   308 #define utlOSPrintVar(cond, os, ...)                             309 #define utlPrintVar(cond, ...)               318 template <
typename T, 
size_t N>
   320 #ifndef COMPILER_MSVC   321 template <
typename T, 
size_t N>
   324 #define utlArraySize(array) (sizeof(__utlArraySizeHelper(array)))   334 #ifdef MATLAB_MEX_FILE   336 #define utlAbort(expout) do { mexErrMsgTxt(expout); } while(0)   338 #define utlAbort(expout) do { std::cerr << expout <<"\n" << std::flush; abort(); } while(0)   345 #define __utlConditionFailPrint(cond)      __UTL_Print_LOCATION <<__UTL_BOLD("Expression")<<": '" << __UTL_EXPSTR(#cond) << "' failed. " << "\n"   346 #define __utlConditionSucceedPrint(cond)   __UTL_Print_LOCATION <<__UTL_BOLD("Expression")<<": '" << __UTL_EXPSTR(#cond) << "' satisfied. " << "\n"   348 #define utlSASetLog(log) Assert::set_log(log)    350 #define utlSAGlobalPrintIf(expr)     \   352     else ::smart_assert::make_assert(#expr).log().print_context( __FILE__, __LINE__,__SMART_ASSERT_LOCATION__, ::smart_assert::lvl_condition_exception).SMART_ASSERT_A    355 #define utlSAGlobalPrint utlSAGlobalPrintIf("")    357 #define utlSAGlobalWarning(expr)        \   359     else ::smart_assert::make_assert(#expr).warn().print_context( __FILE__, __LINE__,__SMART_ASSERT_LOCATION__, ::smart_assert::lvl_condition_exception).SMART_ASSERT_A    362 #define utlSAGlobalException(expr)        \   364     else ::smart_assert::make_assert(#expr).error().print_context( __FILE__, __LINE__,__SMART_ASSERT_LOCATION__, ::smart_assert::lvl_condition_exception).SMART_ASSERT_A    367 #define utlSAGlobalAssert(expr)        \   369     else ::smart_assert::make_assert(#expr).error().print_context( __FILE__, __LINE__,__SMART_ASSERT_LOCATION__, ::smart_assert::lvl_condition_assert).SMART_ASSERT_A    372 #define utlGlobalException(cond,expout)                                                                                                                 \   376     { std::cerr << "\n"<<__UTL_ERROR_STRING<<": " << __utlConditionSucceedPrint(cond) << __UTL_BOLD("msg")<<": '"<<expout << "'\n" << std::flush;       \   381 #define utlGlobalAssert(cond,expout)                                                                                                                    \   385     { std::cerr << "\n"<<__UTL_ERROR_STRING<<": " << __utlConditionFailPrint(cond) << __UTL_BOLD("msg")<<": '"<<expout << "\n" << std::flush;           \   390 #define utlOSGlobalWarning(cond,expout,os)                                                                                                              \   393     { os << "\n"<<__UTL_WARNING_STRING<<": "<< __utlConditionSucceedPrint(cond) <<  __UTL_BOLD("msg")<<": '"<<expout << "\n" << std::flush;   }         \   397 #define utlGlobalWarning(cond,expout)                         utlOSGlobalWarning(cond,expout,std::cout)                  400 #define PrintEnum1(cond,var,val1,os)                                                                     \   402 { if ((cond) && ((var)==(val1)))                                                                         \   403     { os << #var <<" = " << #val1 << std::endl << std::flush; }                                          \   407 #define PrintEnum2(cond,var,val1,val2,os)                                                                \   409 { PrintEnum1(cond,var,val1,os);                                                                          \   410   if ((cond) && ((var)==(val2)))                                                                         \   411     { os << #var <<" = " << #val2 << std::endl << std::flush; }                                          \   415 #define PrintEnum3(cond,var,val1,val2,val3,os)                                                           \   417 { PrintEnum2(cond,var,val1,val2,os);                                                                     \   418   if ((cond) && ((var)==(val3)))                                                                         \   419     { os << #var <<" = " << #val3 << std::endl << std::flush; }                                          \   423 #define PrintEnum4(cond,var,val1,val2,val3,val4,os)                                                      \   425 { PrintEnum3(cond,var,val1,val2,val3,os);                                                                \   426   if ((cond) && ((var)==(val4)))                                                                         \   427     { os << #var <<" = " << #val4 << std::endl << std::flush; }                                          \   431 #define PrintEnum5(cond,var,val1,val2,val3,val4,val5,os)                                                 \   433 { PrintEnum4(cond,var,val1,val2,val3,val4,os);                                                           \   434   if ((cond) && ((var)==(val5)))                                                                         \   435     { os << #var <<" = " << #val5 << std::endl << std::flush; }                                          \   439 #define PrintEnum6(cond,var,val1,val2,val3,val4,val5,val6,os)                                            \   441 { PrintEnum5(cond,var,val1,val2,val3,val4,val5,os);                                                      \   442   if ((cond) && ((var)==(val6)))                                                                         \   443     { os << #var <<" = " << #val6 << std::endl << std::flush; }                                          \   447 #define PrintVar1(cond,var,os)                                                                           \   450     { os << std::boolalpha << #var <<" = " <<  (var) << std::endl << std::flush << std::noboolalpha; }   \   454 #define PrintVar2(cond,var1,var2,os)                                                                     \   457     { os << std::boolalpha << "("<<#var1<<", "<< #var2<<") = (" <<  (var1) << ", " << (var2) << ")"      \   458     << std::endl << std::flush << std::noboolalpha; }                                                    \   462 #define PrintVar3(cond,var1,var2,var3,os)                                                                                     \   465     { os << std::boolalpha << "("<<#var1<<", "<<#var2<<", "<<#var3<<") = ("                                                   \   466     <<  (var1) << ", " << (var2) << ", " << (var3) << ")" << std::endl << std::flush << std::noboolalpha; }                   \   470 #define PrintVar4(cond,var1,var2,var3,var4,os)                                                                                \   473     { os << std::boolalpha << "("<<#var1<<", "<<#var2<<", "<<#var3<<", "<<#var4<<") = ("                                      \   474     <<  (var1) << ", " << (var2) << ", " << (var3) << ", " << (var4) << ")" << std::endl << std::flush << std::noboolalpha; } \   478 #define PrintVar5(cond,var1,var2,var3,var4,var5,os)                                                      \   481     { os << std::boolalpha << "("<<#var1<<", "<<#var2<<", "<<#var3<<", "<<#var4<<", "<<#var5<<") = ("    \   482     <<  (var1) << ", " << (var2) << ", " << (var3) << ", " << (var4) << ", " << (var5) <<")"             \   483     << std::endl << std::flush << std::noboolalpha; }                                                    \   487 #define PrintVar6(cond,var1,var2,var3,var4,var5,var6,os)                                                                  \   490     { os << std::boolalpha << "("<<#var1<<", "<<#var2<<", "<<#var3<<", "<<#var4<<", "<<#var5<<", "<<#var6<<") = ("        \   491     <<  (var1) << ", " << (var2) << ", " << (var3) << ", " << (var4) << ", " << (var5) <<", " << (var6) <<")"             \   492     << std::endl << std::flush << std::noboolalpha; }                                                                     \   499 #define utlSAPrintIf(expr)           utlSAGlobalPrintIf(expr)   500 #define utlSAPrint                   utlSAGlobalPrint   501 #define utlSAWarning(expr)           utlSAGlobalWarning(expr)   502 #define utlSAException(expr)         utlSAGlobalException(expr)   503 #define utlSAAssert(expr)            utlSAGlobalAssert(expr)    507 #define utlException(cond,expout)    utlGlobalException(cond,expout)   508 #define utlAssert(cond,expout)       utlGlobalAssert(cond,expout)   509 #define utlOSWarning(cond,expout,os) utlOSGlobalWarning(cond,expout,os)   510 #define utlWarning(cond,expout)      utlGlobalWarning(cond,expout)   513 #define utlDebug(cond,expout)                                                                                                                          \   516     { std::cerr << "\n"<<__UTL_DEBUG_STRING<<": " << __utlConditionSucceedPrint(cond) << __UTL_BOLD("msg")<<": '"<<expout << "\n" << std::flush; }     \   520 #define utlOSShowPosition(cond,os)    utlVLogOSPosition_IF(cond, 0,  os)                                                             522 #define utlShowPosition(cond)   utlOSShowPosition(cond,std::cout)                                                                        524 #define utlPrintVar1(cond,var)                                              PrintVar1(cond,var,std::cout)   525 #define utlPrintVar2(cond,var1,var2)                                        PrintVar2(cond,var1,var2,std::cout)   526 #define utlPrintVar3(cond,var1,var2,var3)                                   PrintVar3(cond,var1,var2,var3,std::cout)    527 #define utlPrintVar4(cond,var1,var2,var3,var4)                              PrintVar4(cond,var1,var2,var3,var4,std::cout)    528 #define utlPrintVar5(cond,var1,var2,var3,var4,var5)                         PrintVar5(cond,var1,var2,var3,var4,var5,std::cout)   529 #define utlPrintVar6(cond,var1,var2,var3,var4,var5,var6)                    PrintVar6(cond,var1,var2,var3,var4,var5,var6,std::cout)   531 #define utlOSPrintVar1(cond,var,os)                                         PrintVar1(cond,var,os)   532 #define utlOSPrintVar2(cond,var1,var2,os)                                   PrintVar2(cond,var1,var2,os)   533 #define utlOSPrintVar3(cond,var1,var2,var3,os)                              PrintVar3(cond,var1,var2,var3,os)    534 #define utlOSPrintVar4(cond,var1,var2,var3,var4,os)                         PrintVar4(cond,var1,var2,var3,var4,os)    535 #define utlOSPrintVar5(cond,var1,var2,var3,var4,var5,os)                    PrintVar5(cond,var1,var2,var3,var4,var5,os)   536 #define utlOSPrintVar6(cond,var1,var2,var3,var4,var5,var6,os)               PrintVar6(cond,var1,var2,var3,var4,var5,var6,os)   540 #define utlSAPrintIf(expr)    utlSAGlobalPrintIf(false)   541 #define utlSAPrint            utlSAPrintIf("")   542 #define utlSAWarning(expr)    utlSAGlobalWarning(false)   543 #define utlSAException(expr)  utlSAGlobalException(false)   544 #define utlSAAssert(expr)     utlSAGlobalAssert(true)   548 #define utlException(cond,expout)    549 #define utlDebug(cond,expout)    550 #define utlAssert(cond,expout)    551 #define utlOSWarning(cond,expout,os)    552 #define utlWarning(cond,expout)    553 #define utlOSShowPosition(cond,os)   554 #define utlShowPosition(cond)   556 #define utlPrintVar1(cond,var)                                                                          557 #define utlPrintVar2(cond,var1,var2)                                                                    558 #define utlPrintVar3(cond,var1,var2,var3)                                                               559 #define utlPrintVar4(cond,var1,var2,var3,var4)                                                          560 #define utlPrintVar5(cond,var1,var2,var3,var4, var5)                                                    561 #define utlPrintVar6(cond,var1,var2,var3,var4, var5, var6)                                              563 #define utlOSPrintVar1(cond,var)                                                                          564 #define utlOSPrintVar2(cond,var1,var2)                                                                    565 #define utlOSPrintVar3(cond,var1,var2,var3)                                                               566 #define utlOSPrintVar4(cond,var1,var2,var3,var4)                                                          567 #define utlOSPrintVar5(cond,var1,var2,var3,var4, var5)                                                    568 #define utlOSPrintVar6(cond,var1,var2,var3,var4, var5, var6)                                              572 #define utlSetMacro(name, type)                     \   573   virtual void Set##name (const type _arg)          \   575     if ( this->m_##name != _arg )                   \   577       this->m_##name = _arg;                        \   582 #define utlGetMacro(name, type)                     \   583   virtual type Get##name () const                   \   585     return this->m_##name;                          \   589 #define utlSetGetMacro(name, type) \   590   utlSetMacro(name, type);         \   591   utlGetMacro(name, type); char(& __utlArraySizeHelper(T(&array)[N]))[N]
 
bool IsLogLarge(const int level=utl::LogLevel)
 
used for debug information. this->GetDebug() 
 
log for large matrix or vectors. 
 
bool IsLogDebug(const int level=utl::LogLevel)
 
bool IsLogNormal(const int level=utl::LogLevel)
 
utl functions using c++11 Created "07-02-2016 
 
bool IsLogMute(const int level=utl::LogLevel)
 
std::string GetColoredString(const std::string &str, const int color)
 
bool IsLogAll(const int level=utl::LogLevel)