
#ifndef Cage_h_
#define Cage_h_

// Author:  Chuck Stewart
//
// Purpose: Scheduling operations and representation for an individual
// cage.  Each day of the year is represented.  The crucial
// information is in two fixed length arrays indicating for each
// julian day whether or not the cage is filled, and if so which
// animal fills it. 
//
// There were numerous options for representing the animals in the
// cages.   The fixed length array option chosen here is substantially
// more efficent and easier to use than keeping a list of animals in
// the cage (perhaps ordered by the start time of their stay).  Added
// flexibility could be obtained by making the arrays dynamic
// (vectors).    Finally, rather than having two arrays, I could have
// used an array of pairs.  The disadvantage to this, which I found
// convincing, is that the code becomes much less readable:  there
// much less semantic information in the names "first" and "second"
// than in "filled_" and "schedule_".

#ifdef GNU
#define std
#endif

#include "Animal.h"

class Cage {
public:
  Cage() {}
  Cage( int min_weight, int max_weight );
  ~Cage();

  // Operators to keep VC++ happy.
  bool operator==(const Cage & x) const;
  bool operator<(const Cage & x) const;

  // Return true if and only if the animal's weight is within range
  // for the cage.
  bool InWeightRange( const Animal & animal ) const;

  // Schedule an animal for its starting and ending days, if possible.  
  bool Schedule( const Animal& animal );

  // Cancel an animal from the schedule.
  void Cancel( const Animal& animal );

  // What animal, if any, is scheduled for the given day?
  bool OnDay( const Date& day, Animal& animal ) const;
  
protected:
  int min_weight_, max_weight_;
  bool filled_[MaxDays+1];
  Animal schedule_[MaxDays+1];
};

#endif
