FileHandler Class Reference

A base class for handling file input and output. More...

#include <FileHandler.h>

Inheritance diagram for FileHandler:

Inheritance graph
[legend]

List of all members.

Public Member Functions

int getPercentComplete ()
std::vector< Vehicle * > loadTruckGroup (int no)
 Facilitates the buffering of a number of vehicles, rather than line by line input.
virtual void writeLine (Vehicle *pVeh)=0
virtual VehiclereadLine ()=0
 FileHandler ()
 Default Constructor.
virtual ~FileHandler ()
 Default Destructor.

Protected Member Functions

void setInFileSize ()

Protected Attributes

std::ifstream m_InFile
std::ofstream m_OutFile
std::vector< Vehicle * > m_Vehicles
char * m_pCharVeh
char m_VehCharArry [78]
int m_CurLine
int m_InFileSize
int TRUCK_WEIGHT_THRESHOLD


Detailed Description

A base class for handling file input and output.

Definition at line 21 of file FileHandler.h.


Constructor & Destructor Documentation

FileHandler::FileHandler (  ) 

FileHandler::~FileHandler (  )  [virtual]

Default Destructor.

Definition at line 31 of file FileHandler.cpp.

00032 {
00033 
00034 }


Member Function Documentation

int FileHandler::getPercentComplete (  ) 

Definition at line 61 of file FileHandler.cpp.

References m_CurLine, and m_InFileSize.

Referenced by Road::populate().

00062 {
00063         double prop = (double)(m_CurLine) / m_InFileSize;
00064 
00065         int percent = int(prop * 100 + 0.5);
00066 
00067         return percent;
00068 }

std::vector< Vehicle * > FileHandler::loadTruckGroup ( int  no  ) 

Facilitates the buffering of a number of vehicles, rather than line by line input.

Parameters:
no The number of vehicles to buffer
Returns:
The buffer of vehicles

Definition at line 41 of file FileHandler.cpp.

References m_Vehicles, and readLine().

Referenced by Road::init().

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 }

Here is the call graph for this function:

virtual void FileHandler::writeLine ( Vehicle pVeh  )  [pure virtual]

Implemented in CASTORFile, and SAFTFile.

Referenced by OutputDetector::WriteVehiclesToFile().

virtual Vehicle* FileHandler::readLine (  )  [pure virtual]

Implemented in CASTORFile, and SAFTFile.

Referenced by loadTruckGroup(), and Road::populate().

void FileHandler::setInFileSize (  )  [protected]

Definition at line 52 of file FileHandler.cpp.

References m_InFile, and m_InFileSize.

Referenced by CASTORFile::CASTORFile(), and SAFTFile::SAFTFile().

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 }


Member Data Documentation

std::ifstream FileHandler::m_InFile [protected]

std::ofstream FileHandler::m_OutFile [protected]

std::vector<Vehicle*> FileHandler::m_Vehicles [protected]

Definition at line 35 of file FileHandler.h.

Referenced by loadTruckGroup(), CASTORFile::~CASTORFile(), and SAFTFile::~SAFTFile().

char* FileHandler::m_pCharVeh [protected]

char FileHandler::m_VehCharArry[78] [protected]

Definition at line 37 of file FileHandler.h.

Referenced by CASTORFile::CASTORFile(), and SAFTFile::SAFTFile().

int FileHandler::m_CurLine [protected]

int FileHandler::m_InFileSize [protected]

Definition at line 40 of file FileHandler.h.

Referenced by getPercentComplete(), and setInFileSize().

Definition at line 42 of file FileHandler.h.

Referenced by FileHandler(), SAFTFile::readLine(), and CASTORFile::readLine().


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

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