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