// Program Name:  Cheap Banker
// Programmer: Mark Dehus
// Assignment Number: Project 3
// Purpose: To write a program that uses the bankers algorithm

#include "process.h"
#include <iostream>

using namespace std;

void Process::set_resources(string r, string type)
{
	int r1, r2, r3, r4;
	string str_val = r.substr(r.find("A") + 1, 2);
	r1 = atoi(str_val.c_str());
	str_val = r.substr(r.find("B") + 1, 2);
	r2 = atoi(str_val.c_str());
	str_val = r.substr(r.find("C") + 1, 2);
	r3 = atoi(str_val.c_str());
	str_val = r.substr(r.find("D") + 1, 2);
	r4 = atoi(str_val.c_str());
	str_val = r.substr(r.find("P"), 2);
	name = str_val;
	
	finish = false;
	
 	if (type == "Allocation"){
		a = r1;
		b = r2;
		c = r3;
		d = r4;
		cout << name << " Allocation (A,B,C,D): ";
		cout << a << " " << b << " " << c << " " << d << endl;
	} else if (type == "Max"){
		max_a = r1;
		max_b = r2;
		max_c = r3;
		max_d = r4;
		
		need_a = max_a - a;
		need_b = max_b - b;
		need_c = max_c - c;
		need_d = max_d - d;
		
		cout << name << " Max (A,B,C,D): ";
		cout << max_a << " " << max_b << " " << max_c << " " << max_d <<endl;
	} else if (type == "Request"){
		req_a = r1;
		req_b = r2;
		req_c = r3;
		req_d = r4;
		
		cout << name << " Request (A,B,C,D): ";
		cout << req_a << " " << req_b << " " << req_c << " " << req_d <<endl;
	}
}

