using System; using System.IO; using System.Text; using System.Collections; using System.Collections.Generic; namespace Com.Xagasoft.Gats { public class GatsList : GatsObject, IList, ICollection, IEnumerable // IReadOnlyList, IReadOnlyCollection, // These two are in .net 4.5, not 4.0, mono can't use them. { private List Value = new List(); public GatsList() { } public override string ToString() { StringBuilder bld = new StringBuilder(); bld.Append("["); for( int j = 0; j < Value.Count-1; j++ ) { bld.Append( Value[j] ); bld.Append(", "); } bld.Append( Value[Value.Count-1] ); bld.Append("]"); return bld.ToString(); } public override void Read( Stream s, char type ) { for(;;) { GatsObject obj = GatsObject.Read( s ); if( obj == null ) break; Value.Add( obj ); } } public override void Write( Stream s ) { s.WriteByte( (int)'l' ); foreach( GatsObject obj in Value ) { obj.Write( s ); } s.WriteByte( (int)'e' ); } // // List interface overrides under here. // public int IndexOf( GatsObject obj ) { return Value.IndexOf( obj ); } public void Insert( int idx, GatsObject obj ) { Value.Insert( idx, obj ); } public void RemoveAt( int idx ) { Value.RemoveAt( idx ); } public GatsObject this[int idx] { get { return this.Value[idx]; } set { this.Value[idx] = value; } } public int Count { get { return this.Value.Count; } } public bool IsReadOnly { get { return false; } // this.Value.IsReadOnly; } } public void Add( GatsObject obj ) { Value.Add( obj ); } public void Clear() { Value.Clear(); } public bool Contains( GatsObject obj ) { return Value.Contains( obj ); } public void CopyTo( GatsObject[] result, int count ) { Value.CopyTo( result, count ); } public bool Remove( GatsObject obj ) { return Value.Remove( obj ); } IEnumerator IEnumerable.GetEnumerator() { return Value.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return Value.GetEnumerator(); } public bool IsFixedSize { get { return false; } // this.Value.IsFixedSize; } } public bool IsSynchronized { get { return false; } // this.Value.IsSynchronized; } } public object SyncRoot { get { return null; } // this.Value.SyncRoot; } } } }