**** Merged from MCS ****
[mono-project.git] / mcs / class / Mono.Data.SybaseClient / Mono.Data.SybaseTypes / SybaseInt64.cs
blob82e4e87f7c573a84d9bab09f8cccd498833c39d4
1 //
2 // Mono.Data.SybaseTypes.SybaseInt64
3 //
4 // Author:
5 // Tim Coleman <tim@timcoleman.com>
6 //
7 // (C) Copyright Tim Coleman, 2002
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using Mono.Data.SybaseClient;
32 using System;
33 using System.Data.SqlTypes;
34 using System.Globalization;
36 namespace Mono.Data.SybaseTypes {
37 public struct SybaseInt64 : INullable, IComparable
39 #region Fields
41 long value;
43 private bool notNull;
45 public static readonly SybaseInt64 MaxValue = new SybaseInt64 (9223372036854775807);
46 public static readonly SybaseInt64 MinValue = new SybaseInt64 (-9223372036854775808);
48 public static readonly SybaseInt64 Null;
49 public static readonly SybaseInt64 Zero = new SybaseInt64 (0);
51 #endregion
53 #region Constructors
55 public SybaseInt64 (long value)
57 this.value = value;
58 notNull = true;
61 #endregion
63 #region Properties
65 public bool IsNull {
66 get { return !notNull; }
69 public long Value {
70 get {
71 if (this.IsNull)
72 throw new SybaseNullValueException ();
73 else
74 return value;
78 #endregion
80 #region Methods
82 public static SybaseInt64 Add (SybaseInt64 x, SybaseInt64 y)
84 return (x + y);
87 public static SybaseInt64 BitwiseAnd (SybaseInt64 x, SybaseInt64 y)
89 return (x & y);
92 public static SybaseInt64 BitwiseOr (SybaseInt64 x, SybaseInt64 y)
94 return (x | y);
97 public int CompareTo (object value)
99 if (value == null)
100 return 1;
101 else if (!(value is SybaseInt64))
102 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SybaseTypes.SybaseInt64"));
103 else if (((SybaseInt64)value).IsNull)
104 return 1;
105 else
106 return this.value.CompareTo (((SybaseInt64)value).Value);
109 public static SybaseInt64 Divide (SybaseInt64 x, SybaseInt64 y)
111 return (x / y);
114 public override bool Equals (object value)
116 if (!(value is SybaseInt64))
117 return false;
118 else
119 return (bool) (this == (SybaseInt64)value);
122 public static SybaseBoolean Equals (SybaseInt64 x, SybaseInt64 y)
124 return (x == y);
127 public override int GetHashCode ()
129 return (int)(value & 0xffffffff) ^ (int)(value >> 32);
132 public static SybaseBoolean GreaterThan (SybaseInt64 x, SybaseInt64 y)
134 return (x > y);
137 public static SybaseBoolean GreaterThanOrEqual (SybaseInt64 x, SybaseInt64 y)
139 return (x >= y);
142 public static SybaseBoolean LessThan (SybaseInt64 x, SybaseInt64 y)
144 return (x < y);
147 public static SybaseBoolean LessThanOrEqual (SybaseInt64 x, SybaseInt64 y)
149 return (x <= y);
152 public static SybaseInt64 Mod (SybaseInt64 x, SybaseInt64 y)
154 return (x % y);
157 public static SybaseInt64 Multiply (SybaseInt64 x, SybaseInt64 y)
159 return (x * y);
162 public static SybaseBoolean NotEquals (SybaseInt64 x, SybaseInt64 y)
164 return (x != y);
167 public static SybaseInt64 OnesComplement (SybaseInt64 x)
169 return ~x;
173 public static SybaseInt64 Parse (string s)
175 return new SybaseInt64 (Int64.Parse (s));
178 public static SybaseInt64 Subtract (SybaseInt64 x, SybaseInt64 y)
180 return (x - y);
183 public SybaseBoolean ToSybaseBoolean ()
185 return ((SybaseBoolean)this);
188 public SybaseByte ToSybaseByte ()
190 return ((SybaseByte)this);
193 public SybaseDecimal ToSybaseDecimal ()
195 return ((SybaseDecimal)this);
198 public SybaseDouble ToSybaseDouble ()
200 return ((SybaseDouble)this);
203 public SybaseInt16 ToSybaseInt16 ()
205 return ((SybaseInt16)this);
208 public SybaseInt32 ToSybaseInt32 ()
210 return ((SybaseInt32)this);
213 public SybaseMoney ToSybaseMoney ()
215 return ((SybaseMoney)this);
218 public SybaseSingle ToSybaseSingle ()
220 return ((SybaseSingle)this);
223 public SybaseString ToSybaseString ()
225 return ((SybaseString)this);
228 public override string ToString ()
230 if (this.IsNull)
231 return "Null";
233 return value.ToString ();
236 public static SybaseInt64 Xor (SybaseInt64 x, SybaseInt64 y)
238 return (x ^ y);
241 public static SybaseInt64 operator + (SybaseInt64 x, SybaseInt64 y)
243 return new SybaseInt64 (x.Value + y.Value);
246 public static SybaseInt64 operator & (SybaseInt64 x, SybaseInt64 y)
248 return new SybaseInt64 (x.value & y.Value);
251 public static SybaseInt64 operator | (SybaseInt64 x, SybaseInt64 y)
253 return new SybaseInt64 (x.value | y.Value);
256 public static SybaseInt64 operator / (SybaseInt64 x, SybaseInt64 y)
258 return new SybaseInt64 (x.Value / y.Value);
261 public static SybaseBoolean operator == (SybaseInt64 x, SybaseInt64 y)
263 if (x.IsNull || y.IsNull)
264 return SybaseBoolean.Null;
265 else
266 return new SybaseBoolean (x.Value == y.Value);
269 public static SybaseInt64 operator ^ (SybaseInt64 x, SybaseInt64 y)
271 return new SybaseInt64 (x.Value ^ y.Value);
274 public static SybaseBoolean operator > (SybaseInt64 x, SybaseInt64 y)
276 if (x.IsNull || y.IsNull)
277 return SybaseBoolean.Null;
278 else
279 return new SybaseBoolean (x.Value > y.Value);
282 public static SybaseBoolean operator >= (SybaseInt64 x, SybaseInt64 y)
284 if (x.IsNull || y.IsNull)
285 return SybaseBoolean.Null;
286 else
287 return new SybaseBoolean (x.Value >= y.Value);
290 public static SybaseBoolean operator != (SybaseInt64 x, SybaseInt64 y)
292 if (x.IsNull || y.IsNull)
293 return SybaseBoolean.Null;
294 else
295 return new SybaseBoolean (!(x.Value == y.Value));
298 public static SybaseBoolean operator < (SybaseInt64 x, SybaseInt64 y)
300 if (x.IsNull || y.IsNull)
301 return SybaseBoolean.Null;
302 else
303 return new SybaseBoolean (x.Value < y.Value);
306 public static SybaseBoolean operator <= (SybaseInt64 x, SybaseInt64 y)
308 if (x.IsNull || y.IsNull)
309 return SybaseBoolean.Null;
310 else
311 return new SybaseBoolean (x.Value <= y.Value);
314 public static SybaseInt64 operator % (SybaseInt64 x, SybaseInt64 y)
316 return new SybaseInt64(x.Value % y.Value);
319 public static SybaseInt64 operator * (SybaseInt64 x, SybaseInt64 y)
321 return new SybaseInt64 (x.Value * y.Value);
324 public static SybaseInt64 operator ~ (SybaseInt64 x)
326 return new SybaseInt64 (~(x.Value));
329 public static SybaseInt64 operator - (SybaseInt64 x, SybaseInt64 y)
331 return new SybaseInt64 (x.Value - y.Value);
334 public static SybaseInt64 operator - (SybaseInt64 n)
336 return new SybaseInt64 (-(n.Value));
339 public static explicit operator SybaseInt64 (SybaseBoolean x)
341 if (x.IsNull)
342 return SybaseInt64.Null;
343 else
344 return new SybaseInt64 ((long)x.ByteValue);
347 public static explicit operator SybaseInt64 (SybaseDecimal x)
349 if (x.IsNull)
350 return SybaseInt64.Null;
351 else
352 return new SybaseInt64 ((long)x.Value);
355 public static explicit operator SybaseInt64 (SybaseDouble x)
357 if (x.IsNull)
358 return SybaseInt64.Null;
359 else
360 return new SybaseInt64 ((long)x.Value);
363 public static explicit operator long (SybaseInt64 x)
365 return x.Value;
368 public static explicit operator SybaseInt64 (SybaseMoney x)
370 if (x.IsNull)
371 return SybaseInt64.Null;
372 else
373 return new SybaseInt64 ((long)x.Value);
376 public static explicit operator SybaseInt64 (SybaseSingle x)
378 if (x.IsNull)
379 return SybaseInt64.Null;
380 else
381 return new SybaseInt64 ((long)x.Value);
384 public static explicit operator SybaseInt64 (SybaseString x)
386 return SybaseInt64.Parse (x.Value);
389 public static implicit operator SybaseInt64 (long x)
391 return new SybaseInt64 (x);
394 public static implicit operator SybaseInt64 (SybaseByte x)
396 if (x.IsNull)
397 return SybaseInt64.Null;
398 else
399 return new SybaseInt64 ((long)x.Value);
402 public static implicit operator SybaseInt64 (SybaseInt16 x)
404 if (x.IsNull)
405 return SybaseInt64.Null;
406 else
407 return new SybaseInt64 ((long)x.Value);
410 public static implicit operator SybaseInt64 (SybaseInt32 x)
412 if (x.IsNull)
413 return SybaseInt64.Null;
414 else
415 return new SybaseInt64 ((long)x.Value);
418 #endregion