
#ifndef Scheduler_h_
#define Scheduler_h_

// Author:   Chuck Stewart
//
// Purpose:  Header file for the Scheduler.  It maintains a vector of
// cages and lists of animals scheduled or waiting.  The member
// functions drive the scheduling operations.

#ifdef GNU
#define std
#endif
#include <vector>
#include <list>
#include "Cage.h"
#include "Hash.h"

class Scheduler {
public:
  enum Status{NO_FIT, SCHEDULED, WAITING_LIST};
public:
  Scheduler( );
  ~Scheduler();

  // Add a new cage.
  void AddCage( const Cage& cage );

  // Schedule an animal.  Return the status, which indicates whether
  // the animal was scheduled, put on the waiting list, or doesn't
  // fit.   It is assumed that the animal has already been checked to
  // see if it is scheduled.
  Status Schedule( Animal& animal );

  // Cancel an animal from the schedule and fill its cage with waiting
  // animals, if possible.  Return the list of animals added.  This
  // list will be empty if none were added.
  void Cancel( const std::string& name,
	       std::list<Animal>& added );

  // Check to see if an animal of the given name is scheduled or
  // waiting.  Set the status and the information about the animal, if
  // it exists.
  bool InSchedule( const std::string& name, Scheduler::Status& status,
		   Animal& animal );

  // Change the schedule for an animal.  Don't change if it will not
  // fit.  If new space opens up, add animals from the waiting list.
  bool Change( const std::string& name, const Date& new_start, 
	       int new_days, std::list<Animal>& added );

  // Output the schedule for the given day.
  void OutputSchedule( std::ostream& out_str, const Date& day );

private:
  void TryFromWaitList( int cage_num, std::list<Animal> & added );

protected:
  std::vector<Cage> cages_;      // the cages
   HashTable<Animal> scheduled_;  // the animals scheduled
   HashTable<Animal> waiting_;    // the animals on the waiting list.
   //  std::list<Animal> scheduled_;  // the animals scheduled
   //  std::list<Animal> waiting_;    // the animals on the waiting list.
}; 
  
#endif
  
  
