/* platform.h
 *
 * The platform class.  A passenger arrives at a platform and waits
 * Forc++-mode
 * a train.  After a train arrives and has disgorged its
 * passengers, the train asks the platform to signal all waiting
 * passengers of its arrival.  The platform then moves into the
 * train those passengers that want to enter the train.
 */


#ifndef PLATFORM_H
#define PLATFORM_H

#include <string.h>
#include "seq.h"

#define PLATFORM_CAPACITY  200

class Passenger;
class Train;
class Station;
class Section;


class Platform {

  friend void setupNetwork(char *c); // can initialize
  friend void setPlatformSections();

  seq<Passenger*> passengers;	// list of passengers on the platform
  Station *station;		// station containing this platform
  Section *section;		// track section beside the platform

public:

  char *platformName;		// name of platform

  // Constructors

  Platform( char *name, Station *thisStation, Section *sect ) {
    platformName = strdup(name);
    station = thisStation;
    section = sect;
  }

  Platform( char *name ) {
    platformName = strdup(name);
  }

  // Add a passenger, p, to the platform

  void addPassenger( Passenger *p );

  // Signal to all passengers on the platform that a particular train,
  // t, has arrived.  Those who want to enter the train are
  // transferred to the train if it has space for more passengers.

  void signalTrainArrival( Train *t );

  // Count the number of passengers who will board a train, t

  int countBoardingPassengers( Train *t );

  // Access function

  Station *thisStation() { return station; }
  char    *name()        { return platformName; }
  Section *adjSection()  { return section; }

  // Output operators

  void draw();

  void printPassengers();

  friend ostream& operator << ( ostream& stream, Platform const &p ) {
    stream << p.platformName;
    return stream;
  }
};

#endif
