vtm/quelldatein/helfer/brauch.ts

87 lines
1.9 KiB
TypeScript
Raw Normal View History

2018-03-27 19:21:40 +02:00
/*
* Verrückte Turing-Maschinen A turing complete game
* Copyright (C) 2016 Christian Fraß <vidofnir@folksprak.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
module lib_brauch
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
export type typ_brauch<typ_signatur> = {[domäne : string] : typ_signatur};
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function erstellen<typ_signatur>
(
)
: typ_brauch<typ_signatur>
{
return {};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function umsetzen<typ_signatur>
(
brauch : typ_brauch<typ_signatur>,
domaene : string,
implementierung : typ_signatur
)
: void
{
if (domaene in brauch)
{
let meldung : string = ("Domäne '" + domaene + "' bereits vorhanden");
throw (new Error(meldung));
}
else
{
brauch[domaene] = implementierung;
}
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function anwenden<typ_signatur>
(
brauch : typ_brauch<typ_signatur>,
domaene : string
)
: typ_signatur
{
if (! (domaene in brauch))
{
let meldung : string = ("keine Implementierung für Domäne '" + domaene + "' vorhanden");
throw (new Error(meldung));
}
else
{
return brauch[domaene];
}
}
}