Update VS project files
[mono.git] / mcs / class / System.Data / System.Data.SqlTypes / SqlSingle.cs
index 94445e8f07c357f2ced65ac7e085b5c6340f4871..81b74ec25ddbae2b89dfbb60c4b532def04baebf 100644 (file)
@@ -8,17 +8,49 @@
 // (C) Copyright 2002 Tim Coleman
 //
 
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System;
+using System.Xml;
+using System.Xml.Schema;
 using System.Globalization;
+using System.Xml.Serialization;
 
 namespace System.Data.SqlTypes
 {
+#if NET_2_0
+       [SerializableAttribute]
+       [XmlSchemaProvider ("GetXsdType")]
+#endif
        public struct SqlSingle : INullable, IComparable
+#if NET_2_0
+                               , IXmlSerializable
+#endif
        {
                #region Fields
 
-               float value;
-
+               private float value;
                private bool notNull;
 
                public static readonly SqlSingle MaxValue = new SqlSingle (3.40282346638528859E+38f);
@@ -30,13 +62,13 @@ namespace System.Data.SqlTypes
 
                #region Constructors
 
-               public SqlSingle (double value) 
+               public SqlSingle (double value)
                {
                        this.value = (float)value;
                        notNull = true;
                }
 
-               public SqlSingle (float value) 
+               public SqlSingle (float value)
                {
                        this.value = value;
                        notNull = true;
@@ -46,13 +78,13 @@ namespace System.Data.SqlTypes
 
                #region Properties
 
-               public bool IsNull { 
+               public bool IsNull {
                        get { return !notNull; }
                }
 
-               public float Value { 
-                       get { 
-                               if (this.IsNull) 
+               public float Value {
+                       get {
+                               if (this.IsNull)
                                        throw new SqlNullValueException ();
                                else 
                                        return value; 
@@ -74,10 +106,23 @@ namespace System.Data.SqlTypes
                                return 1;
                        else if (!(value is SqlSingle))
                                throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlSingle"));
-                       else if (((SqlSingle)value).IsNull)
+
+                       return CompareSqlSingle ((SqlSingle) value);
+               }
+
+#if NET_2_0
+               public int CompareTo (SqlSingle value)
+               {
+                       return CompareSqlSingle (value);
+               }
+#endif
+               
+               private int CompareSqlSingle (SqlSingle value)
+               {
+                       if (value.IsNull)
                                return 1;
                        else
-                               return this.value.CompareTo (((SqlSingle)value).Value);
+                               return this.value.CompareTo (value.Value);
                }
 
                public static SqlSingle Divide (SqlSingle x, SqlSingle y)
@@ -89,8 +134,8 @@ namespace System.Data.SqlTypes
                {
                        if (!(value is SqlSingle))
                                return false;
-                       else if (this.IsNull && ((SqlSingle)value).IsNull)
-                               return true;
+                       else if (this.IsNull)
+                               return ((SqlSingle)value).IsNull;
                        else if (((SqlSingle)value).IsNull)
                                return false;
                        else
@@ -105,7 +150,7 @@ namespace System.Data.SqlTypes
                public override int GetHashCode ()
                {
                        long LongValue = (long) value;
-                       return (int)(LongValue ^ (LongValue >> 32));
+                       return (int) (LongValue ^ (LongValue >> 32));
                }
 
                public static SqlBoolean GreaterThan (SqlSingle x, SqlSingle y)
@@ -150,58 +195,59 @@ namespace System.Data.SqlTypes
 
                public SqlBoolean ToSqlBoolean ()
                {
-                       return ((SqlBoolean)this);
+                       return ((SqlBoolean) this);
                }
                
                public SqlByte ToSqlByte ()
                {
-                       return ((SqlByte)this);
+                       return ((SqlByte) this);
                }
 
                public SqlDecimal ToSqlDecimal ()
                {
-                       return ((SqlDecimal)this);
+                       return ((SqlDecimal) this);
                }
 
                public SqlDouble ToSqlDouble ()
                {
-                       return ((SqlDouble)this);
+                       return ((SqlDouble) this);
                }
 
                public SqlInt16 ToSqlInt16 ()
                {
-                       return ((SqlInt16)this);
+                       return ((SqlInt16) this);
                }
 
                public SqlInt32 ToSqlInt32 ()
                {
-                       return ((SqlInt32)this);
+                       return ((SqlInt32) this);
                }
 
                public SqlInt64 ToSqlInt64 ()
                {
-                       return ((SqlInt64)this);
+                       return ((SqlInt64) this);
                }
 
                public SqlMoney ToSqlMoney ()
                {
-                       return ((SqlMoney)this);
+                       return ((SqlMoney) this);
                }
 
-
                public SqlString ToSqlString ()
                {
-                       return ((SqlString)this);
+                       return ((SqlString) this);
                }
 
                public override string ToString ()
                {
+                       if (!notNull)
+                               return "Null";
                        return value.ToString ();
                }
 
                public static SqlSingle operator + (SqlSingle x, SqlSingle y)
                {
-                       float f = (float)(x.Value + y.Value);
+                       float f = (float) (x.Value + y.Value);
 
                        if (Single.IsInfinity (f))
                                throw new OverflowException ();
@@ -211,10 +257,9 @@ namespace System.Data.SqlTypes
 
                public static SqlSingle operator / (SqlSingle x, SqlSingle y)
                {
-                       float f = (float)(x.Value / y.Value);
+                       float f = (float) (x.Value / y.Value);
 
                        if (Single.IsInfinity (f)) {
-                               
                                if (y.Value == 0d) 
                                        throw new DivideByZeroException ();
                        }
@@ -224,43 +269,49 @@ namespace System.Data.SqlTypes
 
                public static SqlBoolean operator == (SqlSingle x, SqlSingle y)
                {
-                       if (x.IsNull || y .IsNull) return SqlBoolean.Null;
+                       if (x.IsNull || y .IsNull)
+                               return SqlBoolean.Null;
                        return new SqlBoolean (x.Value == y.Value);
                }
 
                public static SqlBoolean operator > (SqlSingle x, SqlSingle y)
                {
-                       if (x.IsNull || y .IsNull) return SqlBoolean.Null;
+                       if (x.IsNull || y .IsNull)
+                               return SqlBoolean.Null;
                        return new SqlBoolean (x.Value > y.Value);
                }
 
                public static SqlBoolean operator >= (SqlSingle x, SqlSingle y)
                {
-                       if (x.IsNull || y .IsNull) return SqlBoolean.Null;
+                       if (x.IsNull || y .IsNull)
+                               return SqlBoolean.Null;
                        return new SqlBoolean (x.Value >= y.Value);
                }
 
                public static SqlBoolean operator != (SqlSingle x, SqlSingle y)
                {
-                       if (x.IsNull || y .IsNull) return SqlBoolean.Null;
+                       if (x.IsNull || y .IsNull)
+                               return SqlBoolean.Null;
                        return new SqlBoolean (!(x.Value == y.Value));
                }
 
                public static SqlBoolean operator < (SqlSingle x, SqlSingle y)
                {
-                       if (x.IsNull || y .IsNull) return SqlBoolean.Null;
+                       if (x.IsNull || y .IsNull)
+                               return SqlBoolean.Null;
                        return new SqlBoolean (x.Value < y.Value);
                }
 
                public static SqlBoolean operator <= (SqlSingle x, SqlSingle y)
                {
-                       if (x.IsNull || y .IsNull) return SqlBoolean.Null;
+                       if (x.IsNull || y .IsNull)
+                               return SqlBoolean.Null;
                        return new SqlBoolean (x.Value <= y.Value);
                }
 
                public static SqlSingle operator * (SqlSingle x, SqlSingle y)
                {
-                       float f = (float)(x.Value * y.Value);
+                       float f = (float) (x.Value * y.Value);
                        
                        if (Single.IsInfinity (f))
                                throw new OverflowException ();
@@ -270,7 +321,7 @@ namespace System.Data.SqlTypes
 
                public static SqlSingle operator - (SqlSingle x, SqlSingle y)
                {
-                       float f = (float)(x.Value - y.Value);
+                       float f = (float) (x.Value - y.Value);
 
                        if (Single.IsInfinity (f))
                                throw new OverflowException ();
@@ -278,9 +329,9 @@ namespace System.Data.SqlTypes
                        return new SqlSingle (f);
                }
 
-               public static SqlSingle operator - (SqlSingle n)
+               public static SqlSingle operator - (SqlSingle x)
                {
-                       return new SqlSingle (-(n.Value));
+                       return new SqlSingle (-(x.Value));
                }
 
                public static explicit operator SqlSingle (SqlBoolean x)
@@ -302,7 +353,7 @@ namespace System.Data.SqlTypes
 
                        if (Single.IsInfinity (f))
                                throw new OverflowException ();
-                               
+
                        return new SqlSingle(f);
                }
 
@@ -328,53 +379,78 @@ namespace System.Data.SqlTypes
 
                public static implicit operator SqlSingle (SqlByte x)
                {
-                       if (x.IsNull) 
+                       if (x.IsNull)
                                return Null;
                        else 
-                               return new SqlSingle((float)x.Value);
+                               return new SqlSingle((float) x.Value);
                }
 
                public static implicit operator SqlSingle (SqlDecimal x)
                {
-                       if (x.IsNull) 
+                       if (x.IsNull)
                                return Null;
                        else
-                               return new SqlSingle((float)x.Value);
+                               return new SqlSingle((float) x.Value);
                }
 
                public static implicit operator SqlSingle (SqlInt16 x)
                {
-                       if (x.IsNull) 
+                       if (x.IsNull)
                                return Null;
                        else
-                               return new SqlSingle((float)x.Value);
+                               return new SqlSingle((float) x.Value);
                }
 
                public static implicit operator SqlSingle (SqlInt32 x)
                {
-                       if (x.IsNull) 
+                       if (x.IsNull)
                                return Null;
                        else
-                               return new SqlSingle((float)x.Value);
+                               return new SqlSingle((float) x.Value);
                }
 
                public static implicit operator SqlSingle (SqlInt64 x)
                {
-                       if (x.IsNull) 
+                       if (x.IsNull)
                                return Null;
                        else
-                               return new SqlSingle((float)x.Value);
+                               return new SqlSingle((float) x.Value);
                }
 
                public static implicit operator SqlSingle (SqlMoney x)
                {
-                       if (x.IsNull) 
+                       if (x.IsNull)
                                return Null;
                        else
-                               return new SqlSingle((float)x.Value);
+                               return new SqlSingle((float) x.Value);
+               }
+
+#if NET_2_0
+               public static XmlQualifiedName GetXsdType (XmlSchemaSet schemaSet)
+               {
+                       XmlQualifiedName qualifiedName = new XmlQualifiedName ("float", "http://www.w3.org/2001/XMLSchema");
+                       return qualifiedName;
+               }
+
+               [MonoTODO]
+               XmlSchema IXmlSerializable.GetSchema ()
+               {
+                       throw new NotImplementedException ();
+               }
+               
+               [MonoTODO]
+               void IXmlSerializable.ReadXml (XmlReader reader)
+               {
+                       throw new NotImplementedException ();
                }
+               
+               [MonoTODO]
+               void IXmlSerializable.WriteXml (XmlWriter writer)
+               {
+                       throw new NotImplementedException ();
+               }
+#endif
 
                #endregion
        }
 }
-