using System; using System.Collections; using BCG.Utilities; using BCG; namespace BCG { /// /// Representation of each row formed by this Join. The Enumerator for the LightForeignJoinCollection /// returns object of this type. Contains 3 pointers, to the left row, right row and schema respectively. /// So each row is expected to have 12 bytes worth of pointers and 8 byte overhead for itself (as is the /// case for all objects), so its a 20 byte package. /// public class LightForeignJoinRow : IBlueRow { protected IBlueRow myReDRow, myRingGRow; protected IBlueTableSchema mySchema; #region Constructor(s) public LightForeignJoinRow (IBlueRow reDRow, IBlueRow rinGRow, IBlueTableSchema schema) { myReDRow = reDRow; myRingGRow = rinGRow; mySchema = schema; } #endregion #region IBlueRow members public IBlueTableSchema schema {get{return mySchema;}} #endregion #region ICollection members public int Count{get{return mySchema.columnNames.Length;}} public bool IsSynchronized {get{return false;}} public object SyncRoot{get{return this;}} public void CopyTo (Array array, int index) { int i = 0; foreach (object o in this as IEnumerable) array.SetValue (o, i++); } #endregion #region IDictionary members public bool IsFixedSize {get{return true;}} public bool IsReadOnly {get{return true;}} /// /// The key can either be the string corrsponding to the column name or /// the order of the column /// public virtual object this [object key] { get {return key is string ? this [key as string] : this [(int)key];} set {throw new NotSupportedException ("The IBlueRow is read only");} } public virtual object this [int index] { get { if (index == mySchema.columnNames.Length - 1) return myRingGRow["id"]; if (index < myRingGRow.Count) return myRingGRow[index]; else if (index >= myRingGRow.Count && index < mySchema.columnNames.Length - 1) return myReDRow[index - myRingGRow.Count]; // BlueEventLog.logAssert (false, "Incorrect index in JoinRow"); return null; } } public object this [string colName] {get{return this[mySchema[colName].colNo];}} public ICollection Keys{get{return mySchema.columnNames;}} public ICollection Values { get { object[] retVal = new object[mySchema.columnNames.Length]; CopyTo (retVal, 0); return retVal; } } public void Add (object key, object? value) => throw new NotSupportedException ("The IBlueRow is readonly"); public void Clear () {throw new NotSupportedException ("The IBlueRow is readonly");} public bool Contains (object key){return mySchema[(string)key] != null;} /// /// Note, the default enumerator is the IDictionary's enumerator, so if user needs to /// iterate through the values, typecast this into an IEnumerable /// /// public IDictionaryEnumerator GetEnumerator() {return new BlueRowDictionaryEnumerator(this);} IEnumerator IEnumerable.GetEnumerator () {return new BlueRowEnumerator(this);} public void Remove (object key) {throw new NotSupportedException ("The IBlueRow is readonly");} #endregion } }