Date: Thursday, December 15, 2005 @ 12:25:53
Author: gilles
Path: /cvsroot/carob/carob
Modified: include/Common.hpp (1.17 -> 1.18) src/Common.cpp (1.12 -> 1.13)
Removed unnecessary 'extern' keyword for functions
Added wstringToA function that converts wstrings to a given numeric type (int,
float,...) with the given base
--------------------+
include/Common.hpp | 38 +++++++++++++++++++++++---------------
src/Common.cpp | 11 +++++++++++
2 files changed, 34 insertions(+), 15 deletions(-)
Index: carob/include/Common.hpp
diff -u carob/include/Common.hpp:1.17 carob/include/Common.hpp:1.18
--- carob/include/Common.hpp:1.17 Tue Dec 13 16:08:30 2005
+++ carob/include/Common.hpp Thu Dec 15 12:25:53 2005
@@ -65,44 +65,44 @@
extern LogLevel currentLogLevel;
/** Sets the log level to l */
-extern void setLogLevel(const LogLevel l);
+void setLogLevel(const LogLevel l);
/**
* Writes a log message with 'Verbose' level.
* Use isVerboseEnabled() to determine if the message should
* be printed
*/
-extern void logVerbose(const std::wstring, const std::wstring);
+void logVerbose(const std::wstring, const std::wstring);
/**
* Writes a log message with 'Info' level.
* Use isInfoEnabled() to determine if the message should be printed
*/
-extern void logInfo(const std::wstring, const std::wstring);
+void logInfo(const std::wstring, const std::wstring);
/**
* Writes a log message with 'Debug' level.
* Use isDebugEnabled() to determine if the message should be printed
*/
-extern void logDebug(const std::wstring, const std::wstring);
+void logDebug(const std::wstring, const std::wstring);
/**
* Writes a log message with 'Warning' level.
* Use isWarningEnabled() to determine if the message should be printed
*/
-extern void logWarning(const std::wstring, const std::wstring);
+void logWarning(const std::wstring, const std::wstring);
/**
* Writes a log message with 'Error' level.
* Use isErrorEnabled() to determine if the message should be printed
*/
-extern void logError(const std::wstring, const std::wstring);
+void logError(const std::wstring, const std::wstring);
/** Returns true if the verbose level or higher is enabled */
-extern bool isVerboseEnabled();
+bool isVerboseEnabled();
/** Returns true if the info level or higher is enabled */
-extern bool isInfoEnabled();
+bool isInfoEnabled();
/** Returns true if the debug level or higher is enabled */
-extern bool isDebugEnabled();
+bool isDebugEnabled();
/** Returns true if the warning level or higher is enabled */
-extern bool isWarningEnabled();
+bool isWarningEnabled();
/** Returns true if the error level or higher is enabled */
-extern bool isErrorEnabled();
+bool isErrorEnabled();
/**
* Removes given whitespaces from the begining and end of the given string
@@ -110,7 +110,7 @@
* @param delims string representing the whitespaces to remove
* @return copy of the input string without whitespaces and begining nor end
*/
-extern std::wstring trim(const std::wstring& source,
+std::wstring trim(const std::wstring& source,
const wchar_t* delims = L" \t\r\n");
/**
* Default (locale) String to Wide-String conversion.
@@ -118,20 +118,28 @@
* @param in original string
* @return converted wstring
*/
-extern std::wstring fromString(const std::string& in);
+std::wstring fromString(const std::string& in);
/**
* Wide-String to default (locale) String conversion.
* FIXME: throw exception on error
* @param in original wide string
* @return converted string
*/
-extern std::string toString(const std::wstring& in);
+std::string toString(const std::wstring& in);
/**
* Converts integers to wstring
* @param i integer to convert
* @return a wstring representation of the integer
*/
-extern std::wstring toWString(const int& i);
+std::wstring toWString(const int& i);
+
+/**
+ * Converts a wstring to any given type in the given base.
+ * Function found at http://www.codeguru.com/forum/showthread.php?t=231054
+ * @return true if the conversion succeeded, false otherwise
+ */
+template <class T> bool wstringToA(T& t, const std::wstring& s,
+ std::ios_base& (*f)(std::ios_base&));
/**
* Defines data type that can be found in ResultSets
Index: carob/src/Common.cpp
diff -u carob/src/Common.cpp:1.12 carob/src/Common.cpp:1.13
--- carob/src/Common.cpp:1.12 Wed Dec 14 17:47:52 2005
+++ carob/src/Common.cpp Thu Dec 15 12:25:53 2005
@@ -162,3 +162,14 @@
buffer << arg;
return buffer.str();
}
+
+template <class T> bool CarobNS::wstringToA(T& t, const std::wstring& s,
+ std::ios_base& (*f)(std::ios_base&))
+{
+ std::wistringstream iss(s);
+ return !(iss >> f >> t).fail();
+}
+// Explicit instanciation for types actually used
+// More info here: http://www.codeproject.com/cpp/templatesourceorg.asp
+template bool CarobNS::wstringToA<int>(int&, const std::wstring&,
+ std::ios_base& (*f)(std::ios_base&));
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits