2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.Data.OracleClient / System.Data.OracleClient / OracleString.cs
1 //
2 // OracleString.cs 
3 //
4 // Part of the Mono class libraries at
5 // mcs/class/System.Data.OracleClient/System.Data.OracleClient
6 //
7 // Assembly: System.Data.OracleClient.dll
8 // Namespace: System.Data.OracleClient
9 //
10 // Authors: Tim Coleman <tim@timcoleman.com>
11 //          Atsushi Enomoto <atsushi@ximian.com>
12 //
13 // Copyright (C) Tim Coleman, 2003
14 //
15 // Licensed under the MIT/X11 License.
16 //
17
18 using System;
19 using System.Data.SqlTypes;
20 using System.Globalization;
21
22 namespace System.Data.OracleClient
23 {
24         public struct OracleString : IComparable, INullable
25         {
26                 #region Fields
27
28                 string value;
29                 bool notNull;
30
31                 public static readonly OracleString Empty = new OracleString (String.Empty);
32                 public static readonly OracleString Null = new OracleString ();
33
34                 #endregion // Fields
35
36                 #region Constructors
37
38                 public OracleString (string s)
39                 {
40                         value = s;
41                         notNull = true;
42                 }
43
44                 #endregion // Constructors
45
46                 #region Properties
47
48                 public bool IsNull {
49                         get { return !notNull; }
50                 }
51
52                 public int Length {
53                         get { return value.Length; }
54                 }
55
56                 public char this [int index] {
57                         get { return value [index]; }
58                 }
59
60                 public string Value {
61                         get { return value; }
62                 }
63
64                 #endregion // Properties
65
66                 #region Methods
67
68                 public int CompareTo (object value)
69                 {
70                         if (value == null)
71                                 return 1;
72                         else if (!(value is OracleString))
73                                 throw new ArgumentException ("Value is not a System.Data.OracleClient.OracleString");
74                         else if (((OracleString) value).IsNull)
75                                 return 1;
76                         else
77                                 return this.value.CompareTo (((OracleString) value).Value);
78                 }
79
80                 [MonoTODO]
81                 public static OracleBoolean GreaterThan (OracleString x, OracleString y)
82                 {
83                         throw new NotImplementedException ();
84                 }
85
86                 [MonoTODO]
87                 public static OracleBoolean GreaterThanOrEqual (OracleString x, OracleString y)
88                 {
89                         throw new NotImplementedException ();
90                 }
91
92                 public static OracleBoolean LessThan (OracleString x, OracleString y)
93                 {
94                         return (x < y);
95                 }
96
97                 public static OracleBoolean LessThanOrEqual (OracleString x, OracleString y)
98                 {
99                         return (x <= y);
100                 }
101
102                 public static OracleString Concat (OracleString x, OracleString y)
103                 {
104                         return x + y;
105                 }
106
107                 public override int GetHashCode ()
108                 {
109                         // It returns value string's HashCode.
110                         return notNull ? value.GetHashCode () : 0;
111                 }
112
113                 public override bool Equals (object o)
114                 {
115                         if (o is OracleString) {
116                                 OracleString s = (OracleString) o;
117                                 if (notNull && s.notNull)
118                                         return value == s.value;
119                                 else
120                                         throw new InvalidOperationException ("the value is Null.");
121                         }
122                         return false;
123                 }
124
125                 public static OracleBoolean Equals (OracleString x, OracleString y)
126                 {
127                         return (x == y);
128                 }
129
130                 public static OracleBoolean NotEquals (OracleString x, OracleString y)
131                 {
132                         return (x != y);
133                 }
134
135                 public override string ToString ()
136                 {
137                         return notNull ? value : "Null";
138                 }
139
140                 #endregion // Methods
141
142                 #region Operators
143
144                 public static OracleString operator + (OracleString x, OracleString y)
145                 {
146                         return (x.notNull && y.notNull) ?
147                                 new OracleString (x.value + y.value) :
148                                 Null;
149                 }
150
151                 public static OracleBoolean operator == (OracleString x, OracleString y)
152                 {
153                         return (!x.notNull || !y.notNull) ?
154                                 OracleBoolean.Null : new OracleBoolean (x.value == y.value);
155                 }
156
157                 public static explicit operator string (OracleString x)
158                 {
159                         return x.Value;
160                 }
161
162                 [MonoTODO]
163                 public static OracleBoolean operator > (OracleString x, OracleString y)
164                 {
165                         throw new NotImplementedException ();
166                 }
167
168                 [MonoTODO]
169                 public static OracleBoolean operator >= (OracleString x, OracleString y)
170                 {
171                         throw new NotImplementedException ();
172                 }
173
174                 public static implicit operator OracleString (string s)
175                 {
176                         return new OracleString (s);
177                 }
178
179                 public static OracleBoolean operator != (OracleString x, OracleString y)
180                 {
181                         return (!x.notNull || !y.notNull) ?
182                                 OracleBoolean.Null : x.value != y.value;
183                 }
184
185                 public static OracleBoolean operator < (OracleString x, OracleString y)
186                 {
187                         return (!x.notNull || !y.notNull) ?
188                                 OracleBoolean.Null :
189                                 new OracleBoolean (String.Compare (x.value, y.value, false, CultureInfo.InvariantCulture) < 0);
190                 }
191
192                 public static OracleBoolean operator <= (OracleString x, OracleString y)
193                 {
194                         return (!x.notNull || !y.notNull) ?
195                                 OracleBoolean.Null : new OracleBoolean (String.Compare (x.value, y.value, false, CultureInfo.InvariantCulture) <= 0);
196                 }
197
198                 #endregion // Operators
199         }
200 }