Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members File Members Related Pages

# HelperFunctions.cpp

Go to the documentation of this file.

    00001
    00040 #include <stdio.h>
    00041 #include <stdarg.h>
    00042 #include <math.h>
    00043 #include "HelperFunctions.h"
    00044
    00045
    00046 #ifdef WIN32
    00047 #define vsnprintf _vsnprintf
    00048 #endif
    00049
    00050 using namespace std;
    00051
    00052 double SIMILARITY(double x, double y, const double& minVal /*= .1*/)
    00053 {
    00054         x = fabs(x);
    00055         y = fabs(y);
    00056
    00057         if (x > y)
    00058         {
    00059                 if (y == 0)
    00060                         return MIN(minVal, x) / x;
    00061                 else
    00062                         return y / x;
    00063         }
    00064         else if (y > x)
    00065         {
    00066                 if (x == 0)
    00067                         return MIN(minVal, y) / y;
    00068                 else
    00069                         return x / y;
    00070         }
    00071
    00072         return 1;
    00073 }
    00074
    00075 LogFile::LogFile(const char* szFileName)
    00076 {
    00077         open(szFileName, ios::out | ios::trunc);
    00078 }
    00079
    00080 void LogFile::Print(const char* szFormat, ...)
    00081 {
    00082         va_list args;
    00083
    00084         va_start(args, szFormat);
    00085
    00086         //vfprintf((FILE*)this->rdbuf()->fd(), szFormat, args);
    00087         const int size = 512;
    00088         char szBuff[size];
    00089
    00090         vsnprintf(szBuff, size, szFormat, args);
    00091
    00092         va_end(args);
    00093
    00094         (*this) << szBuff;
    00095 }
    00096