Date: Wednesday, July 26, 2006 @ 17:11:57
  Author: gilles
    Path: /cvsroot/carob/carob

Modified: include/BigDecimal.hpp (1.24 -> 1.25) include/ControllerPool.hpp
          (1.1 -> 1.2) include/DriverResultSet.hpp (1.43 -> 1.44)
          src/Common.cpp (1.41 -> 1.42) src/DriverResultSet.cpp (1.57 ->
          1.58) test/30-ResultSet/TestBigDecimal.cpp (1.9 -> 1.10)

Added locale parameter in DriverResultSet::getAsString, default to user's 
current locale, so the conversions can follow given locale rules
Put BigDecimal::toString(decimal_separator) function as public in order to call 
it from getAsString
Fixed big decimal test to use the new getAsString with C locale (makes test 
pass again!)
Various javadoc fixes


--------------------------------------+
 include/BigDecimal.hpp               |   26 ++++++------
 include/ControllerPool.hpp           |    8 +++
 include/DriverResultSet.hpp          |   15 ++++---
 src/Common.cpp                       |    2 
 src/DriverResultSet.cpp              |    8 ++-
 test/30-ResultSet/TestBigDecimal.cpp |   68 ++++++++++++++++-----------------
 6 files changed, 70 insertions(+), 57 deletions(-)


Index: carob/include/BigDecimal.hpp
diff -u carob/include/BigDecimal.hpp:1.24 carob/include/BigDecimal.hpp:1.25
--- carob/include/BigDecimal.hpp:1.24   Wed May 24 08:22:05 2006
+++ carob/include/BigDecimal.hpp        Wed Jul 26 17:11:57 2006
@@ -135,34 +135,40 @@
   virtual ~BigDecimal();
 
   /**
-   * Convertion to string in the user defined locale (for decimal separator)
+   * Conversion to string in the user defined locale (for decimal separator)
    * 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.
    */ 
   operator std::wstring() const;
   /**
-   * Convertion to int.
+   * Conversion to string with the given decimal point
+   * 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.
+   */ 
+  std::wstring  toString(const wchar_t) const;
+  /**
+   * Conversion to int.
    * Any fractional part of this BigDecimal will be discarded, and if the
    * resulting "BigInteger" is too big to fit in an int, throws an exception
    * @throw ConversionException if the value is to big to be converted
    */ 
   operator int() const throw (ConversionException);
   /**
-   * Convertion to long.
+   * Conversion to long.
    * Any fractional part of this BigDecimal will be discarded, and if the
    * resulting "BigInteger" is too big to fit in a long, throws an exception
    * @throw ConversionException if the value is to big to be converted
    */ 
   operator long() const throw (ConversionException);
   /**
-   * Convertion to int64_t
+   * Conversion to int64_t
    * Any fractional part of this BigDecimal will be discarded, and if the
    * resulting "BigInteger" is too big to fit in a int64_t, throws an exception
    * @throw ConversionException if the value is to big to be converted
    */ 
   operator int64_t() const throw (ConversionException);
   /**
-   * Convertion to uint64_t
+   * Conversion to uint64_t
    * Any fractional part of this BigDecimal will be discarded, and if the
    * resulting "BigInteger" is too big to fit in an uint64_t, throws an
    * exception
@@ -170,13 +176,13 @@
    */ 
   operator uint64_t() const throw (ConversionException);
   /**
-   * Convertion to float
+   * Conversion to float
    * TODO: exact behavior description
    * @throw ConversionException if the value is to big to be converted
    */ 
   operator float() const throw (ConversionException);
   /**
-   * Convertion to double
+   * Conversion to double
    * TODO: exact behavior description
    * @throw ConversionException if the value is to big to be converted
    */ 
@@ -216,12 +222,6 @@
    * @param intArrayLength size of the returned array
    */
   int*          toIntArray(mpz_t scaled_val, int* intArrayLength) const;
