* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Data.OracleClient / System.Data.OracleClient / OracleBoolean.cs
1 //
2 // OracleBoolean.cs 
3 //
4 // Part of the Mono class libraries at
5 // mcs/class/System.Data.OracleClient/System.Data.OracleClient
6 //
7 // Assembly: System.Data.OracleClient.dll
8 // Namespace: System.Data.OracleClient
9 //
10 // Author: Tim Coleman <tim@timcoleman.com>
11 //
12 // Copyright (C) Tim Coleman, 2003
13 //
14 // Licensed under the MIT/X11 License.
15 //
16
17 using System;
18 using System.Data.SqlTypes;
19
20 namespace System.Data.OracleClient {
21         public struct OracleBoolean : IComparable
22         {
23                 #region Fields
24
25                 public static readonly OracleBoolean False = new OracleBoolean (false);
26                 public static readonly OracleBoolean Null = new OracleBoolean ();
27                 public static readonly OracleBoolean One = new OracleBoolean (1);
28                 public static readonly OracleBoolean True = new OracleBoolean (true);
29                 public static readonly OracleBoolean Zero = new OracleBoolean (0);
30
31                 bool value;
32                 bool notNull;
33
34                 #endregion // Fields
35
36                 #region Constructors
37
38                 public OracleBoolean (bool value)
39                 {
40                         this.value = value;
41                         notNull = true;
42                 }
43
44                 public OracleBoolean (int value)
45                         : this (value != 0)
46                 {
47                 }
48
49                 #endregion // Constructors
50
51                 #region Properties
52
53                 public bool IsFalse {
54                         get { return (!IsNull && !value); }
55                 }
56
57                 public bool IsNull {
58                         get { return !notNull; }
59                 }
60
61                 public bool IsTrue {
62                         get { return (!IsNull && value); }
63                 }
64
65                 public bool Value {
66                         get { return IsTrue; }
67                 }
68
69                 #endregion // Properties
70
71                 #region Methods
72
73                 public static OracleBoolean And (OracleBoolean x, OracleBoolean y)
74                 {
75                         if (x.IsNull || y.IsNull) 
76                                 return OracleBoolean.Null;
77                         return new OracleBoolean (x.Value && y.Value);
78                 }
79
80                 [MonoTODO]
81                 public int CompareTo (object obj)
82                 {
83                         throw new NotImplementedException ();
84                 }
85
86                 [MonoTODO]
87                 public override bool Equals (object value)
88                 {
89                         throw new NotImplementedException ();
90                 }
91
92                 public static OracleBoolean Equals (OracleBoolean x, OracleBoolean y)
93                 {
94                         if (x.IsNull || y.IsNull)
95                                 return OracleBoolean.Null;
96                         return new OracleBoolean (x.Value == y.Value);
97                 }
98
99                 [MonoTODO]
100                 public override int GetHashCode ()
101                 {
102                         throw new NotImplementedException ();
103                 }
104
105                 public static OracleBoolean NotEquals (OracleBoolean x, OracleBoolean y)
106                 {
107                         if (x.IsNull || y.IsNull)
108                                 return OracleBoolean.Null;
109                         return new OracleBoolean (x.Value != y.Value);
110                 }
111
112                 public static OracleBoolean OnesComplement (OracleBoolean x)
113                 {
114                         if (x.IsNull)
115                                 return OracleBoolean.Null;
116                         return new OracleBoolean (!x.Value);
117                 }
118
119                 public static OracleBoolean Or (OracleBoolean x, OracleBoolean y)
120                 {
121                         if (x.IsNull || y.IsNull)
122                                 return OracleBoolean.Null;
123                         return new OracleBoolean (x.Value || y.Value);
124                 }
125
126                 [MonoTODO]
127                 public static OracleBoolean Parse (string s)
128                 {
129                         throw new NotImplementedException ();
130                 }
131
132                 public override string ToString ()
133                 {
134                         if (IsNull)
135                                 return "Null";
136
137                         if (IsTrue)
138                                 return "True";
139
140                         return "False";
141                 }
142
143                 public static OracleBoolean Xor (OracleBoolean x, OracleBoolean y)
144                 {
145                         if (x.IsNull || y.IsNull)
146                                 return OracleBoolean.Null;
147                         return new OracleBoolean (x.Value ^ y.Value);
148                 }
149
150                 #endregion // Methods
151
152                 #region Operators and Type Conversions
153
154                 public static OracleBoolean operator & (OracleBoolean x, OracleBoolean y)
155                 {
156                         return And (x, y);
157                 }
158
159                 public static OracleBoolean operator | (OracleBoolean x, OracleBoolean y)
160                 {
161                         return Or (x, y);
162                 }
163
164                 public static OracleBoolean operator == (OracleBoolean x, OracleBoolean y)
165                 {
166                         return Equals (x, y);
167                 }
168
169                 public static OracleBoolean operator ^ (OracleBoolean x, OracleBoolean y)
170                 {
171                         return Xor (x, y);
172                 }
173
174                 public static bool operator false (OracleBoolean x)
175                 {
176                         return x.IsFalse; 
177                 }
178
179                 public static OracleBoolean operator != (OracleBoolean x, OracleBoolean y)
180                 {
181                         return NotEquals (x, y);
182                 }
183
184                 public static OracleBoolean operator ! (OracleBoolean x)
185                 {
186                         return OnesComplement (x);
187                 }
188
189                 public static OracleBoolean operator ~ (OracleBoolean x)
190                 {
191                         return OnesComplement (x);
192                 }
193
194                 public static bool operator true (OracleBoolean x)
195                 {
196                         return x.IsTrue;
197                 }
198
199                 public static explicit operator bool (OracleBoolean x)
200                 {
201                         if (x.IsNull)
202                                 throw new NullReferenceException ();
203                         return x.Value;
204                 }
205                         
206                 public static explicit operator OracleBoolean (OracleNumber x)
207                 {
208                         return new OracleBoolean ((int) x);
209                 }
210
211                 public static explicit operator OracleBoolean (string x)
212                 {
213                         return OracleBoolean.Parse (x);
214                 }
215
216                 public static implicit operator OracleBoolean (bool x)
217                 {
218                         return new OracleBoolean (x);
219                 }
220
221                 #endregion // Operators and Type Conversions
222         }
223 }