adding convertType and minor changes

This commit is contained in:
Andre Antunes
2011-04-02 18:19:07 -03:00
parent d29b139321
commit 43001f40b7
6 changed files with 30 additions and 13 deletions

View File

@@ -93,12 +93,12 @@ void ConfigManager::setValue(const std::string &key, const char *value)
void ConfigManager::setValue(const std::string &key, int value)
{
setValue(key, boost::lexical_cast<std::string>(value));
setValue(key, convertType<std::string, int>(value));
}
void ConfigManager::setValue(const std::string &key, float value)
{
setValue(key, boost::lexical_cast<std::string>(value));
setValue(key, convertType<std::string, float>(value));
}
void ConfigManager::setValue(const std::string &key, bool value)
@@ -127,7 +127,7 @@ float ConfigManager::getFloat(const std::string &key)
warning("Config value %s not found", key.c_str());
return 0;
}
return boost::lexical_cast<float>(iter->second);
return convertType<float, std::string>(iter->second);
}
bool ConfigManager::getBoolean(const std::string &key)
@@ -147,5 +147,5 @@ int ConfigManager::getInteger(const std::string &key)
warning("Config value %s not found", key.c_str());
return 0;
}
return boost::lexical_cast<int>(iter->second);
return convertType<int, std::string>(iter->second);
}

View File

@@ -57,7 +57,7 @@ bool ResourceManager::setWriteDir(const std::string& path)
return ret;
}
bool ResourceManager::addToSearchPath(const std::string& path, bool insertInFront)
bool ResourceManager::addToSearchPath(const std::string& path, bool insertInFront /*= true*/)
{
if(!PHYSFS_addToSearchPath(path.c_str(), insertInFront ? 0 : 1)) {
error("Error while adding \"%s\" to resources search path: %s", path.c_str(), PHYSFS_getLastError());

View File

@@ -33,4 +33,21 @@ std::string vformat(const char *format, va_list args);
/// Formatting like printf for std::string
std::string format(const char *format, ...);
/// Convert any data type through boost::lexical_cast
//TODO: move declatation to util.cpp
template<class R, class T>
R convertType(T t)
{
R r = R();
try{
r = boost::lexical_cast<R>(t);
}
catch(boost::bad_lexical_cast bad){
//TODO: add an error message
}
return r;
}
#endif

View File

@@ -288,7 +288,7 @@ void Platform::showMouseCursor()
ShowCursor(true);
}
void Platform::setVsync(bool enable)
void Platform::setVsync(bool enable /*= true*/)
{
typedef GLint (*glSwapIntervalProc)(GLint);
glSwapIntervalProc glSwapInterval = NULL;