2002-10-31 Ville Palo <vi64pa@koti.soon.fi>
[mono.git] / mcs / class / System.Data / System.Data.SqlTypes / SqlInt64.cs
1 //
2 // System.Data.SqlTypes.SqlInt64
3 //
4 // Author:
5 //   Tim Coleman <tim@timcoleman.com>
6 //
7 // (C) Copyright 2002 Tim Coleman
8 //
9
10 using System;
11 using System.Globalization;
12
13 namespace System.Data.SqlTypes
14 {
15         public struct SqlInt64 : INullable, IComparable
16         {
17                 #region Fields
18
19                 long value;
20
21                 private bool notNull;
22                 
23                 public static readonly SqlInt64 MaxValue = new SqlInt64 (9223372036854775807);
24                 public static readonly SqlInt64 MinValue = new SqlInt64 (-9223372036854775808);
25
26                 public static readonly SqlInt64 Null;
27                 public static readonly SqlInt64 Zero = new SqlInt64 (0);
28
29                 #endregion
30
31                 #region Constructors
32
33                 public SqlInt64 (long value) 
34                 {
35                         this.value = value;
36                         notNull = true;
37                 }
38
39                 #endregion
40
41                 #region Properties
42
43                 public bool IsNull { 
44                         get { return !notNull; }
45                 }
46
47                 public long Value { 
48                         get { 
49                                 if (this.IsNull) 
50                                         throw new SqlNullValueException ();
51                                 else 
52                                         return value; 
53                         }
54                 }
55
56                 #endregion
57
58                 #region Methods
59
60                 public static SqlInt64 Add (SqlInt64 x, SqlInt64 y)
61                 {
62                         return (x + y);
63                 }
64
65                 public static SqlInt64 BitwiseAnd (SqlInt64 x, SqlInt64 y)
66                 {
67                         return (x & y);
68                 }
69
70                 public static SqlInt64 BitwiseOr (SqlInt64 x, SqlInt64 y)
71                 {
72                         return (x | y);
73                 }
74
75                 public int CompareTo (object value)
76                 {
77                         if (value == null)
78                                 return 1;
79                         else if (!(value is SqlInt64))
80                                 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlInt64"));
81                         else if (((SqlInt64)value).IsNull)
82                                 return 1;
83                         else
84                                 return this.value.CompareTo (((SqlInt64)value).Value);
85                 }
86
87                 public static SqlInt64 Divide (SqlInt64 x, SqlInt64 y)
88                 {
89                         return (x / y);
90                 }
91
92                 public override bool Equals (object value)
93                 {
94                         if (!(value is SqlInt64))
95                                 return false;
96                         else
97                                 return (bool) (this == (SqlInt64)value);
98                 }
99
100                 public static SqlBoolean Equals (SqlInt64 x, SqlInt64 y)
101                 {
102                         return (x == y);
103                 }
104
105                 public override int GetHashCode ()
106                 {
107                         return (int)(value & 0xffffffff) ^ (int)(value >> 32);
108                 }
109
110                 public static SqlBoolean GreaterThan (SqlInt64 x, SqlInt64 y)
111                 {
112                         return (x > y);
113                 }
114
115                 public static SqlBoolean GreaterThanOrEqual (SqlInt64 x, SqlInt64 y)
116                 {
117                         return (x >= y);
118                 }
119
120                 public static SqlBoolean LessThan (SqlInt64 x, SqlInt64 y)
121                 {
122                         return (x < y);
123                 }
124
125                 public static SqlBoolean LessThanOrEqual (SqlInt64 x, SqlInt64 y)
126                 {
127                         return (x <= y);
128                 }
129
130                 public static SqlInt64 Mod (SqlInt64 x, SqlInt64 y)
131                 {
132                         return (x % y);
133                 }
134
135                 public static SqlInt64 Multiply (SqlInt64 x, SqlInt64 y)
136                 {
137                         return (x * y);
138                 }
139
140                 public static SqlBoolean NotEquals (SqlInt64 x, SqlInt64 y)
141                 {
142                         return (x != y);
143                 }
144
145                 public static SqlInt64 OnesComplement (SqlInt64 x)
146                 {
147                         if (x.IsNull)
148                                 return Null;
149
150                         return ~x;
151                 }
152
153
154                 public static SqlInt64 Parse (string s)
155                 {
156                         checked {
157                                 return new SqlInt64 (Int64.Parse (s));
158                         }
159                 }
160
161                 public static SqlInt64 Subtract (SqlInt64 x, SqlInt64 y)
162                 {
163                         return (x - y);
164                 }
165
166                 public SqlBoolean ToSqlBoolean ()
167                 {
168                         return ((SqlBoolean)this);
169                 }
170                 
171                 public SqlByte ToSqlByte ()
172                 {
173                         return ((SqlByte)this);
174                 }
175
176                 public SqlDecimal ToSqlDecimal ()
177                 {
178                         return ((SqlDecimal)this);
179                 }
180
181                 public SqlDouble ToSqlDouble ()
182                 {
183                         return ((SqlDouble)this);
184                 }
185
186                 public SqlInt16 ToSqlInt16 ()
187                 {
188                         return ((SqlInt16)this);
189                 }
190
191                 public SqlInt32 ToSqlInt32 ()
192                 {
193                         return ((SqlInt32)this);
194                 }
195
196                 public SqlMoney ToSqlMoney ()
197                 {
198                         return ((SqlMoney)this);
199                 }
200
201                 public SqlSingle ToSqlSingle ()
202                 {
203                         return ((SqlSingle)this);
204                 }
205
206                 public SqlString ToSqlString ()
207                 {
208                         return ((SqlString)this);
209                 }
210
211                 public override string ToString ()
212                 {
213                         if (this.IsNull)
214                                 return "Null";
215
216                         return value.ToString ();
217                 }
218
219                 public static SqlInt64 Xor (SqlInt64 x, SqlInt64 y)
220                 {
221                         return (x ^ y);
222                 }
223
224                 public static SqlInt64 operator + (SqlInt64 x, SqlInt64 y)
225                 {
226                         checked {
227                                 return new SqlInt64 (x.Value + y.Value);
228                         }
229                 }
230
231                 public static SqlInt64 operator & (SqlInt64 x, SqlInt64 y)
232                 {
233                         return new SqlInt64 (x.value & y.Value);
234                 }
235
236                 public static SqlInt64 operator | (SqlInt64 x, SqlInt64 y)
237                 {
238                         return new SqlInt64 (x.value | y.Value);
239                 }
240
241                 public static SqlInt64 operator / (SqlInt64 x, SqlInt64 y)
242                 {
243                         return new SqlInt64 (x.Value / y.Value);
244                 }
245
246                 public static SqlBoolean operator == (SqlInt64 x, SqlInt64 y)
247                 {
248                         if (x.IsNull || y.IsNull) 
249                                 return SqlBoolean.Null;
250                         else
251                                 return new SqlBoolean (x.Value == y.Value);
252                 }
253
254                 public static SqlInt64 operator ^ (SqlInt64 x, SqlInt64 y)
255                 {
256                         return new SqlInt64 (x.Value ^ y.Value);
257                 }
258
259                 public static SqlBoolean operator > (SqlInt64 x, SqlInt64 y)
260                 {
261                         if (x.IsNull || y.IsNull) 
262                                 return SqlBoolean.Null;
263                         else
264                                 return new SqlBoolean (x.Value > y.Value);
265                 }
266
267                 public static SqlBoolean operator >= (SqlInt64 x, SqlInt64 y)
268                 {
269                         if (x.IsNull || y.IsNull) 
270                                 return SqlBoolean.Null;
271                         else
272                                 return new SqlBoolean (x.Value >= y.Value);
273                 }
274
275                 public static SqlBoolean operator != (SqlInt64 x, SqlInt64 y)
276                 {
277                         if (x.IsNull || y.IsNull) 
278                                 return SqlBoolean.Null;
279                         else
280                                 return new SqlBoolean (!(x.Value == y.Value));
281                 }
282
283                 public static SqlBoolean operator < (SqlInt64 x, SqlInt64 y)
284                 {
285                         if (x.IsNull || y.IsNull) 
286                                 return SqlBoolean.Null;
287                         else
288                                 return new SqlBoolean (x.Value < y.Value);
289                 }
290
291                 public static SqlBoolean operator <= (SqlInt64 x, SqlInt64 y)
292                 {
293                         if (x.IsNull || y.IsNull) 
294                                 return SqlBoolean.Null;
295                         else
296                                 return new SqlBoolean (x.Value <= y.Value);
297                 }
298
299                 public static SqlInt64 operator % (SqlInt64 x, SqlInt64 y)
300                 {
301                         return new SqlInt64(x.Value % y.Value);
302                 }
303
304                 public static SqlInt64 operator * (SqlInt64 x, SqlInt64 y)
305                 {
306                         checked {
307                                 return new SqlInt64 (x.Value * y.Value);
308                         }
309                 }
310
311                 public static SqlInt64 operator ~ (SqlInt64 x)
312                 {
313                         return new SqlInt64 (~(x.Value));
314                 }
315
316                 public static SqlInt64 operator - (SqlInt64 x, SqlInt64 y)
317                 {
318                         checked {
319                                 return new SqlInt64 (x.Value - y.Value);
320                         }
321                 }
322
323                 public static SqlInt64 operator - (SqlInt64 n)
324                 {
325                         return new SqlInt64 (-(n.Value));
326                 }
327
328                 public static explicit operator SqlInt64 (SqlBoolean x)
329                 {
330                         if (x.IsNull) 
331                                 return SqlInt64.Null;
332                         else
333                                 return new SqlInt64 ((long)x.ByteValue);
334                 }
335
336                 public static explicit operator SqlInt64 (SqlDecimal x)
337                 {
338                         if (x.IsNull) 
339                                 return SqlInt64.Null;
340                         else
341                                 return new SqlInt64 ((long)x.Value);
342                 }
343
344                 public static explicit operator SqlInt64 (SqlDouble x)
345                 {
346                         if (x.IsNull) 
347                                 return SqlInt64.Null;
348                         else
349                                 return new SqlInt64 ((long)x.Value);
350                 }
351
352                 public static explicit operator long (SqlInt64 x)
353                 {
354                         return x.Value;
355                 }
356
357                 public static explicit operator SqlInt64 (SqlMoney x)
358                 {
359                         if (x.IsNull) 
360                                 return SqlInt64.Null;
361                         else
362                                 return new SqlInt64 ((long)x.Value);
363                 }
364
365                 public static explicit operator SqlInt64 (SqlSingle x)
366                 {
367                         if (x.IsNull) 
368                                 return SqlInt64.Null;
369                         else
370                                 return new SqlInt64 ((long)x.Value);
371                 }
372
373                 public static explicit operator SqlInt64 (SqlString x)
374                 {
375                         return SqlInt64.Parse (x.Value);
376                 }
377
378                 public static implicit operator SqlInt64 (long x)
379                 {
380                         return new SqlInt64 (x);
381                 }
382
383                 public static implicit operator SqlInt64 (SqlByte x)
384                 {
385                         if (x.IsNull) 
386                                 return SqlInt64.Null;
387                         else
388                                 return new SqlInt64 ((long)x.Value);
389                 }
390
391                 public static implicit operator SqlInt64 (SqlInt16 x)
392                 {
393                         if (x.IsNull) 
394                                 return SqlInt64.Null;
395                         else
396                                 return new SqlInt64 ((long)x.Value);
397                 }
398
399                 public static implicit operator SqlInt64 (SqlInt32 x)
400                 {
401                         if (x.IsNull) 
402                                 return SqlInt64.Null;
403                         else
404                                 return new SqlInt64 ((long)x.Value);
405                 }
406
407                 #endregion
408         }
409 }
410