2002-05-07 Tim Coleman <tim@timcoleman.com>
[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
12 namespace System.Data.SqlTypes
13 {
14         public struct SqlInt64 : INullable, IComparable
15         {
16                 #region Fields
17
18                 long value;
19                 
20                 [MonoTODO]
21                 public static readonly SqlInt64 MaxValue; // 2^63 - 1
22
23                 [MonoTODO]
24                 public static readonly SqlInt64 MinValue; // -2^63
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                 }
37
38                 #endregion
39
40                 #region Properties
41
42                 public bool IsNull { 
43                         get { return (bool) (this == Null); }
44                 }
45
46                 public long Value { 
47                         get { 
48                                 if (this.IsNull) 
49                                         throw new SqlNullValueException ();
50                                 else 
51                                         return value; 
52                         }
53                 }
54
55                 #endregion
56
57                 #region Methods
58
59                 public static SqlInt64 Add (SqlInt64 x, SqlInt64 y)
60                 {
61                         return (x + y);
62                 }
63
64                 public static SqlInt64 BitwiseAnd (SqlInt64 x, SqlInt64 y)
65                 {
66                         return (x & y);
67                 }
68
69                 public static SqlInt64 BitwiseOr (SqlInt64 x, SqlInt64 y)
70                 {
71                         return (x | y);
72                 }
73
74                 public int CompareTo (object value)
75                 {
76                         if (value == null)
77                                 return 1;
78                         else if (!(value is SqlInt64))
79                                 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlInt64"));
80                         else if (value.IsNull)
81                                 return 1;
82                         else
83                                 return value.CompareTo (value.Value);
84                 }
85
86                 public static SqlInt64 Divide (SqlInt64 x, SqlInt64 y)
87                 {
88                         return (x / y);
89                 }
90
91                 public override bool Equals (object value)
92                 {
93                         if (!(value is SqlInt64))
94                                 return false;
95                         else
96                                 return (bool) (this == value);
97                 }
98
99                 public static SqlBoolean Equals (SqlInt64 x, SqlInt64 y)
100                 {
101                         return (x == y);
102                 }
103
104                 [MonoTODO]
105                 public override int GetHashCode ()
106                 {
107                         return (int)value;
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                         return ~x;
148                 }
149
150                 [MonoTODO]
151                 public static SqlInt64 Parse (string s)
152                 {
153                         throw new NotImplementedException ();
154                 }
155
156                 public static SqlInt64 Subtract (SqlInt64 x, SqlInt64 y)
157                 {
158                         return (x - y);
159                 }
160
161                 public SqlBoolean ToSqlBoolean ()
162                 {
163                         return ((SqlBoolean)this);
164                 }
165                 
166                 public SqlByte ToSqlByte ()
167                 {
168                         return ((SqlByte)this);
169                 }
170
171                 public SqlDecimal ToSqlDecimal ()
172                 {
173                         return ((SqlDecimal)this);
174                 }
175
176                 public SqlDouble ToSqlDouble ()
177                 {
178                         return ((SqlDouble)this);
179                 }
180
181                 public SqlInt16 ToSqlInt16 ()
182                 {
183                         return ((SqlInt16)this);
184                 }
185
186                 public SqlInt32 ToSqlInt32 ()
187                 {
188                         return ((SqlInt32)this);
189                 }
190
191                 public SqlMoney ToSqlMoney ()
192                 {
193                         return ((SqlMoney)this);
194                 }
195
196                 public SqlSingle ToSqlSingle ()
197                 {
198                         return ((SqlSingle)this);
199                 }
200
201                 public SqlString ToSqlString ()
202                 {
203                         return ((SqlString)this);
204                 }
205
206                 public override string ToString ()
207                 {
208                         return value.ToString ();
209                 }
210
211                 public static SqlInt64 Xor (SqlInt64 x, SqlInt64 y)
212                 {
213                         return (x ^ y);
214                 }
215
216                 public static SqlInt64 operator + (SqlInt64 x, SqlInt64 y)
217                 {
218                         return new SqlInt64 (x.Value + y.Value);
219                 }
220
221                 public static SqlInt64 operator & (SqlInt64 x, SqlInt64 y)
222                 {
223                         return new SqlInt64 (x.value & y.Value);
224                 }
225
226                 public static SqlInt64 operator | (SqlInt64 x, SqlInt64 y)
227                 {
228                         return new SqlInt64 (x.value | y.Value);
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 SqlBoolean operator == (SqlInt64 x, SqlInt64 y)
237                 {
238                         if (x.IsNull || y.IsNull) 
239                                 return SqlBoolean.Null;
240                         else
241                                 return new SqlBoolean (x.Value == y.Value);
242                 }
243
244                 public static SqlInt64 operator ^ (SqlInt64 x, SqlInt64 y)
245                 {
246                         return new SqlInt64 (x.Value ^ y.Value);
247                 }
248
249                 public static SqlBoolean operator > (SqlInt64 x, SqlInt64 y)
250                 {
251                         if (x.IsNull || y.IsNull) 
252                                 return SqlBoolean.Null;
253                         else
254                                 return new SqlBoolean (x.Value > y.Value);
255                 }
256
257                 public static SqlBoolean operator >= (SqlInt64 x, SqlInt64 y)
258                 {
259                         if (x.IsNull || y.IsNull) 
260                                 return SqlBoolean.Null;
261                         else
262                                 return new SqlBoolean (x.Value >= y.Value);
263                 }
264
265                 public static SqlBoolean operator != (SqlInt64 x, SqlInt64 y)
266                 {
267                         if (x.IsNull || y.IsNull) 
268                                 return SqlBoolean.Null;
269                         else
270                                 return new SqlBoolean (!(x.Value == y.Value));
271                 }
272
273                 public static SqlBoolean operator < (SqlInt64 x, SqlInt64 y)
274                 {
275                         if (x.IsNull || y.IsNull) 
276                                 return SqlBoolean.Null;
277                         else
278                                 return new SqlBoolean (x.Value < y.Value);
279                 }
280
281                 public static SqlBoolean operator <= (SqlInt64 x, SqlInt64 y)
282                 {
283                         if (x.IsNull || y.IsNull) 
284                                 return SqlBoolean.Null;
285                         else
286                                 return new SqlBoolean (x.Value <= y.Value);
287                 }
288
289                 public static SqlInt64 operator % (SqlInt64 x, SqlInt64 y)
290                 {
291                         return new SqlInt64(x.Value % y.Value);
292                 }
293
294                 public static SqlInt64 operator * (SqlInt64 x, SqlInt64 y)
295                 {
296                         return new SqlInt64 (x.Value * y.Value);
297                 }
298
299                 public static SqlInt64 operator ~ (SqlInt64 x)
300                 {
301                         return new SqlInt64 (~(x.Value));
302                 }
303
304                 public static SqlInt64 operator - (SqlInt64 x, SqlInt64 y)
305                 {
306                         return new SqlInt64 (x.Value - y.Value);
307                 }
308
309                 public static SqlInt64 operator - (SqlInt64 n)
310                 {
311                         return new SqlInt64 (-(n.Value));
312                 }
313
314                 public static explicit operator SqlInt64 (SqlBoolean x)
315                 {
316                         if (x.IsNull) 
317                                 return SqlInt64.Null;
318                         else
319                                 return new SqlInt64 ((long)x.ByteValue);
320                 }
321
322                 public static explicit operator SqlInt64 (SqlDecimal x)
323                 {
324                         if (x.IsNull) 
325                                 return SqlInt64.Null;
326                         else
327                                 return new SqlInt64 ((long)x.Value);
328                 }
329
330                 public static explicit operator SqlInt64 (SqlDouble x)
331                 {
332                         if (x.IsNull) 
333                                 return SqlInt64.Null;
334                         else
335                                 return new SqlInt64 ((long)x.Value);
336                 }
337
338                 public static explicit operator long (SqlInt64 x)
339                 {
340                         return x.Value;
341                 }
342
343                 public static explicit operator SqlInt64 (SqlMoney x)
344                 {
345                         if (x.IsNull) 
346                                 return SqlInt64.Null;
347                         else
348                                 return new SqlInt64 ((long)x.Value);
349                 }
350
351                 public static explicit operator SqlInt64 (SqlSingle x)
352                 {
353                         if (x.IsNull) 
354                                 return SqlInt64.Null;
355                         else
356                                 return new SqlInt64 ((long)x.Value);
357                 }
358
359                 [MonoTODO]
360                 public static explicit operator SqlInt64 (SqlString x)
361                 {
362                         throw new NotImplementedException ();
363                 }
364
365                 public static implicit operator SqlInt64 (long x)
366                 {
367                         return new SqlInt64 (x);
368                 }
369
370                 public static implicit operator SqlInt64 (SqlByte x)
371                 {
372                         if (x.IsNull) 
373                                 return SqlInt64.Null;
374                         else
375                                 return new SqlInt64 ((long)x.Value);
376                 }
377
378                 public static implicit operator SqlInt64 (SqlInt16 x)
379                 {
380                         if (x.IsNull) 
381                                 return SqlInt64.Null;
382                         else
383                                 return new SqlInt64 ((long)x.Value);
384                 }
385
386                 public static implicit operator SqlInt64 (SqlInt32 x)
387                 {
388                         if (x.IsNull) 
389                                 return SqlInt64.Null;
390                         else
391                                 return new SqlInt64 ((long)x.Value);
392                 }
393
394                 #endregion
395         }
396 }
397