# HG changeset patch # User IBBoard # Date 1270825921 0 # Node ID eb47e17ec8249a4dbbaff0782714ede2eb20ba27 # Parent f45d28dc1d6a3357b8a2f0c669acda5a91de3b09 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") diff -r f45d28dc1d6a -r eb47e17ec824 Lang/AbstractTranslationSet.cs --- 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