Date: Tuesday, November 28, 2006 @ 16:54:20
Author: gilles
Path: /cvsroot/carob/carob
Modified: include/Common.hpp (1.47 -> 1.48) src/Common.cpp (1.46 -> 1.47)
Preparing CAROB-110 fix:
Added getCurrentTimeInMs() function that gives the number of milliseconds since
Epoch. This uses gettimeofday()
Added wstring<>java_byte conversion implem
--------------------+
include/Common.hpp | 7 +++++++
src/Common.cpp | 15 +++++++++++++++
2 files changed, 22 insertions(+)
Index: carob/include/Common.hpp
diff -u carob/include/Common.hpp:1.47 carob/include/Common.hpp:1.48
--- carob/include/Common.hpp:1.47 Thu Oct 19 15:23:37 2006
+++ carob/include/Common.hpp Tue Nov 28 16:54:20 2006
@@ -180,6 +180,7 @@
* Converts any type to wstring using C locale (locale independant). To be used
* for internal conversions
* Implemented so far:
+ * java_byte
* char
* wchar_t
* uint16_t
@@ -199,6 +200,7 @@
* Converts any type to wstring using user current locale (ie. std::locale()).
* To be used for user-oriented info (logs, exception)
* Implemented so far:
+ * java_byte
* char
* wchar_t
* int16_t
@@ -245,6 +247,11 @@
*/
std::wstring replaceAll(std::wstring src, const std::wstring &from, const
std::wstring &to);
+/**
+ * Utility to get the current time as number of ms since Epoch
+ */
+long getCurrentTimeInMs();
+
} //namespace CarobNS
#endif //_COMMON_H_
Index: carob/src/Common.cpp
diff -u carob/src/Common.cpp:1.46 carob/src/Common.cpp:1.47
--- carob/src/Common.cpp:1.46 Tue Nov 21 18:38:44 2006
+++ carob/src/Common.cpp Tue Nov 28 16:54:20 2006
@@ -41,6 +41,7 @@
// - "Incompatibilities Between ISO C and ISO C++" - David R. Tribble
// - C++ Technical Report 1 (TR1)
#endif
+#include <sys/time.h> // for gettimeofday()
#include <iostream>
#include <sstream> //for wostringstream
#include <stdexcept>
@@ -329,6 +330,7 @@
}
// Explicit instantiation for types actually used
// Don't forget to update javadoc when changing this
+template wstring CarobNS::toWString<java_byte>(const java_byte&);
template wstring CarobNS::toWString<char>(const char&);
template wstring CarobNS::toWString<wchar_t>(const wchar_t&);
template wstring CarobNS::toWString<int16_t>(const int16_t&);
@@ -350,6 +352,7 @@
return buffer.str();
}
+template wstring CarobNS::toUserString<java_byte>(const java_byte&);
template wstring CarobNS::toUserString<char>(const char&);
template wstring CarobNS::toUserString<wchar_t>(const wchar_t&);
template wstring CarobNS::toUserString<int16_t>(const int16_t&);
@@ -385,6 +388,18 @@
return src;
}
+long CarobNS::getCurrentTimeInMs()
+{
+ struct timeval now;
+ struct timezone ignored;
+ if (gettimeofday(&now, &ignored) != 0)
+ {
+ if (isErrorEnabled())
+ logError(L"getCurrentTimeInMs", L"gettimeofday failed!");
+ }
+ return now.tv_sec*1000 + now.tv_usec/1000;
+}
+
/*
* Local Variables:
* c-file-style: "bsd"
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits