Mercurial > repos > IBBoard
changeset 77:eb47e17ec824
Re #35: Add multi-level cascading of translations
* Check for loops using the method defined at http://ostermiller.org/find_loop_singly_linked_list.html ("Floyd's Cycle-Finding Algorithm")
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 09 Apr 2010 15:12:01 +0000 |
parents | f45d28dc1d6a |
children | da339d10c5fe |
files | Lang/AbstractTranslationSet.cs |
diffstat | 1 files changed, 25 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/Lang/AbstractTranslationSet.cs Wed Apr 07 19:55:05 2010 +0000 +++ b/Lang/AbstractTranslationSet.cs Fri Apr 09 15:12:01 2010 +0000 @@ -59,6 +59,7 @@ if (parentTranslations != null) { + CheckForLooping(parentTranslations); parentTranslation = parentTranslations[key]; } @@ -67,6 +68,30 @@ protected abstract AbstractTranslationSet GetParentTranslations(); + private void CheckForLooping(AbstractTranslationSet translations) + { + bool hasLoop = false; + AbstractTranslationSet slowLoop = translations; + AbstractTranslationSet fastLoop1 = translations; + AbstractTranslationSet fastLoop2 = translations; + + while (slowLoop != null && (fastLoop1 = fastLoop2.GetParentTranslations()) != null && (fastLoop2 = fastLoop1.GetParentTranslations()) != null) + { + if (slowLoop.Equals(fastLoop1) || slowLoop.Equals(fastLoop2)) + { + hasLoop = true; + break; + } + + slowLoop = slowLoop.GetParentTranslations(); + } + + if (hasLoop) + { + throw new TranslationLoadException("Translations contained an inheritence loop"); + } + } + public string LanguageName { get