CASTORFile Class Reference

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

#include <CASTORFile.h>

Inheritance diagram for CASTORFile:

Inheritance graph
[legend]
Collaboration diagram for CASTORFile:

Collaboration graph
[legend]

List of all members.

Public Member Functions

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


Detailed Description

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

Definition at line 17 of file CASTORFile.h.


Constructor & Destructor Documentation

CASTORFile::CASTORFile ( 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 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 }

Here is the call graph for this function:

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 }


Member Function Documentation

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

Writes a line representing a truck to a CASTOR file.

Parameters:
pVeh The vehicle to write to file
This function takes a vehicle as a parameter, and calls this vehicle's doCASTORDATA function, in order to obtain a string which represents all of the vehicle's physical properties. It then writes this string to a CASTOR format 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 }

Here is the call graph for this function:

Vehicle * CASTORFile::readLine (  )  [virtual]

Reads a line representing a truck from a CASTOR file.

Returns:
A newly created truck
This function reads the next line available from a CASTOR 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 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 }

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:42 2008 for EvolveTraffic by  doxygen 1.5.6