Date: Friday, March 10, 2006 @ 18:47:33
  Author: gilles
    Path: /cvsroot/carob/carob

Modified: include/BigDecimal.hpp (1.16 -> 1.17) src/BigDecimal.cpp (1.20
          -> 1.21)

Added == operator for comparisons
Added ostream << friend operator for serialization needs (see 
ParameterStatement class)


------------------------+
 include/BigDecimal.hpp |   20 ++++++++++++++++----
 src/BigDecimal.cpp     |   25 ++++++++++++++++---------
 2 files changed, 32 insertions(+), 13 deletions(-)


Index: carob/include/BigDecimal.hpp
diff -u carob/include/BigDecimal.hpp:1.16 carob/include/BigDecimal.hpp:1.17
--- carob/include/BigDecimal.hpp:1.16   Thu Mar  9 10:46:04 2006
+++ carob/include/BigDecimal.hpp        Fri Mar 10 18:47:33 2006
@@ -27,6 +27,7 @@
 
 #include <gmpxx.h>
 #include <string>
+#include <sstream>
 
 namespace CarobNS {
 
@@ -50,15 +51,21 @@
   /**
    * Empty constructor.
    * Sets fields to default values. This big decimal becomes zero (0 scale 
-   * and 0 intVal)
+   * and 0 unscaled_value)
    */
   BigDecimal();
   /**
-   * Frees intVal if applicable
-   */
-  virtual ~BigDecimal();
   
   /**
+   * Compares scale, sign and unscaled_value
+   */
+  bool operator == (const BigDecimal&);
+  /**
+   * BigDecimal display or serialization as a string
+   */
+  friend std::basic_ostream<wchar_t>& operator << 
(std::basic_ostream<wchar_t>& os, 
+      const BigDecimal &bd)  { return os<<(static_cast<std::wstring>(bd)); }
+  /**
    * Constructor to deserialize a BigDecimal from a stream.
    * @param input socket from which to deserializer Big Decimal
    * @throws SocketIOException if an error occurs on the stream
@@ -66,6 +73,11 @@
   BigDecimal::BigDecimal(const DriverSocket& input)
       throw (SocketIOException, UnexpectedException);
   /**
+   * Frees intVal if applicable
+   */
+  virtual ~BigDecimal();
+
+  /**
    * Convertion to string.
    * A leading minus sign is used to indicate sign, and the number of digits to
    * the right of the decimal point is used to indicate scale.
Index: carob/src/BigDecimal.cpp
diff -u carob/src/BigDecimal.cpp:1.20 carob/src/BigDecimal.cpp:1.21
--- carob/src/BigDecimal.cpp:1.20       Thu Mar  9 10:46:04 2006
+++ carob/src/BigDecimal.cpp    Fri Mar 10 18:47:33 2006
@@ -40,15 +40,6 @@
   scale = 0;
   signum = 0;
 }
-
-BigDecimal::~BigDecimal()
-{
-  if (byteArrayLength > 0 && byteArray != NULL)
-  {
-    delete[] byteArray;
-  }
-}
-
 BigDecimal::BigDecimal(const DriverSocket& input)
     throw (SocketIOException, UnexpectedException) : unscaled_value(0)
 {
@@ -118,6 +109,22 @@
   // TODO: if ODBC/odbsequoia doesn't need the byte array, we should
   // delete and throw away the byte array now.
 }
+
+BigDecimal::~BigDecimal()
+{
+  if (byteArrayLength > 0 && byteArray != NULL)
+  {
+    delete[] byteArray;
+  }
+}
+
+bool BigDecimal::operator == (const BigDecimal& ref)
+{
+  return (signum == ref.signum
+      && scale == ref.scale
+      && mpz_cmp(unscaled_value.get_mpz_t(), ref.unscaled_value.get_mpz_t()) 
== 0);
+}
+
 mpz_class BigDecimal::toBigInteger() const
 {
   if (scale == 0)

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to