00001 // CASTORFile.cpp: implementation of the CASTORFile class. 00002 // 00004 00005 #include "stdafx.h" 00006 #include "EvolveTraffic.h" 00007 #include "CASTORFile.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 CASTORFile::CASTORFile(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 CASTORFile::~CASTORFile() 00036 { 00037 m_InFile.close(); 00038 m_OutFile.flush(); 00039 00040 m_Vehicles.clear(); 00041 } 00042 00052 Vehicle* CASTORFile::readLine() 00053 { 00054 std::string str; 00055 std::getline(m_InFile, str, '\n'); 00056 00057 if(str != "") 00058 { 00059 m_CurLine++; 00060 Vehicle* pVeh; 00061 int GVW = atoi( str.substr(21,4).c_str() ); // TRUCK_WEIGHT_THRESHOLD in kg/100 00062 00063 if(GVW >= TRUCK_WEIGHT_THRESHOLD * KG100_TO_KN) 00064 pVeh = new Truck(); 00065 else 00066 pVeh = new Car(); 00067 00068 pVeh->createCASTORVehicle(str); 00069 return pVeh; 00070 } 00071 00072 return NULL; 00073 } 00074 00084 void CASTORFile::writeLine(Vehicle *pVeh) 00085 { 00086 pVeh->writeCASTORData(m_pCharVeh); 00087 m_OutFile << m_pCharVeh << '\n'; 00088 }