// JobStream.h Dave Reed 9/9/03 // // 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, len; while (infile >> arr >> id >> len) { Job j(id, arr, len); arrivingJobs.Enter(j); } } bool JobStream::JobsRemaining() const // Returns: true if any jobs are left to be processed, else false { return !arrivingJobs.IsEmpty(); } bool JobStream::JobHasArrived(int time) const // Returns: true if a job has arrived by given time, else false { return (!arrivingJobs.IsEmpty() && 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.Remove(); return nextJob; }