// JobStream.cpp Dave Reed 2/5/05 //////////////////////////////////////////////////////////////// #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; }