00001 // SAFTFile.cpp: implementation of the SAFTFile class. 00002 // 00004 00005 #include "stdafx.h" 00006 #include "EvolveTraffic.h" 00007 #include "SAFTFile.h" 00008 00009 #ifdef _DEBUG 00010 #undef THIS_FILE 00011 static char THIS_FILE[]=__FILE__; 00012 #define new DEBUG_NEW 00013 #endif 00014 00016 // Construction/Destruction 00018 00025 SAFTFile::SAFTFile(std::string inputFile, std::string outputFile) 00026 { 00027 m_InFile.open(inputFile.c_str(), std::ios::in); 00028 setInFileSize(); 00029 00030 m_OutFile.open(outputFile.c_str(), std::ios::out); 00031 m_pCharVeh = m_VehCharArry; 00032 } 00033 00035 SAFTFile::~SAFTFile() 00036 { 00037 m_InFile.close(); 00038 m_OutFile.flush(); 00039 00040 m_Vehicles.clear(); 00041 } 00042 00052 Vehicle* SAFTFile::readLine() 00053 { 00054 std::string str; 00055 00056 std::getline(m_InFile, str, '\n'); 00057 00058 if(str != "") 00059 { 00060 m_CurLine++; 00061 Vehicle* pVeh; 00062 double GVW = atoi( str.substr(27,4).c_str() ) * KG100_TO_KN; // convert kg/100 to kN 00063 00064 if(GVW >= TRUCK_WEIGHT_THRESHOLD) 00065 pVeh = new Truck(); 00066 00067 else 00068 pVeh = new Car(); 00069 00070 pVeh->createSAFTVehicle(str); 00071 return pVeh; 00072 } 00073 00074 return NULL; 00075 } 00076 00086 void SAFTFile::writeLine(Vehicle *pVeh) 00087 { 00088 pVeh->writeSAFTData(m_pCharVeh); 00089 m_OutFile << m_pCharVeh << '\n'; 00090 }