Date: Monday, March 6, 2006 @ 13:43:23
Author: gilles
Path: /cvsroot/carob/carob
Modified: include/Common.hpp (1.32 -> 1.33) src/Common.cpp (1.26 -> 1.27)
src/Connection.cpp (1.72 -> 1.73) src/ParameterStatement.cpp
(1.24 -> 1.25)
Generalized toWString(int) functio to any type using templates
Had to add explicit static_casts (which is a good thing) when calling with
TypeTag and ConnectionPolicy numbers
----------------------------+
include/Common.hpp | 4 ++--
src/Common.cpp | 16 +++++++++++++---
src/Connection.cpp | 5 +++--
src/ParameterStatement.cpp | 2 ++
4 files changed, 20 insertions(+), 7 deletions(-)
Index: carob/include/Common.hpp
diff -u carob/include/Common.hpp:1.32 carob/include/Common.hpp:1.33
--- carob/include/Common.hpp:1.32 Tue Feb 14 18:35:48 2006
+++ carob/include/Common.hpp Mon Mar 6 13:43:23 2006
@@ -118,11 +118,11 @@
/**
- * Converts integers to wstring
+ * Converts any type to wstring
* @param i integer to convert
* @return a wstring representation of the integer
*/
-std::wstring toWString(const int& i);
+template <class T> std::wstring toWString(const T& t);
/**
* Converts the given wstring to any given type.
Index: carob/src/Common.cpp
diff -u carob/src/Common.cpp:1.26 carob/src/Common.cpp:1.27
--- carob/src/Common.cpp:1.26 Tue Feb 28 11:59:54 2006
+++ carob/src/Common.cpp Mon Mar 6 13:43:23 2006
@@ -185,13 +185,23 @@
const CarobNS::MBSCodec
CarobNS::StaticCodecs::utf8_codec(trylocale(NAME_OF_ANY_UTF8_LOCALE_AVAILABLE));
const CarobNS::MBSCodec CarobNS::StaticCodecs::user_codec;
-
-wstring CarobNS::toWString(const int& arg)
+//Can this be factorized with ParameterStatement ?
+template <class T> wstring CarobNS::toWString(const T& t)
{
std::wostringstream buffer;
- buffer << arg;
+ buffer << t;
return buffer.str();
}
+// Explicit instantiation for types actually used
+// More info here: http://www.codeproject.com/cpp/templatesourceorg.asp
+template wstring CarobNS::toWString<uint16_t>(const uint16_t&);
+template wstring CarobNS::toWString<int16_t>(const int16_t&);
+template wstring CarobNS::toWString<uint32_t>(const uint32_t&);
+template wstring CarobNS::toWString<int64_t>(const int64_t&);
+template wstring CarobNS::toWString<int>(const int&);
+template wstring CarobNS::toWString<long>(const long&);
+template wstring CarobNS::toWString<float>(const float&);
+template wstring CarobNS::toWString<double>(const double&);
template <class T> bool CarobNS::wstringTo(T& t, const std::wstring& s)
{
Index: carob/src/Connection.cpp
diff -u carob/src/Connection.cpp:1.72 carob/src/Connection.cpp:1.73
--- carob/src/Connection.cpp:1.72 Fri Mar 3 16:23:32 2006
+++ carob/src/Connection.cpp Mon Mar 6 13:43:23 2006
@@ -80,7 +80,8 @@
parameters.getRetryInterval());
break;
default:
- throw DriverException(L"Unsupported connection policy #" +
toWString(parameters.getConnectPolicy()));
+ throw DriverException(L"Unsupported connection policy #"
+ + toWString(static_cast<int>(parameters.getConnectPolicy())));
}
persistent_connection = parameters.getPersistentConnection();
for (int connectRetry = 0; connectRetry<CONNECT_RETRIES; connectRetry++)
@@ -974,7 +975,7 @@
receiveException();
throw ProtocolException(L"Expected a resultset, received unexpected tag: "
- + toWString(tag));
+ + toWString(static_cast<int>(tag)));
//just to avoid compiler warnings
return NULL;
}
Index: carob/src/ParameterStatement.cpp
diff -u carob/src/ParameterStatement.cpp:1.24
carob/src/ParameterStatement.cpp:1.25
--- carob/src/ParameterStatement.cpp:1.24 Thu Mar 2 16:01:36 2006
+++ carob/src/ParameterStatement.cpp Mon Mar 6 13:43:23 2006
@@ -177,6 +177,8 @@
///// Template & specialized filters /////
+//This code is very similar to Common.cpp toWString(<>) => factorize ?
+
namespace CarobNS {
using std::basic_ostream;
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits