SAFTFile Class Reference

A class for reading from, and writing to, SAFT format files. More...

#include <SAFTFile.h>

Inheritance diagram for SAFTFile:

Inheritance graph
[legend]
Collaboration diagram for SAFTFile:

Collaboration graph
[legend]

List of all members.

Public Member Functions

void writeLine (Vehicle *pVeh)
 Writes a line representing a truck to a SAFT file.
VehiclereadLine ()
 Reads a line representing a truck from a SAFT file.
 SAFTFile (std::string inputFile, std::string outputFile)
 Constructor.
virtual ~SAFTFile ()
 Default destructor.


Detailed Description

A class for reading from, and writing to, SAFT format files.

Definition at line 17 of file SAFTFile.h.


Constructor & Destructor Documentation

SAFTFile::SAFTFile ( std::string  inputFile,
std::string  outputFile 
)

Constructor.

Parameters:
inputFile The file to read input from
outputFile The file to write output to

Definition at line 25 of file SAFTFile.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 }

Here is the call graph for this function:

SAFTFile::~SAFTFile (  )  [virtual]

Default destructor.

Definition at line 35 of file SAFTFile.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 }


Member Function Documentation

void SAFTFile::writeLine ( Vehicle pVeh  )  [virtual]

Writes a line representing a truck to a SAFT file.

Parameters:
pVeh The vehicle to write to file
This function takes a vehicle as a parameter, and calls this vehicle's doSAFTDATA function, in order to obtain a string which represents all of the vehicle's physical properties. It then writes this string to a SAFT format file

Implements FileHandler.

Definition at line 86 of file SAFTFile.cpp.

References FileHandler::m_OutFile, FileHandler::m_pCharVeh, and Vehicle::writeSAFTData().

00087 {
00088         pVeh->writeSAFTData(m_pCharVeh);
00089         m_OutFile << m_pCharVeh << '\n';
00090 }

Here is the call graph for this function:

Vehicle * SAFTFile::readLine (  )  [virtual]

Reads a line representing a truck from a SAFT file.

Returns:
A newly created truck
This function reads the next line available from a SAFT format file and stores the information in a string. If the string is not null, a truck is created with the properties specified by the line from the file, and the truck is returned

Implements FileHandler.

Definition at line 52 of file SAFTFile.cpp.

References Vehicle::createSAFTVehicle(), KG100_TO_KN, FileHandler::m_CurLine, FileHandler::m_InFile, and FileHandler::TRUCK_WEIGHT_THRESHOLD.

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 }

Here is the call graph for this function:


The documentation for this class was generated from the following files:

Generated on Wed Aug 20 00:48:50 2008 for EvolveTraffic by  doxygen 1.5.6