// JobStream.cpp Dave Reed // // JobStream class implementation //////////////////////////////////////////////////////////////// #include #include #include #include "Job.h" #include "JobStream.h" using namespace std; JobStream::JobStream(string filename) // Assumes: filename is the name of the job data file // Results: constructs a queue of jobs from file { ifstream infile(filename.c_str()); if (!infile) { cout << "Input file not found. Program aborted." << endl; exit(1); } int arr, id; string str; while (infile >> arr >> id) { getline(infile, str); Job j(id, arr, str); arrivingJobs.push(j); } } bool JobStream::JobsRemaining() const // Returns: true if any jobs are left to be processed, else false { return !arrivingJobs.empty(); } bool JobStream::JobHasArrived(int time) const // Returns: true if a job has arrived by given time, else false { return (!arrivingJobs.empty() && arrivingJobs.front().GetArrival() <= time); } Job JobStream::GetJob() // Assumes: at least one job is waiting to be processed // Returns: the next job (and removes it from the stream) { Job nextJob = arrivingJobs.front(); arrivingJobs.pop(); return nextJob; }