2002-04-28 Daniel Morgan <danmorg@sc.rr.com>
[mono.git] / mcs / class / System.Data / System.Data / DataTableCollection.cs
1 //
2 // System.Data.DataTableCollection.cs
3 //
4 // Author:
5 //   Christopher Podurgiel (cpodurgiel@msn.com)
6 //
7 // (C) Chris Podurgiel
8 //
9
10 using System;
11 using System.Collections;
12 using System.ComponentModel;
13
14 namespace System.Data
15 {
16         /// <summary>
17         /// Represents the collection of tables for the DataSet.
18         /// </summary>
19         public class DataTableCollection : InternalDataCollectionBase
20         {
21                 private DataTable[] tables = null;
22                 private int size = 0;
23
24                 public virtual DataTable Add () {
25                         DataTable table = new DataTable ();
26                         DataTable[] tmp = new DataTable[size + 1];
27
28                         if (size > 0)
29                                 Array.Copy (tables, tmp, size);
30                         size++;
31                         tables = tmp;
32                         tables[size - 1] = table;
33
34                         return table;
35                 }
36
37                 public virtual void Add (DataTable table) {
38                         DataTable[] tmp = new DataTable[size + 1];
39
40                         Array.Copy (tables, tmp, size);
41                         size++;
42                         tables = tmp;
43                         tables[size - 1] = table;
44                 }
45
46                 public virtual DataTable Add (string name) {
47                         DataTable table = this.Add ();
48                         table.TableName = name;
49
50                         return table;
51                 }
52
53                 public void AddRange (DataTable[] tables_to_add) {
54                         for (int i = 0; i < tables_to_add.Length; i++) {
55                                 this.Add (tables_to_add[i]);
56                         }
57                 }
58
59                 [MonoTODO]
60                 public bool CanRemove (DataTable table) {
61                         throw new NotImplementedException ();
62                 }
63
64                 public void Clear () {
65                         /* FIXME: is this correct? */
66                         tables = null;
67                         size = 0;
68                 }
69
70                 public bool Contains (string name) {
71                         for (int i = 0; i < size; i++) {
72                                 if (tables[i].TableName == name)
73                                         return true;
74                         }
75
76                         return false;
77                 }
78
79                 public virtual int IndexOf (DataTable table) {
80                         for (int i = 0; i < size; i++) {
81                                 if (tables[i] == table)
82                                         return i;
83                         }
84
85                         return -1;
86                 }
87
88                 public virtual int IndexOf (string name) {
89                         for (int i = 0; i < size; i++) {
90                                 if (tables[i].TableName == name)
91                                         return i;
92                         }
93
94                         return -1;
95                 }
96
97                 public void Remove (DataTable table) {
98                         this.RemoveAt (this.IndexOf (table));
99                 }
100
101                 public void Remove (string name) {
102                         this.RemoveAt (this.IndexOf (name));
103                 }
104
105                 [MonoTODO]
106                 public void RemoveAt (int index) {
107                         throw new NotImplementedException ();
108                 }
109                 
110                 public override int Count {
111                         get { return size; }
112                 }
113
114                 // IsReadOnly and IsSynchronized must be implemented or
115                 // is it safe to use InternalDataCollectionBase's
116
117                 public DataTable this[int index] {
118                         get {
119                                 if (index < size)
120                                         return tables[index];
121                                 return null;
122                         }
123                 }
124
125                 public DataTable this[string name] {
126                         get {
127                                 for (int i = 0; i < size; i++) {
128                                         if (tables[i].TableName == name)
129                                                 return tables[i];
130                                 }
131
132                                 return null;
133                         }
134                 }
135 \r
136                 protected override ArrayList List {
137                         [MonoTODO]
138                         get{
139                                 throw new NotImplementedException ();
140                         }
141                 }
142                 
143                 public event CollectionChangeEventHandler CollectionChanged;
144
145                 public event CollectionChangeEventHandler CollectionChanging;
146
147                 protected virtual void OnCollectionChanged (
148                         CollectionChangeEventArgs ccevent) {
149
150                         throw new NotImplementedException ();
151                 }
152
153                 protected internal virtual void OnCollectionChanging (
154                         CollectionChangeEventArgs ccevent) {
155
156                         throw new NotImplementedException ();
157                 }
158         }
159 }