**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Data / System.Data / Node.cs
blobd99bc65f285a1c9d6ae1b46a7ac3ba32499893dd
2 //
3 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 using System;
26 namespace System.Data
28 /// <summary>
29 /// Summary description for Node.
30 /// </summary>
31 internal class Node
33 protected int _iBalance; // currently, -2 means 'deleted'
34 internal Node _nNext; // node of next index (nNext==null || nNext.iId=iId+1)
35 protected Node _nLeft;
36 protected Node _nRight;
37 protected Node _nParent;
39 protected DataRow _row;
41 public Node(DataRow row)
43 _row = row;
46 internal int GetBalance()
48 if (_iBalance == -2)
49 throw new Exception ("Node is deleted.");
51 return _iBalance;
54 internal void Delete()
56 _iBalance = -2;
57 _nLeft = null;
58 _nRight = null;
59 _nParent = null;
63 internal DataRow Row
65 get {
66 return _row;
70 internal Node Left
72 get {
73 if (_iBalance == -2)
74 throw new Exception ("Node is deleted.");
76 return _nLeft;
79 set {
80 if (_iBalance == -2)
81 throw new Exception ("Node is deleted.");
83 _nLeft = value;
87 internal Node Right
89 get {
90 if (_iBalance == -2)
91 throw new Exception ("Node is deleted.");
92 return _nRight;
95 set {
96 if (_iBalance == -2)
97 throw new Exception ("Node is deleted.");
99 _nRight = value;
104 internal Node Parent
106 get {
107 if (_iBalance == -2)
108 throw new Exception ("Node is deleted.");
110 return _nParent;
113 set {
114 if (_iBalance == -2)
115 throw new Exception ("Node is deleted.");
116 _nParent = value;
120 internal bool IsRoot()
122 return _nParent == null;
126 internal void SetBalance(int b)
129 if (_iBalance == -2)
130 throw new Exception ("Node is deleted.");
132 _iBalance = b;
135 internal bool From()
138 if (this.IsRoot()){
139 return true;
142 if (_iBalance == -2)
143 throw new Exception ("Node is deleted.");
144 Node parent = Parent;
146 return Equals(parent.Left);
149 internal Object[] GetData()
152 if (_iBalance == -2)
153 throw new Exception ("Node is deleted.");
154 return _row.ItemArray;
157 internal bool Equals(Node n)
160 if (_iBalance == -2)
161 throw new Exception ("Node is deleted.");
163 return n == this;