(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Mono.Data.SybaseClient / Mono.Data.SybaseTypes / SybaseBoolean.cs
blob0a7c5e267f1c45bea2435a8eea3f1e7303aba22a
1 //
2 // Mono.Data.SybaseTypes.SybaseBoolean
3 //
4 // Author:
5 // Tim Coleman (tim@timcoleman.com)
6 //
7 // Based on System.Data.SqlTypes.SqlBoolean
8 //
9 // (C) Ximian, Inc. 2002-2003
10 // (C) Copyright Tim Coleman, 2002-2003
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 //
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 //
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using Mono.Data.SybaseClient;
35 using System;
36 using System.Data.SqlTypes;
37 using System.Globalization;
39 namespace Mono.Data.SybaseTypes {
40 public struct SybaseBoolean : INullable, IComparable
42 #region Fields
44 byte value;
46 // default is false
47 private bool notNull;
49 public static readonly SybaseBoolean False = new SybaseBoolean (false);
50 public static readonly SybaseBoolean Null;
51 public static readonly SybaseBoolean One = new SybaseBoolean (1);
52 public static readonly SybaseBoolean True = new SybaseBoolean (true);
53 public static readonly SybaseBoolean Zero = new SybaseBoolean (0);
55 #endregion // Fields
57 #region Constructors
59 public SybaseBoolean (bool value)
61 this.value = (byte) (value ? 1 : 0);
62 notNull = true;
65 public SybaseBoolean (int value)
67 this.value = (byte) (value != 0 ? 1 : 0);
68 notNull = true;
71 #endregion // Constructors
73 #region Properties
75 public byte ByteValue {
76 get {
77 if (this.IsNull)
78 throw new SybaseNullValueException(Locale.GetText("The property is set to null."));
79 else
80 return value;
84 public bool IsFalse {
85 get {
86 if (this.IsNull)
87 return false;
88 else
89 return (value == 0);
93 public bool IsNull {
94 get {
95 return !notNull;
99 public bool IsTrue {
100 get {
101 if (this.IsNull)
102 return false;
103 else
104 return (value != 0);
108 public bool Value {
109 get {
110 if (this.IsNull)
111 throw new SybaseNullValueException(Locale.GetText("The property is set to null."));
112 else
113 return this.IsTrue;
117 #endregion // Properties
119 public static SybaseBoolean And (SybaseBoolean x, SybaseBoolean y)
121 return (x & y);
124 public int CompareTo (object value)
126 if (value == null)
127 return 1;
128 else if (!(value is SybaseBoolean))
129 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SybaseTypes.SybaseBoolean"));
130 else if (((SybaseBoolean)value).IsNull)
131 return 1;
132 else
133 return this.value.CompareTo (((SybaseBoolean)value).ByteValue);
136 public override bool Equals(object value)
138 if (!(value is SybaseByte))
139 return false;
140 else
141 return (bool) (this == (SybaseBoolean)value);
144 public static SybaseBoolean Equals(SybaseBoolean x, SybaseBoolean y)
146 return (x == y);
149 public override int GetHashCode()
151 return (int)value;
154 public static SybaseBoolean NotEquals(SybaseBoolean x, SybaseBoolean y)
156 return (x != y);
159 public static SybaseBoolean OnesComplement(SybaseBoolean x)
161 return ~x;
164 public static SybaseBoolean Or(SybaseBoolean x, SybaseBoolean y)
166 return (x | y);
169 public static SybaseBoolean Parse(string s)
171 return new SybaseBoolean (Boolean.Parse (s));
174 public SybaseByte ToSybaseByte()
176 return new SybaseByte (value);
179 // **************************************************
180 // Conversion from SybaseBoolean to other SybaseTypes
181 // **************************************************
183 public SybaseDecimal ToSybaseDecimal()
185 return ((SybaseDecimal)this);
188 public SybaseDouble ToSybaseDouble()
190 return ((SybaseDouble)this);
193 public SybaseInt16 ToSybaseInt16()
195 return ((SybaseInt16)this);
198 public SybaseInt32 ToSybaseInt32()
200 return ((SybaseInt32)this);
203 public SybaseInt64 ToSybaseInt64()
205 return ((SybaseInt64)this);
208 public SybaseMoney ToSybaseMoney()
210 return ((SybaseMoney)this);
213 public SybaseSingle ToSybaseSingle()
215 return ((SybaseSingle)this);
218 public SybaseString ToSybaseString()
220 if (this.IsNull)
221 return new SybaseString ("Null");
222 if (this.IsTrue)
223 return new SybaseString ("True");
224 else
225 return new SybaseString ("False");
228 public override string ToString()
230 if (this.IsNull)
231 return "Null";
232 if (this.IsTrue)
233 return "True";
234 else
235 return "False";
238 // Bitwise exclusive-OR (XOR)
239 public static SybaseBoolean Xor(SybaseBoolean x, SybaseBoolean y)
241 return (x ^ y);
244 // **************************************************
245 // Public Operators
246 // **************************************************
248 // Bitwise AND
249 public static SybaseBoolean operator & (SybaseBoolean x, SybaseBoolean y)
251 return new SybaseBoolean (x.Value & y.Value);
254 // Bitwise OR
255 public static SybaseBoolean operator | (SybaseBoolean x, SybaseBoolean y)
257 return new SybaseBoolean (x.Value | y.Value);
261 // Compares two instances for equality
262 public static SybaseBoolean operator == (SybaseBoolean x, SybaseBoolean y)
264 if (x.IsNull || y.IsNull)
265 return SybaseBoolean.Null;
266 else
267 return new SybaseBoolean (x.Value == y.Value);
270 // Bitwize exclusive-OR (XOR)
271 public static SybaseBoolean operator ^ (SybaseBoolean x, SybaseBoolean y)
273 return new SybaseBoolean (x.Value ^ y.Value);
276 // test Value of SybaseBoolean to determine it is false.
277 public static bool operator false (SybaseBoolean x)
279 return x.IsFalse;
282 // in-equality
283 public static SybaseBoolean operator != (SybaseBoolean x, SybaseBoolean y)
285 if (x.IsNull || y.IsNull)
286 return SybaseBoolean.Null;
287 else
288 return new SybaseBoolean (x.Value != y.Value);
291 // Logical NOT
292 public static SybaseBoolean operator ! (SybaseBoolean x)
294 if (x.IsNull)
295 return SybaseBoolean.Null;
296 else
297 return new SybaseBoolean (!x.Value);
300 // One's Complement
301 public static SybaseBoolean operator ~ (SybaseBoolean x)
303 return new SybaseBoolean (~x.ByteValue);
306 // test to see if value is true
307 public static bool operator true (SybaseBoolean x)
309 return x.IsTrue;
312 // ****************************************
313 // Type Conversion
314 // ****************************************
317 // SybaseBoolean to Boolean
318 public static explicit operator bool (SybaseBoolean x)
320 return x.Value;
324 // SybaseByte to SybaseBoolean
325 public static explicit operator SybaseBoolean (SybaseByte x)
327 if (x.IsNull)
328 return Null;
329 else
330 return new SybaseBoolean ((int)x.Value);
333 // SybaseDecimal to SybaseBoolean
334 public static explicit operator SybaseBoolean (SybaseDecimal x)
336 if (x.IsNull)
337 return Null;
338 else
339 return new SybaseBoolean ((int)x.Value);
342 // SybaseDouble to SybaseBoolean
343 public static explicit operator SybaseBoolean (SybaseDouble x)
345 if (x.IsNull)
346 return Null;
347 else
348 return new SybaseBoolean ((int)x.Value);
351 // SybaseInt16 to SybaseBoolean
352 public static explicit operator SybaseBoolean (SybaseInt16 x)
354 if (x.IsNull)
355 return Null;
356 else
357 return new SybaseBoolean ((int)x.Value);
360 // SybaseInt32 to SybaseBoolean
361 public static explicit operator SybaseBoolean (SybaseInt32 x)
363 if (x.IsNull)
364 return Null;
365 else
366 return new SybaseBoolean (x.Value);
369 // SybaseInt64 to SybaseBoolean
370 public static explicit operator SybaseBoolean (SybaseInt64 x)
372 if (x.IsNull)
373 return Null;
374 else
375 return new SybaseBoolean ((int)x.Value);
378 // SybaseMoney to SybaseBoolean
379 public static explicit operator SybaseBoolean (SybaseMoney x)
381 if (x.IsNull)
382 return Null;
383 else
384 return new SybaseBoolean ((int)x.Value);
387 // SybaseSingle to SybaseBoolean
388 public static explicit operator SybaseBoolean (SybaseSingle x)
390 if (x.IsNull)
391 return Null;
392 else
393 return new SybaseBoolean ((int)x.Value);
396 // SybaseString to SybaseBoolean
397 public static explicit operator SybaseBoolean (SybaseString x)
399 return SybaseBoolean.Parse (x.Value);
402 // Boolean to SybaseBoolean
403 public static implicit operator SybaseBoolean (bool x)
405 return new SybaseBoolean (x);