aboutsummaryrefslogtreecommitdiff
path: root/cs-dotnet/src/gatslist.cs
blob: 7d570355dacf64f764d296edcfd34e3181d9360c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * Copyright (C) 2007-2012 Xagasoft, All rights reserved.
 *
 * This file is part of the libgats library and is released under the
 * terms of the license contained in the file LICENSE.
 */

using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

namespace Com.Xagasoft.Gats
{
    public class GatsList : GatsObject, IList<GatsObject>,
        ICollection<GatsObject>, IEnumerable<GatsObject>
//        IReadOnlyList<GatsObject>, IReadOnlyCollection<GatsObject>,
//        These two are in .net 4.5, not 4.0, mono can't use them.
    {
        private List<GatsObject> Value = new List<GatsObject>();

        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<GatsObject> IEnumerable<GatsObject>.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; }
        }

    }
}