* DataTable.cs: Add rows to the row list if there is
[mono.git] / mcs / class / System.Data / System.Data / Node.cs
1 using System;
2
3 namespace System.Data
4 {
5         /// <summary>
6         /// Summary description for Node.
7         /// </summary>
8         public class Node
9         {
10                 protected int _iBalance;    // currently, -2 means 'deleted'
11                 internal Node _nNext;       // node of next index (nNext==null || nNext.iId=iId+1)
12                 protected Node _nLeft;
13                 protected Node _nRight;
14                 protected Node _nParent;
15
16                 protected DataRow _row;
17                 
18                 public Node(DataRow row)
19                 {
20                         _row = row;
21                 }
22
23                 internal int GetBalance()
24                 {
25                         if (_iBalance == -2)
26                                 throw new Exception ("Node is deleted.");
27
28                         return _iBalance;
29                 }
30
31                 internal void Delete()
32                 {
33                         _iBalance = -2;
34                         _nLeft = null;
35                         _nRight = null;
36                         _nParent = null;
37                 }
38
39
40                 internal DataRow Row
41                 {
42                         get {
43                                 return _row;
44                         }
45                 }
46
47                 internal Node Left
48                 {
49                         get {
50                                 if (_iBalance == -2)
51                                         throw new Exception ("Node is deleted.");
52
53                                 return _nLeft;
54                         }
55
56                         set {
57                                 if (_iBalance == -2)
58                                         throw new Exception ("Node is deleted.");
59
60                                 _nLeft = value;
61                         }
62                 }
63
64                 internal Node Right
65                 {
66                         get {
67                                 if (_iBalance == -2)
68                                         throw new Exception ("Node is deleted.");
69                                 return _nRight;
70                         }
71
72                         set {
73                                 if (_iBalance == -2)
74                                         throw new Exception ("Node is deleted.");
75
76                                 _nRight = value;
77                         }
78                 }
79
80
81                 internal Node Parent
82                 {
83                         get {
84                                 if (_iBalance == -2)
85                                         throw new Exception ("Node is deleted.");
86
87                                 return _nParent;
88                         }
89
90                         set {
91                                 if (_iBalance == -2)
92                                         throw new Exception ("Node is deleted.");
93                                 _nParent = value;
94                         }
95                 }
96
97                 internal bool IsRoot()
98                 {
99                         return _nParent == null;
100                 }
101
102
103                 internal void SetBalance(int b)
104                 {
105
106                         if (_iBalance == -2)
107                                 throw new Exception ("Node is deleted.");
108
109                         _iBalance = b;
110                 }
111
112                 internal bool From()
113                 {
114
115                         if (this.IsRoot()){
116                                 return true;
117                         }
118
119                         if (_iBalance == -2)
120                                 throw new Exception ("Node is deleted.");
121                         Node parent = Parent;
122
123                         return Equals(parent.Left);
124                 }
125
126                 internal Object[] GetData()
127                 {
128
129                         if (_iBalance == -2)
130                                 throw new Exception ("Node is deleted.");
131                         return _row.ItemArray;
132                 }
133
134                 internal bool Equals(Node n)
135                 {
136
137                         if (_iBalance == -2)
138                                 throw new Exception ("Node is deleted.");
139
140                         return n == this;
141                 }
142         }
143 }