2002-05-13 Tim Coleman
[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                         if (size > 0)
41                                 Array.Copy (tables, tmp, size);
42                         size++;
43                         tables = tmp;
44                         tables[size - 1] = table;
45                 }
46
47                 public virtual DataTable Add (string name) {
48                         DataTable table = this.Add ();
49                         table.TableName = name;
50
51                         return table;
52                 }
53
54                 public void AddRange (DataTable[] tables_to_add) {
55                         for (int i = 0; i < tables_to_add.Length; i++) {
56                                 this.Add (tables_to_add[i]);
57                         }
58                 }
59
60                 [MonoTODO]
61                 public bool CanRemove (DataTable table) {
62                         throw new NotImplementedException ();
63                 }
64
65                 public void Clear () {
66                         /* FIXME: is this correct? */
67                         tables = null;
68                         size = 0;
69                 }
70
71                 public bool Contains (string name) {
72                         for (int i = 0; i < size; i++) {
73                                 if (tables[i].TableName == name)
74                                         return true;
75                         }
76
77                         return false;
78                 }
79
80                 public virtual int IndexOf (DataTable table) {
81                         for (int i = 0; i < size; i++) {
82                                 if (tables[i] == table)
83                                         return i;
84                         }
85
86                         return -1;
87                 }
88
89                 public virtual int IndexOf (string name) {
90                         for (int i = 0; i < size; i++) {
91                                 if (tables[i].TableName == name)
92                                         return i;
93                         }
94
95                         return -1;
96                 }
97
98                 public void Remove (DataTable table) {
99                         this.RemoveAt (this.IndexOf (table));
100                 }
101
102                 public void Remove (string name) {
103                         this.RemoveAt (this.IndexOf (name));
104                 }
105
106                 [MonoTODO]
107                 public void RemoveAt (int index) {
108                         throw new NotImplementedException ();
109                 }
110                 
111                 public override int Count {
112                         get { return size; }
113                 }
114
115                 // IsReadOnly and IsSynchronized must be implemented or
116                 // is it safe to use InternalDataCollectionBase's
117
118                 public DataTable this[int index] {
119                         get {
120                                 if (index < size)
121                                         return tables[index];
122                                 return null;
123                         }
124                 }
125
126                 public DataTable this[string name] {
127                         get {
128                                 for (int i = 0; i < size; i++) {
129                                         if (tables[i].TableName == name)
130                                                 return tables[i];
131                                 }
132
133                                 return null;
134                         }
135                 }
136
137                 protected override ArrayList List {
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 }