aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-11-15 19:22:26 +0000
committerMike Buland <eichlan@xagasoft.com>2012-11-15 19:22:26 +0000
commitb9b5a5fc16e21387b3350260d2139b293bbcd2b0 (patch)
treef7d7203af2efe8f41bbeeb8fcdd649c4ec3390c0
parentf1e413e914b9f03607194757848bab1ed4f401a3 (diff)
downloadlibgats-b9b5a5fc16e21387b3350260d2139b293bbcd2b0.tar.gz
libgats-b9b5a5fc16e21387b3350260d2139b293bbcd2b0.tar.bz2
libgats-b9b5a5fc16e21387b3350260d2139b293bbcd2b0.tar.xz
libgats-b9b5a5fc16e21387b3350260d2139b293bbcd2b0.zip
Much overriding was done, but GatsList works great. And just like a standard
.net list.
-rw-r--r--cs-dotnet/src/gatslist.cs135
-rw-r--r--cs-dotnet/src/gatsobject.cs2
-rw-r--r--cs-dotnet/src/gatsstring.cs7
-rw-r--r--cs-dotnet/src/tests/lists.cs43
4 files changed, 185 insertions, 2 deletions
diff --git a/cs-dotnet/src/gatslist.cs b/cs-dotnet/src/gatslist.cs
new file mode 100644
index 0000000..d111bac
--- /dev/null
+++ b/cs-dotnet/src/gatslist.cs
@@ -0,0 +1,135 @@
1using System;
2using System.IO;
3using System.Text;
4using System.Collections;
5using System.Collections.Generic;
6
7namespace Com.Xagasoft.Gats
8{
9 public class GatsList : GatsObject, IList<GatsObject>,
10 ICollection<GatsObject>, IEnumerable<GatsObject>
11// IReadOnlyList<GatsObject>, IReadOnlyCollection<GatsObject>,
12// These two are in .net 4.5, not 4.0, mono can't use them.
13 {
14 private List<GatsObject> Value = new List<GatsObject>();
15
16 public GatsList()
17 {
18 }
19
20 public override string ToString()
21 {
22 StringBuilder bld = new StringBuilder();
23 bld.Append("[");
24 for( int j = 0; j < Value.Count-1; j++ )
25 {
26 bld.Append( Value[j] );
27 bld.Append(", ");
28 }
29 bld.Append( Value[Value.Count-1] );
30 bld.Append("]");
31 return bld.ToString();
32 }
33
34 public override void Read( Stream s, char type )
35 {
36 for(;;)
37 {
38 GatsObject obj = GatsObject.Read( s );
39 if( obj == null )
40 break;
41 Value.Add( obj );
42 }
43 }
44
45 public override void Write( Stream s )
46 {
47 s.WriteByte( (int)'l' );
48 foreach( GatsObject obj in Value )
49 {
50 obj.Write( s );
51 }
52 s.WriteByte( (int)'e' );
53 }
54
55 //
56 // List interface overrides under here.
57 //
58 public int IndexOf( GatsObject obj )
59 {
60 return Value.IndexOf( obj );
61 }
62
63 public void Insert( int idx, GatsObject obj )
64 {
65 Value.Insert( idx, obj );
66 }
67
68 public void RemoveAt( int idx )
69 {
70 Value.RemoveAt( idx );
71 }
72
73 public GatsObject this[int idx] {
74 get { return this.Value[idx]; }
75 set { this.Value[idx] = value; }
76 }
77
78 public int Count {
79 get { return this.Value.Count; }
80 }
81
82 public bool IsReadOnly {
83 get { return false; } // this.Value.IsReadOnly; }
84 }
85
86 public void Add( GatsObject obj )
87 {
88 Value.Add( obj );
89 }
90
91 public void Clear()
92 {
93 Value.Clear();
94 }
95
96 public bool Contains( GatsObject obj )
97 {
98 return Value.Contains( obj );
99 }
100
101 public void CopyTo( GatsObject[] result, int count )
102 {
103 Value.CopyTo( result, count );
104 }
105
106 public bool Remove( GatsObject obj )
107 {
108 return Value.Remove( obj );
109 }
110
111 IEnumerator<GatsObject> IEnumerable<GatsObject>.GetEnumerator()
112 {
113 return Value.GetEnumerator();
114 }
115
116 IEnumerator IEnumerable.GetEnumerator()
117 {
118 return Value.GetEnumerator();
119 }
120
121 public bool IsFixedSize {
122 get { return false; } // this.Value.IsFixedSize; }
123 }
124
125 public bool IsSynchronized {
126 get { return false; } // this.Value.IsSynchronized; }
127 }
128
129 public object SyncRoot {
130 get { return null; } // this.Value.SyncRoot; }
131 }
132
133 }
134}
135
diff --git a/cs-dotnet/src/gatsobject.cs b/cs-dotnet/src/gatsobject.cs
index a48a464..5e76a6c 100644
--- a/cs-dotnet/src/gatsobject.cs
+++ b/cs-dotnet/src/gatsobject.cs
@@ -30,7 +30,7 @@ namespace Com.Xagasoft.Gats
30 break; 30 break;
31 31
32 case 'l': 32 case 'l':
33// goRet = new GatsList(); 33 goRet = new GatsList();
34 break; 34 break;
35 35
36 case 'd': 36 case 'd':
diff --git a/cs-dotnet/src/gatsstring.cs b/cs-dotnet/src/gatsstring.cs
index 30b0afb..47b63ed 100644
--- a/cs-dotnet/src/gatsstring.cs
+++ b/cs-dotnet/src/gatsstring.cs
@@ -15,9 +15,14 @@ namespace Com.Xagasoft.Gats
15 Value = val; 15 Value = val;
16 } 16 }
17 17
18 public GatsString( string val )
19 {
20 Value = System.Text.Encoding.UTF8.GetBytes( val );
21 }
22
18 public override string ToString() 23 public override string ToString()
19 { 24 {
20 return Value.ToString(); 25 return System.Text.Encoding.UTF8.GetString( Value );
21 } 26 }
22 27
23 public override void Read( Stream s, char cType ) 28 public override void Read( Stream s, char cType )
diff --git a/cs-dotnet/src/tests/lists.cs b/cs-dotnet/src/tests/lists.cs
new file mode 100644
index 0000000..8d12bf9
--- /dev/null
+++ b/cs-dotnet/src/tests/lists.cs
@@ -0,0 +1,43 @@
1using System;
2using System.IO;
3using Com.Xagasoft.Gats;
4
5public class Test
6{
7 public static void Write( GatsObject o, Stream s )
8 {
9 o.Write( s );
10 Console.WriteLine("Wrote: " + o );
11 }
12
13 public static void Read( Stream s )
14 {
15 GatsObject o = GatsObject.Read( s );
16 Console.WriteLine("Read type: " + o.GetType() );
17 Console.WriteLine("Read vlaue: " + o );
18 }
19
20 public static void Main()
21 {
22 MemoryStream ms = new MemoryStream();
23 GatsList l = new GatsList();
24 l.Add( new GatsFloat( Math.PI ) );
25 l.Add( new GatsInteger( 1337 ) );
26 l.Add( new GatsString("Hello") );
27 Write( l, ms );
28 ms.Seek( 0, SeekOrigin.Begin );
29 Read( ms );
30/*
31 try
32 {
33 FileStream fs = new FileStream("float.gats", FileMode.Open,
34 FileAccess.Read );
35 Read( fs );
36 }
37 catch( Exception e )
38 {
39 Console.WriteLine("Can't test files: " + e.Message );
40 }
41 */
42 }
43}