Changeset 15334 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/PrintStack.cs
- Timestamp:
- 08/21/17 11:33:53 (7 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP
- Property svn:ignore
-
old new 1 1 *.user 2 packages 3 TestResults
-
- Property svn:ignore
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/PrintStack.cs
r15289 r15334 14 14 public class PrintStack : IPrintStack { 15 15 private int lineCount = 0; 16 private int length = 0; 17 private IReadOnlyList<string> lines; 16 18 private readonly StringBuilder stringBuilder = new StringBuilder(); 17 19 20 public PrintStack() { 21 IsCurrentLineEmpty = true; 22 } 23 24 public bool IsCurrentLineEmpty { get; private set; } 25 18 26 IEnumerator IEnumerable.GetEnumerator() { 19 var lines = AsStrings(); 20 return lines.GetEnumerator(); 27 return Lines.GetEnumerator(); 21 28 } 22 29 … … 25 32 } 26 33 34 public IReadOnlyList<string> Lines 35 { 36 get 37 { 38 if (stringBuilder.Length == length) return lines; 39 length = stringBuilder.Length; 40 lines = stringBuilder.ToString().Split(PushEnvironment.NewLine); 41 42 return lines; 43 } 44 } 45 27 46 void IPushStack.Clear() { 47 lineCount = 0; 48 length = 0; 49 lines = null; 50 IsCurrentLineEmpty = true; 28 51 stringBuilder.Clear(); 29 52 } … … 31 54 public void NewLine() { 32 55 stringBuilder.Append(PushEnvironment.NewLine); 56 IsCurrentLineEmpty = true; 33 57 lineCount++; 34 58 } … … 36 60 public void Push<T>(T item) { 37 61 if (IsEmpty) lineCount = 1; 38 stringBuilder.Append(item); 62 var str = item.ToString(); 63 stringBuilder.Append(str); 64 IsCurrentLineEmpty = IsCurrentLineEmpty && string.IsNullOrEmpty(str); 39 65 } 40 66 … … 42 68 if (IsEmpty) lineCount = 1; 43 69 stringBuilder.Concat(item); 70 IsCurrentLineEmpty = false; 44 71 } 45 72 … … 47 74 if (IsEmpty) lineCount = 1; 48 75 stringBuilder.Concat(item); 76 IsCurrentLineEmpty = false; 49 77 } 50 78 … … 52 80 if (IsEmpty) lineCount = 1; 53 81 stringBuilder.Concat(item); 82 IsCurrentLineEmpty = false; 54 83 } 55 84 … … 57 86 if (IsEmpty) lineCount = 1; 58 87 stringBuilder.Concat(item); 88 IsCurrentLineEmpty = false; 59 89 } 60 90 … … 62 92 if (IsEmpty) lineCount = 1; 63 93 stringBuilder.Append(item); 94 IsCurrentLineEmpty = false; 64 95 } 65 96 … … 67 98 if (IsEmpty) lineCount = 1; 68 99 stringBuilder.Append(item); 100 IsCurrentLineEmpty = false; 69 101 } 70 71 102 72 103 public void Push(string item) { 73 104 if (IsEmpty) lineCount = 1; 74 105 stringBuilder.Append(item); 106 IsCurrentLineEmpty = IsCurrentLineEmpty && string.IsNullOrEmpty(item); 75 107 } 76 108 … … 78 110 for (var i = startIndex; i < items.Count; i++) 79 111 stringBuilder.Append(items[i]); 112 113 IsCurrentLineEmpty = false; 80 114 } 81 115 … … 87 121 foreach (var item in items) 88 122 stringBuilder.Append(item); 123 124 IsCurrentLineEmpty = false; 89 125 } 90 126 91 127 public IEnumerable<string> AsStrings() { 92 var lines = stringBuilder.ToString().Split(PushEnvironment.NewLine); 93 return lines; 128 return Lines; 94 129 } 95 130 96 131 public IEnumerable<object> AsObjects() { 97 return AsStrings();132 return Lines; 98 133 } 99 134
Note: See TracChangeset
for help on using the changeset viewer.