1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#include "LogFile.h"
#include "RAI.h"
#include "LegacyCpp/IAICallback.h"
#include <string>
//#include <fstream>
//#include <stdlib.h>
//#include <iostream>
#include <stdio.h>
using std::string;
cLogFile::cLogFile(IAICallback* cb, string sFilename, bool bAppend)
{
string sFilename_w;
const bool located = cRAI::LocateFile(cb, sFilename, sFilename_w, true);
if (!located) {
throw 11;
}
if( bAppend )
logFile = fopen(sFilename_w.c_str(), "a");
// logFile = new ofstream();
// logFile->open( logFileName.c_str(), ios::app );
else
logFile = fopen(sFilename_w.c_str(), "w");
// ofstream oLog( logFileName.c_str() );
// oLog.close();
/*
pFile = fopen(logFileName.c_str(),"wt");
fclose(pFile);
*/
}
cLogFile::~cLogFile()
{
fclose(logFile);
// logFile->close();
// delete logFile;
}
cLogFile& cLogFile::operator<<(float message)
{
if( message - int(message) > 0.0 )
{
if( message < 1.0 && message > 0.0 )
fprintf(logFile, "%1.3f", message);
else
fprintf(logFile, "%1.2f", message);
}
else
fprintf(logFile, "%1.0f", message);
return *this;
}
/*
cLogFile& cLogFile::operator<<(int message)
{
fprintf(logFile, "%i", message);
return *this;
}
*/
cLogFile& cLogFile::operator<<(string message)
{
fprintf(logFile, "%s", message.c_str());
return *this;
}
/*
void cLogFile::Write(string message)
{
fprintf(logFile, "%s", message.c_str());
// fputs(message.c_str(),logFile);
// *logFile<<message.c_str();
// logFile->flush();
}
void cLogFile::Write(float message)
{
if( message - int(message) > 0.0 )
fprintf(logFile, "%1.2f", message);
else
fprintf(logFile, "%1.0f", message);
// *logFile<<message;
// logFile->flush();
}
void cLogFile::Write(int message)
{
// *logFile<<message;
// logFile->flush();
}
*/
|