* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Mono.Data.SybaseClient / Mono.Data.SybaseTypes / SybaseInt32.cs
1 //
2 // Mono.Data.SybaseTypes.SybaseInt32
3 //
4 // Author:
5 //   Tim Coleman (tim@timcoleman.com)
6 //
7 // (C) Copyright Tim Coleman, 2002
8 //
9
10 //
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.
29 //
30
31 using Mono.Data.SybaseClient;
32 using System;
33 using System.Data.SqlTypes;
34 using System.Globalization;
35
36 namespace Mono.Data.SybaseTypes {
37         public struct SybaseInt32 : INullable, IComparable 
38         {
39                 #region Fields
40
41                 int value;
42                 private bool notNull;
43
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);
48
49                 #endregion
50
51                 #region Constructors
52
53                 public SybaseInt32(int value) 
54                 {
55                         this.value = value;
56                         notNull = true;
57                 }
58
59                 #endregion
60
61                 #region Properties
62
63                 public bool IsNull {
64                         get { return !notNull; }
65                 }
66
67                 public int Value {
68                         get { 
69                                 if (this.IsNull) 
70                                         throw new SybaseNullValueException ();
71                                 else 
72                                         return value; 
73                         }
74                 }
75
76                 #endregion
77
78                 #region Methods
79
80                 public static SybaseInt32 Add (SybaseInt32 x, SybaseInt32 y) 
81                 {
82                         return (x + y);
83                 }
84
85                 public static SybaseInt32 BitwiseAnd(SybaseInt32 x, SybaseInt32 y) 
86                 {
87                         return (x & y);
88                 }
89                 
90                 public static SybaseInt32 BitwiseOr(SybaseInt32 x, SybaseInt32 y) 
91                 {
92                         return (x | y);
93                 }
94
95                 public int CompareTo(object value) 
96                 {
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);
105                 }
106
107                 public static SybaseInt32 Divide(SybaseInt32 x, SybaseInt32 y) 
108                 {
109                         return (x / y);
110                 }
111
112                 public override bool Equals(object value) 
113                 {
114                         if (!(value is SybaseInt32))
115                                 return false;
116                         else
117                                 return (bool) (this == (SybaseInt32)value);
118                 }
119
120                 public static SybaseBoolean Equals(SybaseInt32 x, SybaseInt32 y) 
121                 {
122                         return (x == y);
123                 }
124
125                 public override int GetHashCode() 
126                 {
127                         return value;
128                 }
129
130                 public static SybaseBoolean GreaterThan (SybaseInt32 x, SybaseInt32 y) 
131                 {
132                         return (x > y);
133                 }
134
135                 public static SybaseBoolean GreaterThanOrEqual (SybaseInt32 x, SybaseInt32 y) 
136                 {
137                         return (x >= y);
138                 }
139                 
140                 public static SybaseBoolean LessThan(SybaseInt32 x, SybaseInt32 y) 
141                 {
142                         return (x < y);
143                 }
144
145                 public static SybaseBoolean LessThanOrEqual(SybaseInt32 x, SybaseInt32 y) 
146                 {
147                         return (x <= y);
148                 }
149
150                 public static SybaseInt32 Mod(SybaseInt32 x, SybaseInt32 y) 
151                 {
152                         return (x % y);
153                 }
154
155                 public static SybaseInt32 Multiply(SybaseInt32 x, SybaseInt32 y) 
156                 {
157                         return (x * y);
158                 }
159
160                 public static SybaseBoolean NotEquals(SybaseInt32 x, SybaseInt32 y) 
161                 {
162                         return (x != y);
163                 }
164
165                 public static SybaseInt32 OnesComplement(SybaseInt32 x) 
166                 {
167                         return ~x;
168                 }
169
170                 public static SybaseInt32 Parse(string s) 
171                 {
172                         return new SybaseInt32 (Int32.Parse (s));
173                 }
174
175                 public static SybaseInt32 Subtract(SybaseInt32 x, SybaseInt32 y) 
176                 {
177                         return (x - y);
178                 }
179
180                 public SybaseBoolean ToSybaseBoolean() 
181                 {
182                         return ((SybaseBoolean)this);
183                 }
184
185                 public SybaseByte ToSybaseByte() 
186                 {
187                         return ((SybaseByte)this);
188                 }
189
190                 public SybaseDecimal ToSybaseDecimal() 
191                 {
192                         return ((SybaseDecimal)this);
193                 }
194
195                 public SybaseDouble ToSybaseDouble()    
196                 {
197                         return ((SybaseDouble)this);
198                 }
199
200                 public SybaseInt16 ToSybaseInt16() 
201                 {
202                         return ((SybaseInt16)this);
203                 }
204
205                 public SybaseInt64 ToSybaseInt64() 
206                 {
207                         return ((SybaseInt64)this);
208                 }
209
210                 public SybaseMoney ToSybaseMoney() 
211                 {
212                         return ((SybaseMoney)this);
213                 }
214
215                 public SybaseSingle ToSybaseSingle() 
216                 {
217                         return ((SybaseSingle)this);
218                 }
219
220                 public SybaseString ToSybaseString ()
221                 {
222                         return ((SybaseString)this);
223                 }
224
225                 public override string ToString() 
226                 {
227                         if (this.IsNull)
228                                 return "Null";
229                         else
230                                 return value.ToString ();
231                 }
232
233                 public static SybaseInt32 Xor(SybaseInt32 x, SybaseInt32 y) 
234                 {
235                         return (x ^ y);
236                 }
237
238                 #endregion
239
240                 #region Operators
241
242                 // Compute Addition
243                 public static SybaseInt32 operator + (SybaseInt32 x, SybaseInt32 y) 
244                 {
245                         return new SybaseInt32 (x.Value + y.Value);
246                 }
247
248                 // Bitwise AND
249                 public static SybaseInt32 operator & (SybaseInt32 x, SybaseInt32 y) 
250                 {
251                         return new SybaseInt32 (x.Value & y.Value);
252                 }
253
254                 // Bitwise OR
255                 public static SybaseInt32 operator | (SybaseInt32 x, SybaseInt32 y) 
256                 {
257                         return new SybaseInt32 (x.Value | y.Value);
258                 }
259
260                 // Compute Division
261                 public static SybaseInt32 operator / (SybaseInt32 x, SybaseInt32 y) 
262                 {
263                         return new SybaseInt32 (x.Value / y.Value);
264                 }
265
266                 // Compare Equality
267                 public static SybaseBoolean operator == (SybaseInt32 x, SybaseInt32 y) 
268                 {
269                         if (x.IsNull || y.IsNull) 
270                                 return SybaseBoolean.Null;
271                         else
272                                 return new SybaseBoolean (x.Value == y.Value);
273                 }
274
275                 // Bitwise Exclusive-OR (XOR)
276                 public static SybaseInt32 operator ^ (SybaseInt32 x, SybaseInt32 y) 
277                 {
278                         return new SybaseInt32 (x.Value ^ y.Value);
279                 }
280
281                 // > Compare
282                 public static SybaseBoolean operator >(SybaseInt32 x, SybaseInt32 y) 
283                 {
284                         if (x.IsNull || y.IsNull) 
285                                 return SybaseBoolean.Null;
286                         else
287                                 return new SybaseBoolean (x.Value > y.Value);
288                 }
289
290                 // >= Compare
291                 public static SybaseBoolean operator >= (SybaseInt32 x, SybaseInt32 y) 
292                 {
293                         if (x.IsNull || y.IsNull) 
294                                 return SybaseBoolean.Null;
295                         else
296                                 return new SybaseBoolean (x.Value >= y.Value);
297                 }
298
299                 // != Inequality Compare
300                 public static SybaseBoolean operator != (SybaseInt32 x, SybaseInt32 y) 
301                 {
302                         if (x.IsNull || y.IsNull) 
303                                 return SybaseBoolean.Null;
304                         else
305                                 return new SybaseBoolean (x.Value != y.Value);
306                 }
307                 
308                 // < Compare
309                 public static SybaseBoolean operator < (SybaseInt32 x, SybaseInt32 y) 
310                 {
311                         if (x.IsNull || y.IsNull) 
312                                 return SybaseBoolean.Null;
313                         else
314                                 return new SybaseBoolean (x.Value < y.Value);
315                 }
316
317                 // <= Compare
318                 public static SybaseBoolean operator <= (SybaseInt32 x, SybaseInt32 y) 
319                 {
320                         if (x.IsNull || y.IsNull) 
321                                 return SybaseBoolean.Null;
322                         else
323                                 return new SybaseBoolean (x.Value <= y.Value);
324                 }
325
326                 // Compute Modulus
327                 public static SybaseInt32 operator % (SybaseInt32 x, SybaseInt32 y) 
328                 {
329                         return new SybaseInt32 (x.Value % y.Value);
330                 }
331
332                 // Compute Multiplication
333                 public static SybaseInt32 operator * (SybaseInt32 x, SybaseInt32 y) 
334                 {
335                         return new SybaseInt32 (x.Value * y.Value);
336                 }
337
338                 // Ones Complement
339                 public static SybaseInt32 operator ~ (SybaseInt32 x) 
340                 {
341                         return new SybaseInt32 (~x.Value);
342                 }
343
344                 // Subtraction
345                 public static SybaseInt32 operator - (SybaseInt32 x, SybaseInt32 y) 
346                 {
347                         return new SybaseInt32 (x.Value - y.Value);
348                 }
349
350                 // Negates the Value
351                 public static SybaseInt32 operator - (SybaseInt32 x) 
352                 {
353                         return new SybaseInt32 (-x.Value);
354                 }
355
356                 // Type Conversions
357                 public static explicit operator SybaseInt32 (SybaseBoolean x) 
358                 {
359                         if (x.IsNull) 
360                                 return Null;
361                         else 
362                                 return new SybaseInt32 ((int)x.ByteValue);
363                 }
364
365                 public static explicit operator SybaseInt32 (SybaseDecimal x) 
366                 {
367                         if (x.IsNull) 
368                                 return Null;
369                         else 
370                                 return new SybaseInt32 ((int)x.Value);
371                 }
372
373                 public static explicit operator SybaseInt32 (SybaseDouble x) 
374                 {
375                         if (x.IsNull) 
376                                 return Null;
377                         else 
378                                 return new SybaseInt32 ((int)x.Value);
379                 }
380
381                 public static explicit operator int (SybaseInt32 x)
382                 {
383                         return x.Value;
384                 }
385
386                 public static explicit operator SybaseInt32 (SybaseInt64 x) 
387                 {
388                         if (x.IsNull) 
389                                 return Null;
390                         else 
391                                 return new SybaseInt32 ((int)x.Value);
392                 }
393
394                 public static explicit operator SybaseInt32(SybaseMoney x) 
395                 {
396                         if (x.IsNull) 
397                                 return Null;
398                         else 
399                                 return new SybaseInt32 ((int)x.Value);
400                 }
401
402                 public static explicit operator SybaseInt32(SybaseSingle x) 
403                 {
404                         if (x.IsNull) 
405                                 return Null;
406                         else 
407                                 return new SybaseInt32 ((int)x.Value);
408                 }
409
410                 public static explicit operator SybaseInt32(SybaseString x) 
411                 {
412                         return SybaseInt32.Parse (x.Value);
413                 }
414
415                 public static implicit operator SybaseInt32(int x) 
416                 {
417                         return new SybaseInt32 (x);
418                 }
419
420                 public static implicit operator SybaseInt32(SybaseByte x) 
421                 {
422                         if (x.IsNull) 
423                                 return Null;
424                         else 
425                                 return new SybaseInt32 ((int)x.Value);
426                 }
427
428                 public static implicit operator SybaseInt32(SybaseInt16 x) 
429                 {
430                         if (x.IsNull) 
431                                 return Null;
432                         else 
433                                 return new SybaseInt32 ((int)x.Value);
434                 }
435
436                 #endregion
437         }
438 }