Untested.
Type TScenario
Global list:TList = New TList
Global current_s:TLink
Field id
Function load_scenarios()
'load the scenarios and add them to the list in the right order, or sort them after load
If list.IsEmpty() Then RuntimeError "No scenarios loaded."
restart()
End Function
Function restart()
current_s = list.FirstLink()
Assert current_s
End Function
Function get_current:TScenario()
Local scen:TScenario = TScenario(current_s.Value())
Assert scen
Return scen
End Function
Function next_scenario:Int()
'returns false and makes no change if no more scenarios
Local link:TLink = current_s.NextLink()
If link
'we find a scenario
current_s = link
Return True
Else
'link is null, we're at the end of the list
Return False
End If
End Function
Function prev_scenario:Int()
'returns false and makes no change if no more scenarios
Local link:TLink = current_s.PrevLink()
If link
'we find a scenario
current_s = link
Return True
Else
'link is null, we're at the end of the list
Return False
End If
End Function
Function set_scenario:Int(id)
'sets the current scenario to the one which matches this id number
'returns false and makes no change if scenario not found
'if you have more than a hundred scenarios, you should use a faster way
'start at the beginning of the list
Local link:TLink = list.FirstLink()
'stop if we reach the end of the list
While link
'retreive the scenario at this location
Local scen:TScenario = TScenario(link.Value())
If scen.id = id
'the id matches
current_s = link
Return True
Else
'the id doesn't match, next link
link = link.NextLink()
End If
Wend
'if we get here, then we did not find a matching scenario
Return False
End Function
End Type
Last edited 2011
|