#include <CASTORFile.h>
Public Member Functions | |
void | writeLine (Vehicle *pVeh) |
Writes a line representing a truck to a CASTOR file. | |
Vehicle * | readLine () |
Reads a line representing a truck from a CASTOR file. | |
CASTORFile (std::string inputFile, std::string outputFile) | |
Constructor. | |
virtual | ~CASTORFile () |
Default Destructor. |
Definition at line 17 of file CASTORFile.h.
CASTORFile::CASTORFile | ( | std::string | inputFile, | |
std::string | outputFile | |||
) |
Constructor.
inputFile | The file to read input from | |
outputFile | The file to write output to |
Definition at line 25 of file CASTORFile.cpp.
References FileHandler::m_InFile, FileHandler::m_OutFile, FileHandler::m_pCharVeh, FileHandler::m_VehCharArry, and FileHandler::setInFileSize().
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 }
CASTORFile::~CASTORFile | ( | ) | [virtual] |
Default Destructor.
Definition at line 35 of file CASTORFile.cpp.
References FileHandler::m_InFile, FileHandler::m_OutFile, and FileHandler::m_Vehicles.
00036 { 00037 m_InFile.close(); 00038 m_OutFile.flush(); 00039 00040 m_Vehicles.clear(); 00041 }
void CASTORFile::writeLine | ( | Vehicle * | pVeh | ) | [virtual] |
Writes a line representing a truck to a CASTOR file.
pVeh | The vehicle to write to file |
Implements FileHandler.
Definition at line 84 of file CASTORFile.cpp.
References FileHandler::m_OutFile, FileHandler::m_pCharVeh, and Vehicle::writeCASTORData().
00085 { 00086 pVeh->writeCASTORData(m_pCharVeh); 00087 m_OutFile << m_pCharVeh << '\n'; 00088 }
Vehicle * CASTORFile::readLine | ( | ) | [virtual] |
Reads a line representing a truck from a CASTOR file.
Implements FileHandler.
Definition at line 52 of file CASTORFile.cpp.
References Vehicle::createCASTORVehicle(), KG100_TO_KN, FileHandler::m_CurLine, FileHandler::m_InFile, and FileHandler::TRUCK_WEIGHT_THRESHOLD.
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 }