/// <summary> /// Resets the engine to offset. Clears all cached engines after the given offset. /// </summary> public void ResetEngineToPosition(int lineNumber) { // We are already there if (currentEngine.LineNumber <= lineNumber) { return; } bool gotCachedEngine = false; while (cachedEngines.Count > 0) { var topEngine = cachedEngines.Peek(); if (topEngine.LineNumber <= lineNumber) { currentEngine = topEngine.Clone(); gotCachedEngine = true; break; } else { cachedEngines.Pop(); } } if (!gotCachedEngine) { currentEngine.Reset(); } }
/// <summary> /// Creates a new CacheIndentEngine instance from the given prototype. /// </summary> /// <param name="prototype"> /// A CacheIndentEngine instance. /// </param> public CacheIndentEngine(CacheIndentEngine prototype) { currentEngine = prototype.currentEngine.Clone(); }
/// <summary> /// Creates a new CacheIndentEngine instance. /// </summary> /// <param name="decoratedEngine"> /// An instance of <see cref="IDocumentIndentEngine"/> to which the /// logic for indentation will be delegated. /// </param> /// <param name="cacheRate"> /// The number of lines between caching. /// </param> public CacheIndentEngine(IDocumentIndentEngine decoratedEngine, int cacheRate = 50) { this.cacheRate = cacheRate; currentEngine = decoratedEngine; }