- Timestamp:
- 02/10/17 15:13:29 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistentDataStructures/HeuristicLab.Data/3.3/ValueTypeArray.cs
r14650 r14657 44 44 protected T[] oldArrayValuePersistence { set { historyArray = new HistoryArray<T>(value); } } 45 45 46 [Storable(AllowOneWay = true, Name = "elementNames")] 47 protected List<string> oldElementNamesValuePersistence { set { historyElementNames = new HistoryList<string>(value); } } 48 46 49 [Storable] 47 50 protected HistoryArray<T> historyArray; 48 51 49 52 [Storable] 50 protected List<string> elementNames; 53 protected HistoryList<string> historyElementNames; 54 51 55 public virtual IEnumerable<string> ElementNames { 52 get { return this. elementNames; }56 get { return this.historyElementNames; } 53 57 set { 54 58 if (ReadOnly) throw new NotSupportedException("ElementNames cannot be set. ValueTypeArray is read-only."); 55 59 if (value == null || !value.Any()) 56 elementNames = newList<string>();60 historyElementNames = new HistoryList<string>(); 57 61 else if (value.Count() > Length) 58 62 throw new ArgumentException("The number of element names must not exceed the array length."); 59 else 60 elementNames = newList<string>(value);63 else 64 historyElementNames = new HistoryList<string>(value); 61 65 OnElementNamesChanged(); 62 66 } … … 71 75 if (value != Length) { 72 76 historyArray.Resize(value); 73 while ( elementNames.Count > value)74 elementNames.RemoveAt(elementNames.Count - 1);77 while (historyElementNames.Count > value) 78 historyElementNames.RemoveAt(historyElementNames.Count - 1); 75 79 OnElementNamesChanged(); 76 80 OnReset(); … … 112 116 [StorableHook(HookType.AfterDeserialization)] 113 117 private void AfterDeserialization() { 114 if ( elementNames == null) { elementNames = newList<string>(); }118 if (historyElementNames == null) { historyElementNames = new HistoryList<string>(); } 115 119 } 116 120 … … 122 126 this.readOnly = original.readOnly; 123 127 this.resizable = original.resizable; 124 this. elementNames = new List<string>(original.elementNames);128 this.historyElementNames = (HistoryList<string>)original.historyElementNames.Clone(); 125 129 } 126 130 protected ValueTypeArray() { … … 128 132 readOnly = false; 129 133 resizable = true; 130 elementNames = newList<string>();134 historyElementNames = new HistoryList<string>(); 131 135 } 132 136 protected ValueTypeArray(int length) { … … 134 138 readOnly = false; 135 139 resizable = true; 136 elementNames = newList<string>();140 historyElementNames = new HistoryList<string>(); 137 141 } 138 142 protected ValueTypeArray(T[] elements) { … … 141 145 readOnly = false; 142 146 resizable = true; 143 elementNames = new List<string>(); 147 historyElementNames = new HistoryList<string>(); 148 } 149 private ValueTypeArray(HistoryArray<T> values, HistoryList<string> historyElementNames) { 150 this.historyArray = values; 151 this.historyElementNames = historyElementNames; 144 152 } 145 153 … … 205 213 OnToStringChanged(); 206 214 } 215 216 public void CreateSnapshot() { 217 historyArray.CreateSnapshot(); 218 historyElementNames.CreateSnapshot(); 219 } 220 221 public IEnumerable<ValueTypeArray<T>> GetHistory() { 222 foreach (var vta in historyArray.GetHistory().Zip(historyElementNames.GetHistory(), (v, n) => new {v, n})) { 223 var clone = (ValueTypeArray<T>)Clone(); 224 clone.historyArray = vta.v; 225 clone.historyElementNames = vta.n; 226 yield return clone; 227 } 228 } 207 229 } 208 230 }
Note: See TracChangeset
for help on using the changeset viewer.