-  /**
-   * Convertion to string with the given decimal point
-   * 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.
-   */ 
-  std::wstring  toString(const wchar_t) const;
 private:
   /** Length of the unscaled value java_byte-array */
   size_t        byteArrayLength;
Index: carob/include/ControllerPool.hpp
diff -u carob/include/ControllerPool.hpp:1.1 
carob/include/ControllerPool.hpp:1.2
--- carob/include/ControllerPool.hpp:1.1        Wed Jul 26 16:31:47 2006
+++ carob/include/ControllerPool.hpp    Wed Jul 26 17:11:57 2006
@@ -140,6 +140,7 @@
   /** mutex on suspected controllers */
   static CriticalSection      suspected_controllers_CS;
 private:
+  /** references counter managed by controller pool manager */
   int                         ref_counter;
 };
 
@@ -165,9 +166,14 @@
   ControllerInfo              getController() throw (NoMoreControllerException,
                                   UnexpectedException);
 private:
+  /** index of last controller given by getController */ 
   int                         index;
 };
 
+/**
+ * Utility struct for controller list / controller pool association (see
+ * controller pool manager
+ */
 typedef struct
 {
   std::vector<ControllerInfo> controllers;
@@ -236,7 +242,9 @@
   static void                     freePool(AbstractControllerPool* pool);
 protected:
 private:
+  /** To manage pool map concurrent accesses */
   static CriticalSection          pool_map_CS;
+  /** The map that associates controller lists to pools */
   static std::map<PoolIndex, AbstractControllerPool*, ltPoolIndex>  pool_map;
 };
 
Index: carob/include/DriverResultSet.hpp
diff -u carob/include/DriverResultSet.hpp:1.43 
carob/include/DriverResultSet.hpp:1.44
--- carob/include/DriverResultSet.hpp:1.43      Wed Jul  5 09:26:05 2006
+++ carob/include/DriverResultSet.hpp   Wed Jul 26 17:11:57 2006
@@ -26,6 +26,7 @@
 #include "CarobException.hpp"
 
 #include <vector>
+#include <locale>
 
 namespace CarobNS {
 
@@ -166,19 +167,21 @@
                                   NullValueException, NotImplementedException,
                                   UnexpectedException);
   /**
-   * Tries to get the value of a column in the current row as a wstring. If the
-   * value at the given row/col is not of type string, tries to convert it 
using
-   * STL std::wostringstream conversion functions
+   * Tries to get the value of a column in the current row as a wstring with 
the
+   * given locale. If the value at the given row/col is not of type string,
+   * tries to convert it using STL std::wostringstream conversion functions
    * 
    * @param columnIndex the first column is 1, the second is 2...
+   * @param loc (optional) the locale to be used for string conversions. 
Ignored
+   *            if the column is of type STRING
    * @return the column value, null for SQL NULL
    * @throw DriverException if the ResultSet is closed or the cursor is
    *            out of bounds
    * @throw NullValueException if the retrieved value is NULL
    */
-  std::wstring                getAsString(int columnIndex) throw 
(DriverException,
-                                  NullValueException, NotImplementedException,
-                                  UnexpectedException);
+  std::wstring                getAsString(int columnIndex, std::locale loc = 
std::locale(""))
+                                  throw (DriverException, NullValueException,
+                                  NotImplementedException, 
UnexpectedException);
   /**
    * Gets the 32bits integer value of a column in the current row only if the
    * given column is of int type, throws an exception otherwise. To get the
Index: carob/src/Common.cpp
diff -u carob/src/Common.cpp:1.41 carob/src/Common.cpp:1.42
--- carob/src/Common.cpp:1.41   Wed Jul 26 16:31:47 2006
+++ carob/src/Common.cpp        Wed Jul 26 17:11:57 2006
@@ -44,7 +44,7 @@
 #include <iostream>
 #include <sstream> //for wostringstream
 #include <stdexcept>
-
+#include <locale>
 
 CarobNS::LogLevel CarobNS::currentLogLevel = LOG_LEVEL_WARN;
 
Index: carob/src/DriverResultSet.cpp
diff -u carob/src/DriverResultSet.cpp:1.57 carob/src/DriverResultSet.cpp:1.58
--- carob/src/DriverResultSet.cpp:1.57  Wed Jul  5 09:26:05 2006
+++ carob/src/DriverResultSet.cpp       Wed Jul 26 17:11:57 2006
@@ -265,8 +265,9 @@
   return (*(static_cast<wstring*>((data[currentRow][columnIndex - 
1].as_other))));
 }
 
-wstring DriverResultSet::getAsString(int columnIndex) throw (DriverException,
-    NullValueException, NotImplementedException, UnexpectedException)
+wstring DriverResultSet::getAsString(int columnIndex, std::locale 
loc/*=std::locale("")*/)
+    throw (DriverException, NullValueException, NotImplementedException,
+    UnexpectedException)
 {
   checkRowAndColPosAndSetNullFlag(columnIndex);
   if (wasNullFlag)
@@ -276,6 +277,7 @@
   }
 
   std::wostringstream buffer;
