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