Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/28/18 16:56:41 (6 years ago)
Author:
bburlacu
Message:

#2886: address additional serialization issues, make Production implement IList<T> instead of deriving from List<T>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Symbol.cs

    r15974 r15975  
    11using System;
     2using System.Collections;
    23using System.Collections.Generic;
     4using System.Linq;
    35using HeuristicLab.Common;
    46using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    101103
    102104  [StorableClass]
    103   public class Production : List<Symbol>, IDeepCloneable {
     105  public class Production : DeepCloneable, IList<Symbol> {
     106    [Storable]
     107    private List<Symbol> symbols;
    104108
    105     public Production(params Symbol[] symbols) : base(symbols) { }
     109    public int Count { get { return symbols.Count; } }
    106110
    107     public Production(IEnumerable<Symbol> symbols) : base(symbols) { }
     111    public bool IsReadOnly => throw new NotImplementedException();
     112
     113    public Symbol this[int index] { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
     114
     115    public Production(params Symbol[] symbols) {
     116      this.symbols = symbols.ToList();
     117    }
     118
     119    public Production(IEnumerable<Symbol> symbols) {
     120      this.symbols = symbols.ToList();
     121    }
    108122
    109123    [StorableConstructor]
    110124    protected Production(bool deserializing) { }
    111125
    112     protected Production(Production original, Cloner cloner) : this(original) {
    113       cloner.RegisterClonedObject(original, this);
     126    protected Production(Production original, Cloner cloner) {
     127      symbols = original.symbols.Select(cloner.Clone).ToList();
    114128    }
    115129
    116     public IDeepCloneable Clone(Cloner cloner) {
     130    public override IDeepCloneable Clone(Cloner cloner) {
    117131      return new Production(this, cloner);
    118     }
    119 
    120     public object Clone() {
    121       return Clone(new Cloner());
    122132    }
    123133
     
    125135      return string.Join(" ", this);
    126136    }
     137
     138    #region IList<Symbol> methods
     139    public IEnumerator<Symbol> GetEnumerator() {
     140      return symbols.GetEnumerator();
     141    }
     142
     143    IEnumerator IEnumerable.GetEnumerator() {
     144      return GetEnumerator();
     145    }
     146
     147    public int IndexOf(Symbol item) {
     148      return symbols.IndexOf(item);
     149    }
     150
     151    public void Insert(int index, Symbol item) {
     152      symbols.Insert(index, item);
     153    }
     154
     155    public void RemoveAt(int index) {
     156      symbols.RemoveAt(index);
     157    }
     158
     159    public void Add(Symbol item) {
     160      symbols.Add(item);
     161    }
     162
     163    public void Clear() {
     164      symbols.Clear();
     165    }
     166
     167    public bool Contains(Symbol item) {
     168      return symbols.Contains(item);
     169    }
     170
     171    public void CopyTo(Symbol[] array, int arrayIndex) {
     172      symbols.CopyTo(array, arrayIndex);
     173    }
     174
     175    public void CopyTo(int index, Symbol[] array, int arrayIndex, int count) {
     176      symbols.CopyTo(index, array, arrayIndex, count);
     177    }
     178
     179    public bool Remove(Symbol item) {
     180      return symbols.Remove(item);
     181    }
     182    #endregion
    127183  }
    128184}
Note: See TracChangeset for help on using the changeset viewer.