using Bts.DataStreamCore; using System; using System.Collections; namespace BCG { /// /// All what this type does is to keep a reference to the original rows, and all accessors /// to the row, return a ProjectedRow (which is basically a wrapping around the original row) /// internal class ProjectedTable : IImmutableRowCollection { private IBlueRowCollection myRows; private ProjectHelper myHelper; internal ProjectedTable (IBlueRowCollection rows, ProjectHelper helper) { if (helper == null) throw new ArgumentException("helper"); myRows = rows ?? new BlueTable(helper.schema); myHelper = helper; } #region IBlueRowCollection Members public IBlueRow this [int id] { get {return new ProjectedRow (myRows[id], myHelper);} } public bool containsID(int id) {return myRows.containsID (id);} public IBlueTableSchema schema {get {return myHelper.schema;}} #endregion #region ICollection Members public bool IsSynchronized {get {return myRows.IsSynchronized;}} public int Count {get {return myRows.Count;}} public void CopyTo (Array array, int index) { foreach (IBlueRow r in myRows) array.SetValue(this[r.Id()], index++); } public object SyncRoot {get {return myRows.SyncRoot;}} #endregion #region IEnumerable Members public IEnumerator GetEnumerator () { return new MyEnumerator (myRows, myHelper); } private class MyEnumerator : IEnumerator { #region IEnumerator Members private IEnumerator myMaster; private ProjectHelper myHelper; public MyEnumerator (IBlueRowCollection master, ProjectHelper helper) { myMaster = master.GetEnumerator (); myHelper = helper; } public void Reset() {myMaster.Reset();} public object? Current => myMaster.Current is null ? null : new ProjectedRow((IBlueRow)myMaster.Current, myHelper); public bool MoveNext() {return myMaster.MoveNext ();} #endregion } #endregion } }