unit clock; {clocks for all flavors of simulation} {the OOP version for turbo Pascal 6.0} INTERFACE type aClockType = OBJECT NOW : REAL; constructor Init; procedure AdvanceTo (newtime : REAL); {set clock ahead} function TellTime : REAL; procedure rite; {writes as 8:2} end; {aClockType} anAsyncClockType = OBJECT(aClockType) TimeOfNextEvent : REAL; constructor Init; end; aSyncClockType = OBJECT(anAsyncClockType) resolution : REAL; {length of time-slice} constructor Init (resolutionP:REAL); end; {------- aSyncClockType inherits NOW TimeofNextEvent and the method TellTime (from aClockType) --------------------------------------} var TheClock : anAsyncClockType ; {the clock is visible to all} Function TIME : real; {returns current global time} IMPLEMENTATION constructor aClockType.Init; begin NOW := 0.0 end; procedure aClockType.AdvanceTo (newtime : REAL); {set clock ahead} begin if newtime >= NOW then NOW := newtime else WRITELN ('CLOCK CANNOT RUN BACKWARDS FROM ',NOW:8:2,' TO',newtime:8:2); end; function aClockType.TellTime : REAL; begin TellTime := NOW; end; procedure aClockType.rite; begin write (now:8:2,' ') end; constructor anAsyncClockType.Init; const aLongNumber = MAXINT; begin aClockType.Init; {parent's Init} TimeOfNextEvent := aLongNumber; {additional init.} end; constructor aSyncClockType.Init (resolutionP:REAL); begin anAsyncClockType.Init; {all ancestors Init} {NOTE: This picks up init of TimeOfNextEvent, which was left out of the Cont. toolbox!} if resolutionP <= 0 then begin WRITELN ('Time grain can''t be negative or zero! Set to 1.'); resolution := 1; end else resolution := resolutionP; end; function TIME:real; begin Time := TheClock.NOW; end; begin {unit initialization code} theClock.Init; {construct the clock} END.