00001 // FileHandler.cpp: implementation of the FileHandler class. 00002 // 00004 00005 #include "stdafx.h" 00006 #include "EvolveTraffic.h" 00007 #include "FileHandler.h" 00008 00009 #include "ConfigData.h" 00010 extern CConfigData g_ConfigData; 00011 00012 #ifdef _DEBUG 00013 #undef THIS_FILE 00014 static char THIS_FILE[]=__FILE__; 00015 #define new DEBUG_NEW 00016 #endif 00017 00019 // Construction/Destruction 00021 00023 FileHandler::FileHandler() 00024 { 00025 TRUCK_WEIGHT_THRESHOLD = g_ConfigData.VehicleID.TRUCK_WEIGHT_THRESHOLD; 00026 00027 m_CurLine = 0; 00028 } 00029 00031 FileHandler::~FileHandler() 00032 { 00033 00034 } 00035 00041 std::vector<Vehicle*> FileHandler::loadTruckGroup(int no) 00042 { 00043 for(int i = 0; i < no; i++) 00044 { 00045 Vehicle* pVeh = readLine(); 00046 m_Vehicles.push_back(pVeh); 00047 } 00048 00049 return m_Vehicles; 00050 } 00051 00052 void FileHandler::setInFileSize() 00053 { 00054 m_InFileSize = std::count( std::istreambuf_iterator<char>(m_InFile), 00055 std::istreambuf_iterator<char>(), 00056 '\n'); 00057 00058 m_InFile.seekg(0,std::ios::beg); // go back to start of file 00059 } 00060 00061 int FileHandler::getPercentComplete() 00062 { 00063 double prop = (double)(m_CurLine) / m_InFileSize; 00064 00065 int percent = int(prop * 100 + 0.5); 00066 00067 return percent; 00068 }