+  buffer.imbue(loc);
 
   // big switch on column data type
   switch (columnTypeTags[columnIndex - 1])
@@ -286,7 +288,7 @@
     case TT_BIGDECIMAL:
     {
       BigDecimal* bd = (static_cast<BigDecimal*>((data[currentRow][columnIndex 
- 1].as_other)));
-      buffer << static_cast<wstring>(*bd);
+      buffer << bd->toString(std::use_facet< std::numpunct<wchar_t> 
>(loc).decimal_point());
       break;
     }
     case TT_BOOLEAN:
Index: carob/test/30-ResultSet/TestBigDecimal.cpp
diff -u carob/test/30-ResultSet/TestBigDecimal.cpp:1.9 
carob/test/30-ResultSet/TestBigDecimal.cpp:1.10
--- carob/test/30-ResultSet/TestBigDecimal.cpp:1.9      Wed Jul 26 16:31:47 2006
+++ carob/test/30-ResultSet/TestBigDecimal.cpp  Wed Jul 26 17:11:57 2006
@@ -112,56 +112,56 @@
   statementPtr = connectionPtr->createStatement();
   DriverResultSet* drsPtr = statementPtr->executeQuery(L"SELECT * FROM 
product");
   drsPtr->next();
-  logInfo(fctName, L"0 - getAsString=" + drsPtr->getAsString(3));
-  CPPUNIT_ASSERT(drsPtr->getAsString(3) == L"0");
+  logInfo(fctName, L"0 - getAsString=" + drsPtr->getAsString(3, 
std::locale::classic()));
+  CPPUNIT_ASSERT(drsPtr->getAsString(3, std::locale::classic()) == L"0");
   drsPtr->next();
-  logInfo(fctName, L"-0.5 - getAsString=" + drsPtr->getAsString(3));
-  CPPUNIT_ASSERT(drsPtr->getAsString(3) == toWString(-0.5));
+  logInfo(fctName, L"-0.5 - getAsString=" + drsPtr->getAsString(3, 
std::locale::classic()));
+  CPPUNIT_ASSERT(drsPtr->getAsString(3, std::locale::classic()) == 
toWString(-0.5));
   drsPtr->next();
-  logInfo(fctName, L"0.5 - getAsString=" + drsPtr->getAsString(3));
-  CPPUNIT_ASSERT(drsPtr->getAsString(3) == toWString(0.5));
+  logInfo(fctName, L"0.5 - getAsString=" + drsPtr->getAsString(3, 
std::locale::classic()));
+  CPPUNIT_ASSERT(drsPtr->getAsString(3, std::locale::classic()) == 
toWString(0.5));
   drsPtr->next();
-  logInfo(fctName, L"-1 - getAsString=" + drsPtr->getAsString(3));
-  CPPUNIT_ASSERT(drsPtr->getAsString(3) == L"-1");
+  logInfo(fctName, L"-1 - getAsString=" + drsPtr->getAsString(3, 
std::locale::classic()));
+  CPPUNIT_ASSERT(drsPtr->getAsString(3, std::locale::classic()) == L"-1");
   drsPtr->next();
-  logInfo(fctName, L"1 - getAsString=" + drsPtr->getAsString(3));
-  CPPUNIT_ASSERT(drsPtr->getAsString(3) == L"1");
+  logInfo(fctName, L"1 - getAsString=" + drsPtr->getAsString(3, 
std::locale::classic()));
+  CPPUNIT_ASSERT(drsPtr->getAsString(3, std::locale::classic()) == L"1");
   drsPtr->next();
-  logInfo(fctName, toWString(-12.34) + L" - getAsString=" + 
drsPtr->getAsString(3));
-  CPPUNIT_ASSERT(drsPtr->getAsString(3) == toWString(-12.34));
+  logInfo(fctName, toWString(-12.34) + L" - getAsString=" + 
drsPtr->getAsString(3, std::locale::classic()));
+  CPPUNIT_ASSERT(drsPtr->getAsString(3, std::locale::classic()) == 
toWString(-12.34));
   drsPtr->next();
-  logInfo(fctName, toWString(12.34) + L" - getAsString=" + 
drsPtr->getAsString(3));
-  CPPUNIT_ASSERT(drsPtr->getAsString(3) == toWString(12.34));
+  logInfo(fctName, toWString(12.34) + L" - getAsString=" + 
drsPtr->getAsString(3, std::locale::classic()));
+  CPPUNIT_ASSERT(drsPtr->getAsString(3, std::locale::classic()) == 
toWString(12.34));
   drsPtr->next();
-  logInfo(fctName, toWString(numeric_limits<int>::min()) + L" - getAsString=" 
+ drsPtr->getAsString(3));
-  CPPUNIT_ASSERT(drsPtr->getAsString(3) == 
toWString(numeric_limits<int>::min()));
+  logInfo(fctName, toWString(numeric_limits<int>::min()) + L" - getAsString=" 
+ drsPtr->getAsString(3, std::locale::classic()));
+  CPPUNIT_ASSERT(drsPtr->getAsString(3, std::locale::classic()) == 
toWString(numeric_limits<int>::min()));
   drsPtr->next();
-  logInfo(fctName, toWString(numeric_limits<int>::max()) + L" - getAsString=" 
+ drsPtr->getAsString(3));
-  CPPUNIT_ASSERT(drsPtr->getAsString(3) == 
toWString(numeric_limits<int>::max()));
+  logInfo(fctName, toWString(numeric_limits<int>::max()) + L" - getAsString=" 
+ drsPtr->getAsString(3, std::locale::classic()));
+  CPPUNIT_ASSERT(drsPtr->getAsString(3, std::locale::classic()) == 
toWString(numeric_limits<int>::max()));
   drsPtr->next();
-  logInfo(fctName, toWString(numeric_limits<long long>::min()) + L" - 
getAsString=" + drsPtr->getAsString(3));
-  CPPUNIT_ASSERT(drsPtr->getAsString(3) == toWString(numeric_limits<long 
long>::min()));
+  logInfo(fctName, toWString(numeric_limits<long long>::min()) + L" - 
getAsString=" + drsPtr->getAsString(3, std::locale::classic()));
+  CPPUNIT_ASSERT(drsPtr->getAsString(3, std::locale::classic()) == 
toWString(numeric_limits<long long>::min()));
   drsPtr->next();
-  logInfo(fctName, toWString(numeric_limits<long long>::max()) + L" - 
getAsString=" + drsPtr->getAsString(3));
-  CPPUNIT_ASSERT(drsPtr->getAsString(3) == toWString(numeric_limits<long 
long>::max()));
+  logInfo(fctName, toWString(numeric_limits<long long>::max()) + L" - 
getAsString=" + drsPtr->getAsString(3, std::locale::classic()));
+  CPPUNIT_ASSERT(drsPtr->getAsString(3, std::locale::classic()) == 
toWString(numeric_limits<long long>::max()));
   drsPtr->next();
-//  logInfo(fctName, toWString(numeric_limits<float>::min()) + L" - 
getAsString=" + drsPtr->getAsString(3));
-//  CPPUNIT_ASSERT(drsPtr->getAsString(3) == 
toWString(numeric_limits<float>::min()));
+//  logInfo(fctName, toWString(numeric_limits<float>::min()) + L" - 
getAsString=" + drsPtr->getAsString(3, std::locale::classic()));
+//  CPPUNIT_ASSERT(drsPtr->getAsString(3, std::locale::classic()) == 
toWString(numeric_limits<float>::min()));
   drsPtr->next();
-//  logInfo(fctName, toWString(numeric_limits<float>::max()) + L" - 
getAsString=" + drsPtr->getAsString(3));
-//  CPPUNIT_ASSERT(drsPtr->getAsString(3) == 
toWString(numeric_limits<float>::max()));
+//  logInfo(fctName, toWString(numeric_limits<float>::max()) + L" - 
getAsString=" + drsPtr->getAsString(3, std::locale::classic()));
+//  CPPUNIT_ASSERT(drsPtr->getAsString(3, std::locale::classic()) == 
toWString(numeric_limits<float>::max()));
   drsPtr->next();
-//  logInfo(fctName, toWString(numeric_limits<double>::min()) + L" - 
getAsString=" + drsPtr->getAsString(3));
-//  CPPUNIT_ASSERT(drsPtr->getAsString(3) == 
toWString(numeric_limits<double>::min()));
+//  logInfo(fctName, toWString(numeric_limits<double>::min()) + L" - 
getAsString=" + drsPtr->getAsString(3, std::locale::classic()));
+//  CPPUNIT_ASSERT(drsPtr->getAsString(3, std::locale::classic()) == 
toWString(numeric_limits<double>::min()));
   drsPtr->next();
