/*------------------------------------------------------------------------------
Description: Log class for elevator project
Author: Chris Huyler
Language: C++
Name: log.h
Date: April 30, 2000
------------------------------------------------------------------------------*/


#include <conio.h>
#include <fstream.h>
ofstream fout("ElevatorLog.txt");

/*   Singleton Class ! ! !  */
class Log {
	public:
      static Log* Instance();
   	void Print_FloorButtonPress(int fbID, string d);
      void Print_ElevatorButtonPress(int ebID,int ID);
      void Print_ElevatorMove(int c,int n,int ID);
      void Print_ElevatorWait(int c,int ID);
      void Print_ElevatorStop(int c,int ID);
      void Print_ElevatorLoad(int c,int ID);
 	  void Print_ElevatorUnload(int c,int ID);
      void Print_Time();
      void Log_Time(int t);

	private:

      static Log* instance;
    	int time;
      bool printed;     // bool to make sure time is printed once per second
    protected:
    	Log();
};

Log::Log(){}
Log* Log::instance = 0;
Log* Log::Instance(){
	if(instance == 0)
    	instance = new Log;
    return(instance);
}

void Log::Log_Time(int t){
	time = t;
    printed = false;
}
void Log::Print_Time(){
    cout << endl;
    fout << endl;
    if(!printed)
    {
    	printed = true;
		int sec = time%60;
   	int min = time/60;
   	cout << "< " << min << ":";
      fout << "< " << min << ":";
   	if(sec<10)
      {
   		cout << "0";
         fout << "0";
      }
    	cout << sec << " > ";
      fout << sec << " > ";
	}
    else
    {
    	cout << "\t";
      fout << "\t";
    }
}
void Log::Print_FloorButtonPress(int fbID, string d){
	Print_Time();
    fbID++;
	cout << "\t\t*Request on floor " << fbID << " in " << d << " direction. ";
   fout << "\t\t*Request on floor " << fbID << " in " << d << " direction. ";
}
void Log::Print_ElevatorButtonPress(int f,int ID){
	Print_Time();
    ID++;f++;
	cout << "\t\t*Floor " << f << " stop requested on Elevator "<<ID<<".";
   fout << "\t\t*Floor " << f << " stop requested on Elevator "<<ID<<".";
}
void Log::Print_ElevatorMove(int c,int n,int ID){
	Print_Time();
    ID++;c++;n++;
	cout << "\t\tElevator "<<ID<<" moving from floor " << c << " to floor " << n << ".";
   fout << "\t\tElevator "<<ID<<" moving from floor " << c << " to floor " << n << ".";
}
void Log::Print_ElevatorWait(int c,int ID){
	Print_Time();
    ID++;c++;
	cout << "\t\tElevator "<<ID<<" waiting on floor " << c << ".";
   fout << "\t\tElevator "<<ID<<" waiting on floor " << c << ".";
}
void Log::Print_ElevatorStop(int c,int ID){
	Print_Time();
    ID++;c++;
	cout << "\t\tElevator "<<ID<<" stopped on floor " << c << ".";
   fout << "\t\tElevator "<<ID<<" stopped on floor " << c << ".";
}
void Log::Print_ElevatorLoad(int c,int ID) {
	Print_Time();
    ID++;c++;
	cout << "\t\tElevator "<<ID<<" loading on floor " << c << ".";
   fout << "\t\tElevator "<<ID<<" loading on floor " << c << ".";
}
void Log::Print_ElevatorUnload(int c,int ID) {
	Print_Time();
    ID++;c++;
	cout << "\t\tElevator "<<ID<<" unloading on floor " << c << ".";
   fout << "\t\tElevator "<<ID<<" unloading on floor " << c << ".";
}

