diff --git a/src/Bonsai.ML.HiddenMarkovModels/PythonStringBuilder.cs b/src/Bonsai.ML.HiddenMarkovModels/PythonStringBuilder.cs new file mode 100644 index 00000000..c86a8b4c --- /dev/null +++ b/src/Bonsai.ML.HiddenMarkovModels/PythonStringBuilder.cs @@ -0,0 +1,35 @@ +using System; +using System.Text; + +namespace Bonsai.ML.HiddenMarkovModels +{ + public abstract class PythonStringBuilder + { + + private string _cachedString; + private bool _updateString; + protected readonly StringBuilder StringBuilder = new StringBuilder(); + + protected void UpdateString() + { + _updateString = true; + } + + protected virtual string BuildString() + { + return StringBuilder.ToString(); + } + + public override string ToString() + { + if (_updateString) + { + _cachedString = BuildString(); + _updateString = false; + } + return _cachedString; + } + } +} + +