Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/10/17 15:13:29 (7 years ago)
Author:
epitzer
Message:

#2727 add generic MetaInfo to AMT e.g. for tracking Count in facades

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PersistentDataStructures/HeuristicLab.Data/3.3/ValueTypeArray.cs

    r14650 r14657  
    4444    protected T[] oldArrayValuePersistence { set { historyArray = new HistoryArray<T>(value); } }
    4545
     46    [Storable(AllowOneWay = true, Name = "elementNames")]
     47    protected List<string> oldElementNamesValuePersistence { set { historyElementNames = new HistoryList<string>(value); } }
     48
    4649    [Storable]
    4750    protected HistoryArray<T> historyArray;
    4851
    4952    [Storable]
    50     protected List<string> elementNames;
     53    protected HistoryList<string> historyElementNames;
     54
    5155    public virtual IEnumerable<string> ElementNames {
    52       get { return this.elementNames; }
     56      get { return this.historyElementNames; }
    5357      set {
    5458        if (ReadOnly) throw new NotSupportedException("ElementNames cannot be set. ValueTypeArray is read-only.");
    5559        if (value == null || !value.Any())
    56           elementNames = new List<string>();
     60          historyElementNames = new HistoryList<string>();
    5761        else if (value.Count() > Length)
    5862          throw new ArgumentException("The number of element names must not exceed the array length.");
    59         else
    60           elementNames = new List<string>(value);
     63        else 
     64          historyElementNames = new HistoryList<string>(value);
    6165        OnElementNamesChanged();
    6266      }
     
    7175        if (value != Length) {
    7276          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);
    7579          OnElementNamesChanged();
    7680          OnReset();
     
    112116    [StorableHook(HookType.AfterDeserialization)]
    113117    private void AfterDeserialization() {
    114       if (elementNames == null) { elementNames = new List<string>(); }
     118      if (historyElementNames == null) { historyElementNames = new HistoryList<string>(); }
    115119    }
    116120
     
    122126      this.readOnly = original.readOnly;
    123127      this.resizable = original.resizable;
    124       this.elementNames = new List<string>(original.elementNames);
     128      this.historyElementNames = (HistoryList<string>)original.historyElementNames.Clone();
    125129    }
    126130    protected ValueTypeArray() {
     
    128132      readOnly = false;
    129133      resizable = true;
    130       elementNames = new List<string>();
     134      historyElementNames = new HistoryList<string>();
    131135    }
    132136    protected ValueTypeArray(int length) {
     
    134138      readOnly = false;
    135139      resizable = true;
    136       elementNames = new List<string>();
     140      historyElementNames = new HistoryList<string>();
    137141    }
    138142    protected ValueTypeArray(T[] elements) {
     
    141145      readOnly = false;
    142146      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;
    144152    }
    145153
     
    205213      OnToStringChanged();
    206214    }
     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    }
    207229  }
    208230}
Note: See TracChangeset for help on using the changeset viewer.