(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Mono.Data.SybaseClient / Mono.Data.SybaseTypes / SybaseInt32.cs
blobcf181bfcc9cc9733cab1255e7cf47c587cd3f293
1 //
2 // Mono.Data.SybaseTypes.SybaseInt32
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 SybaseInt32 : INullable, IComparable
39 #region Fields
41 int value;
42 private bool notNull;
44 public static readonly SybaseInt32 MaxValue = new SybaseInt32 (2147483647);
45 public static readonly SybaseInt32 MinValue = new SybaseInt32 (-2147483648);
46 public static readonly SybaseInt32 Null;
47 public static readonly SybaseInt32 Zero = new SybaseInt32 (0);
49 #endregion
51 #region Constructors
53 public SybaseInt32(int value)
55 this.value = value;
56 notNull = true;
59 #endregion
61 #region Properties
63 public bool IsNull {
64 get { return !notNull; }
67 public int Value {
68 get {
69 if (this.IsNull)
70 throw new SybaseNullValueException ();
71 else
72 return value;
76 #endregion
78 #region Methods
80 public static SybaseInt32 Add (SybaseInt32 x, SybaseInt32 y)
82 return (x + y);
85 public static SybaseInt32 BitwiseAnd(SybaseInt32 x, SybaseInt32 y)
87 return (x & y);
90 public static SybaseInt32 BitwiseOr(SybaseInt32 x, SybaseInt32 y)
92 return (x | y);
95 public int CompareTo(object value)
97 if (value == null)
98 return 1;
99 else if (!(value is SybaseInt32))
100 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SybaseTypes.SybaseInt32"));
101 else if (((SybaseInt32)value).IsNull)
102 return 1;
103 else
104 return this.value.CompareTo (((SybaseInt32)value).Value);
107 public static SybaseInt32 Divide(SybaseInt32 x, SybaseInt32 y)
109 return (x / y);
112 public override bool Equals(object value)
114 if (!(value is SybaseInt32))
115 return false;
116 else
117 return (bool) (this == (SybaseInt32)value);
120 public static SybaseBoolean Equals(SybaseInt32 x, SybaseInt32 y)
122 return (x == y);
125 public override int GetHashCode()
127 return value;
130 public static SybaseBoolean GreaterThan (SybaseInt32 x, SybaseInt32 y)
132 return (x > y);
135 public static SybaseBoolean GreaterThanOrEqual (SybaseInt32 x, SybaseInt32 y)
137 return (x >= y);
140 public static SybaseBoolean LessThan(SybaseInt32 x, SybaseInt32 y)
142 return (x < y);
145 public static SybaseBoolean LessThanOrEqual(SybaseInt32 x, SybaseInt32 y)
147 return (x <= y);
150 public static SybaseInt32 Mod(SybaseInt32 x, SybaseInt32 y)
152 return (x % y);
155 public static SybaseInt32 Multiply(SybaseInt32 x, SybaseInt32 y)
157 return (x * y);
160 public static SybaseBoolean NotEquals(SybaseInt32 x, SybaseInt32 y)
162 return (x != y);
165 public static SybaseInt32 OnesComplement(SybaseInt32 x)
167 return ~x;
170 public static SybaseInt32 Parse(string s)
172 return new SybaseInt32 (Int32.Parse (s));
175 public static SybaseInt32 Subtract(SybaseInt32 x, SybaseInt32 y)
177 return (x - y);
180 public SybaseBoolean ToSybaseBoolean()
182 return ((SybaseBoolean)this);
185 public SybaseByte ToSybaseByte()
187 return ((SybaseByte)this);
190 public SybaseDecimal ToSybaseDecimal()
192 return ((SybaseDecimal)this);
195 public SybaseDouble ToSybaseDouble()
197 return ((SybaseDouble)this);
200 public SybaseInt16 ToSybaseInt16()
202 return ((SybaseInt16)this);
205 public SybaseInt64 ToSybaseInt64()
207 return ((SybaseInt64)this);
210 public SybaseMoney ToSybaseMoney()
212 return ((SybaseMoney)this);
215 public SybaseSingle ToSybaseSingle()
217 return ((SybaseSingle)this);
220 public SybaseString ToSybaseString ()
222 return ((SybaseString)this);
225 public override string ToString()
227 if (this.IsNull)
228 return "Null";
229 else
230 return value.ToString ();
233 public static SybaseInt32 Xor(SybaseInt32 x, SybaseInt32 y)
235 return (x ^ y);
238 #endregion
240 #region Operators
242 // Compute Addition
243 public static SybaseInt32 operator + (SybaseInt32 x, SybaseInt32 y)
245 return new SybaseInt32 (x.Value + y.Value);
248 // Bitwise AND
249 public static SybaseInt32 operator & (SybaseInt32 x, SybaseInt32 y)
251 return new SybaseInt32 (x.Value & y.Value);
254 // Bitwise OR
255 public static SybaseInt32 operator | (SybaseInt32 x, SybaseInt32 y)
257 return new SybaseInt32 (x.Value | y.Value);
260 // Compute Division
261 public static SybaseInt32 operator / (SybaseInt32 x, SybaseInt32 y)
263 return new SybaseInt32 (x.Value / y.Value);
266 // Compare Equality
267 public static SybaseBoolean operator == (SybaseInt32 x, SybaseInt32 y)
269 if (x.IsNull || y.IsNull)
270 return SybaseBoolean.Null;
271 else
272 return new SybaseBoolean (x.Value == y.Value);
275 // Bitwise Exclusive-OR (XOR)
276 public static SybaseInt32 operator ^ (SybaseInt32 x, SybaseInt32 y)
278 return new SybaseInt32 (x.Value ^ y.Value);
281 // > Compare
282 public static SybaseBoolean operator >(SybaseInt32 x, SybaseInt32 y)
284 if (x.IsNull || y.IsNull)
285 return SybaseBoolean.Null;
286 else
287 return new SybaseBoolean (x.Value > y.Value);
290 // >= Compare
291 public static SybaseBoolean operator >= (SybaseInt32 x, SybaseInt32 y)
293 if (x.IsNull || y.IsNull)
294 return SybaseBoolean.Null;
295 else
296 return new SybaseBoolean (x.Value >= y.Value);
299 // != Inequality Compare
300 public static SybaseBoolean operator != (SybaseInt32 x, SybaseInt32 y)
302 if (x.IsNull || y.IsNull)
303 return SybaseBoolean.Null;
304 else
305 return new SybaseBoolean (x.Value != y.Value);
308 // < Compare
309 public static SybaseBoolean operator < (SybaseInt32 x, SybaseInt32 y)
311 if (x.IsNull || y.IsNull)
312 return SybaseBoolean.Null;
313 else
314 return new SybaseBoolean (x.Value < y.Value);
317 // <= Compare
318 public static SybaseBoolean operator <= (SybaseInt32 x, SybaseInt32 y)
320 if (x.IsNull || y.IsNull)
321 return SybaseBoolean.Null;
322 else
323 return new SybaseBoolean (x.Value <= y.Value);
326 // Compute Modulus
327 public static SybaseInt32 operator % (SybaseInt32 x, SybaseInt32 y)
329 return new SybaseInt32 (x.Value % y.Value);
332 // Compute Multiplication
333 public static SybaseInt32 operator * (SybaseInt32 x, SybaseInt32 y)
335 return new SybaseInt32 (x.Value * y.Value);
338 // Ones Complement
339 public static SybaseInt32 operator ~ (SybaseInt32 x)
341 return new SybaseInt32 (~x.Value);
344 // Subtraction
345 public static SybaseInt32 operator - (SybaseInt32 x, SybaseInt32 y)
347 return new SybaseInt32 (x.Value - y.Value);
350 // Negates the Value
351 public static SybaseInt32 operator - (SybaseInt32 x)
353 return new SybaseInt32 (-x.Value);
356 // Type Conversions
357 public static explicit operator SybaseInt32 (SybaseBoolean x)
359 if (x.IsNull)
360 return Null;
361 else
362 return new SybaseInt32 ((int)x.ByteValue);
365 public static explicit operator SybaseInt32 (SybaseDecimal x)
367 if (x.IsNull)
368 return Null;
369 else
370 return new SybaseInt32 ((int)x.Value);
373 public static explicit operator SybaseInt32 (SybaseDouble x)
375 if (x.IsNull)
376 return Null;
377 else
378 return new SybaseInt32 ((int)x.Value);
381 public static explicit operator int (SybaseInt32 x)
383 return x.Value;
386 public static explicit operator SybaseInt32 (SybaseInt64 x)
388 if (x.IsNull)
389 return Null;
390 else
391 return new SybaseInt32 ((int)x.Value);
394 public static explicit operator SybaseInt32(SybaseMoney x)
396 if (x.IsNull)
397 return Null;
398 else
399 return new SybaseInt32 ((int)x.Value);
402 public static explicit operator SybaseInt32(SybaseSingle x)
404 if (x.IsNull)
405 return Null;
406 else
407 return new SybaseInt32 ((int)x.Value);
410 public static explicit operator SybaseInt32(SybaseString x)
412 return SybaseInt32.Parse (x.Value);
415 public static implicit operator SybaseInt32(int x)
417 return new SybaseInt32 (x);
420 public static implicit operator SybaseInt32(SybaseByte x)
422 if (x.IsNull)
423 return Null;
424 else
425 return new SybaseInt32 ((int)x.Value);
428 public static implicit operator SybaseInt32(SybaseInt16 x)
430 if (x.IsNull)
431 return Null;
432 else
433 return new SybaseInt32 ((int)x.Value);
436 #endregion