// $Source: /usr/local/SimSoft/Sfx3D/src/gsl/route.cpp,v $
// $Revision: 1.2 $
// $Author: baum $
// $Date: 2001/11/29 15:18:10 $
//
// Login name of the user who locked the revision
// $Locker:  $
// Tag name used to checkout the file
// $Name:  $
// State assigned to revision
// $State: Exp $
//
//
// $Log: route.cpp,v $
// Revision 1.2  2001/11/29 15:18:10  baum
// -Realzeitsteuerung eingebaut
// -Handsteuerung eingebaut
//

#define _ROUTE_CPP
#include "modell.h"
#include "route.h"

#include "transp.h"
#include "baustein.h"

//-----------------------------------------------------
//   class typTransportRoute
//-----------------------------------------------------                      

typTransportRoute::typTransportRoute (unsigned n)
 : ObjNummer      (n),
   ObjTempEin     (0),
   ObjTempAus     (0),
   ObjStationen   (),
   ObjDlzRegister (NULL)
 { }

typTransportRoute::~typTransportRoute () {
  if (ObjDlzRegister) delete ObjDlzRegister;
}

unsigned typTransportRoute::Nummer () const {
  return ObjNummer;
}

unsigned typTransportRoute::TempEin () const {
  return ObjTempEin;
}

unsigned typTransportRoute::TempAus () const {
  return ObjTempAus;
}

typBaustein* typTransportRoute::nextBaustein (typBaustein* zS) const {
  LCursor<typBaustein> c (ObjStationen);
  while (c && (c () != zS)) c++;
  return ++c;
}

const List<typBaustein>& typTransportRoute::Stationen () const {
  return ObjStationen;
}

Register *typTransportRoute::DlzRegister () const {
  return ObjDlzRegister;
}

void typTransportRoute::setDlzRegister (Register *newReg) {
  ObjDlzRegister = newReg;
}

void typTransportRoute::startBDE () {
  ObjTempEin++;
}

void typTransportRoute::stopBDE (typTransportEinheit *zTE) {
  ObjTempAus++;
  if (ObjDlzRegister) ObjDlzRegister->erfassen (zTE->TransportRouteLaufzeit ().inMinutes ());
}

void typTransportRoute::lesen (InputFile& file) {
  SFXToken tok;
  int nr, anzahl;

  tok.nextToken (file);
  anzahl = atoi (tok ());
  for (int s = 1; s <= anzahl; s++) {
    tok.nextToken (file);
    nr = atoi (tok ());
    ObjStationen.append (*(baustein [nr]));
  } // for
}

ostream& typTransportRoute::schreiben (ostream& ostrm) const {
  ostrm << "TFK: ";
  ostrm.width (4);
  ostrm << ObjStationen.Count () << "  ";
  for (LCursor<typBaustein> c (ObjStationen); c; c++) {
    ostrm.width (3);
    ostrm << c ()->Nummer () << " ";
  }
  ostrm << endl;
  return ostrm;
}

ostream& typTransportRoute::schreibeZustand (ostream& ostrm) const {
  ostrm << "TempEin = ";
  ostrm.width (4);
  ostrm << ObjTempEin << " TempAus = ";
  ostrm.width (4);
  ostrm << ObjTempEin << "    ";
  if (ObjDlzRegister)
    ostrm << (*ObjDlzRegister);
  return ostrm;
}

ostream& typTransportRoute::schreibeProtokoll (ostream& ostrm) const {
  ostrm << "typTransportRoute::schreibeProtokoll nicht implementiert" << endl;
  return ostrm;
}

