diff --git a/latan/Global.cpp b/latan/Global.cpp index 61475df..5830846 100644 --- a/latan/Global.cpp +++ b/latan/Global.cpp @@ -26,3 +26,21 @@ using namespace Latan; const string Env::fullName = PACKAGE_STRING; const string Env::name = PACKAGE_NAME; const string Env::version = PACKAGE_VERSION; + +template <> +float Latan::strTo(const string &str) +{ + return strtof(str.c_str(), (char **)NULL); +} + +template <> +double Latan::strTo(const string &str) +{ + return strtod(str.c_str(), (char **)NULL); +} + +template <> +int Latan::strTo(const string &str) +{ + return (int)(strtol(str.c_str(), (char **)NULL, 10)); +} diff --git a/latan/Global.hpp b/latan/Global.hpp index 6f17898..44d1b13 100644 --- a/latan/Global.hpp +++ b/latan/Global.hpp @@ -49,7 +49,7 @@ namespace Env // string conversions template -T strTo(std::string str) +T strTo(const std::string &str) { T buf; std::istringstream stream(str); @@ -59,8 +59,16 @@ T strTo(std::string str) return buf; } +//// optimized specializations +template <> +float strTo(const std::string &str); +template <> +double strTo(const std::string &str); +template <> +int strTo(const std::string &str); + template -std::string strFrom(T x) +std::string strFrom(const T x) { std::ostringstream stream;