-//  logInfo(fctName, toWString(numeric_limits<double>::max()) + L" - 
getAsString=" + drsPtr->getAsString(3));
-//  CPPUNIT_ASSERT(drsPtr->getAsString(3) == 
toWString(numeric_limits<double>::max()));
+//  logInfo(fctName, toWString(numeric_limits<double>::max()) + L" - 
getAsString=" + drsPtr->getAsString(3, std::locale::classic()));
+//  CPPUNIT_ASSERT(drsPtr->getAsString(3, std::locale::classic()) == 
toWString(numeric_limits<double>::max()));
   drsPtr->next();
-  logInfo(fctName, wstring(L"-123456789012345678901234567890") + 
userDecimalPoint + L"123456789012345678901234567890 - getAsString=" + 
drsPtr->getAsString(3));
-  CPPUNIT_ASSERT(drsPtr->getAsString(3) == 
wstring(L"-123456789012345678901234567890") + userDecimalPoint + 
L"123456789012345678901234567890");
+  logInfo(fctName, 
wstring(L"-123456789012345678901234567890.123456789012345678901234567890 - 
getAsString=") + drsPtr->getAsString(3, std::locale::classic()));
+  CPPUNIT_ASSERT(drsPtr->getAsString(3, std::locale::classic()) == 
wstring(L"-123456789012345678901234567890.123456789012345678901234567890"));
   drsPtr->next();
-  logInfo(fctName, wstring(L"123456789012345678901234567890") + 
userDecimalPoint + L"123456789012345678901234567890 - getAsString=" + 
drsPtr->getAsString(3));
-  CPPUNIT_ASSERT(drsPtr->getAsString(3) == 
wstring(L"123456789012345678901234567890") + userDecimalPoint + 
L"123456789012345678901234567890");
+  logInfo(fctName, 
wstring(L"123456789012345678901234567890.123456789012345678901234567890 - 
getAsString=") + drsPtr->getAsString(3, std::locale::classic()));
+  CPPUNIT_ASSERT(drsPtr->getAsString(3, std::locale::classic()) == 
wstring(L"123456789012345678901234567890.123456789012345678901234567890"));
 
 }
 //TODO: display as strings (when logging) in order to see where the test 
crashes

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

Reply via email to