1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-14 01:45:35 +00:00

inline string conversions and runtime type test

This commit is contained in:
Antonin Portelli 2014-02-18 18:09:41 +00:00
parent 364c56209a
commit 283245b1b6
2 changed files with 21 additions and 23 deletions

View File

@ -26,21 +26,3 @@ using namespace Latan;
const string Env::fullName = PACKAGE_STRING; const string Env::fullName = PACKAGE_STRING;
const string Env::name = PACKAGE_NAME; const string Env::name = PACKAGE_NAME;
const string Env::version = PACKAGE_VERSION; const string Env::version = PACKAGE_VERSION;
template <>
float Latan::strTo<float>(const string &str)
{
return strtof(str.c_str(), (char **)NULL);
}
template <>
double Latan::strTo<double>(const string &str)
{
return strtod(str.c_str(), (char **)NULL);
}
template <>
int Latan::strTo<int>(const string &str)
{
return (int)(strtol(str.c_str(), (char **)NULL, 10));
}

View File

@ -61,9 +61,16 @@ namespace Env
extern const std::string version; extern const std::string version;
} }
// pointer type test
template <typename Derived, typename Base>
inline bool isDerivedFrom(const Base *pt)
{
return (dynamic_cast<const Derived *>(pt) != nullptr);
}
// string conversions // string conversions
template <typename T> template <typename T>
T strTo(const std::string &str) inline T strTo(const std::string &str)
{ {
T buf; T buf;
std::istringstream stream(str); std::istringstream stream(str);
@ -75,14 +82,23 @@ T strTo(const std::string &str)
//// optimized specializations //// optimized specializations
template <> template <>
float strTo<float>(const std::string &str); inline float strTo<float>(const std::string &str)
{
return strtof(str.c_str(), (char **)NULL);
}
template <> template <>
double strTo<double>(const std::string &str); inline double strTo<double>(const std::string &str)
{
return strtod(str.c_str(), (char **)NULL);
}
template <> template <>
int strTo<int>(const std::string &str); inline int strTo<int>(const std::string &str)
{
return (int)(strtol(str.c_str(), (char **)NULL, 10));
}
template <typename T> template <typename T>
std::string strFrom(const T x) inline std::string strFrom(const T x)
{ {
std::ostringstream stream; std::ostringstream stream;